Skip to content

Commit 2e72f7f

Browse files
committed
chore: formatting
1 parent 671cbcb commit 2e72f7f

File tree

3 files changed

+64
-51
lines changed

3 files changed

+64
-51
lines changed

src/main/java/org/codejive/properties/Properties.java

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.regex.Matcher;
1313
import java.util.regex.Pattern;
1414
import java.util.stream.Collectors;
15-
import java.util.stream.IntStream;
1615
import java.util.stream.Stream;
1716
import java.util.stream.StreamSupport;
1817

@@ -42,9 +41,11 @@ private Properties(Properties defaults, List<PropertiesParser.Token> tokens) {
4241
this.defaults = defaults;
4342
values = new LinkedHashMap<>();
4443
this.tokens = tokens;
45-
rawEntrySet().forEach(e -> {
46-
values.put(unescape(e.getKey()), unescape(e.getValue()));
47-
});
44+
rawEntrySet()
45+
.forEach(
46+
e -> {
47+
values.put(unescape(e.getKey()), unescape(e.getValue()));
48+
});
4849
}
4950

5051
/**
@@ -197,8 +198,8 @@ public void storeToXML(OutputStream os, String comment, String encoding) throws
197198
}
198199

199200
/**
200-
* Returns the current properties table with all its defaults as a single
201-
* flattened properties table. NB: Result will have no formatting or comments!
201+
* Returns the current properties table with all its defaults as a single flattened properties
202+
* table. NB: Result will have no formatting or comments!
202203
*
203204
* @return a <code>Properties</code> object
204205
* @deprecated Use <code>flattened()</code>
@@ -209,8 +210,8 @@ public Properties flatten() {
209210
}
210211

211212
/**
212-
* Returns the current properties table with all its defaults as a single
213-
* flattened properties table. NB: Result will have no formatting or comments!
213+
* Returns the current properties table with all its defaults as a single flattened properties
214+
* table. NB: Result will have no formatting or comments!
214215
*
215216
* @return a <code>Properties</code> object
216217
*/
@@ -615,8 +616,7 @@ private Cursor indexOf(String key) {
615616
}
616617

617618
private static String escapeValue(String value) {
618-
return value
619-
.replace("\\", "\\\\")
619+
return value.replace("\\", "\\\\")
620620
.replace("\n", "\\n")
621621
.replace("\r", "\\r")
622622
.replace("\t", "\\t")
@@ -631,7 +631,7 @@ private static String escapeUnicode(String text) {
631631
return replace(
632632
text,
633633
"[^\\x{0000}-\\x{00FF}]",
634-
m -> "\\\\u" + String.format("%04x", (int)m.group(0).charAt(0)));
634+
m -> "\\\\u" + String.format("%04x", (int) m.group(0).charAt(0)));
635635
}
636636

637637
private static String unescapeUnicode(String escape) {
@@ -671,9 +671,9 @@ private static String replace(String input, Pattern regex, Function<Matcher, Str
671671
}
672672

673673
/**
674-
* Returns a copy of the object where all characters, in keys and values that are not in
675-
* the Unicode range of 0x0000-0x00FF, have been escaped. This is useful when using
676-
* <code>store()</code> to write to an output that does not support UTF8.
674+
* Returns a copy of the object where all characters, in keys and values that are not in the
675+
* Unicode range of 0x0000-0x00FF, have been escaped. This is useful when using <code>store()
676+
* </code> to write to an output that does not support UTF8.
677677
*
678678
* @return A <code>Properties</code> with encoded keys and values
679679
*/
@@ -682,7 +682,9 @@ public Properties escaped() {
682682
}
683683

684684
private static List<PropertiesParser.Token> escapeTokens(List<PropertiesParser.Token> tokens) {
685-
return mapKeyValues(tokens, ts -> Arrays.asList(escapeToken(ts.get(0)), ts.get(1), escapeToken(ts.get(2))));
685+
return mapKeyValues(
686+
tokens,
687+
ts -> Arrays.asList(escapeToken(ts.get(0)), ts.get(1), escapeToken(ts.get(2))));
686688
}
687689

688690
private static PropertiesParser.Token escapeToken(PropertiesParser.Token token) {
@@ -694,18 +696,22 @@ private static PropertiesParser.Token escapeToken(PropertiesParser.Token token)
694696
}
695697

696698
/**
697-
* Returns a copy of the object where all Unicode escape sequences, in keys and values,
698-
* have been decoded into their actual Unicode characters. This is useful when using
699-
* <code>store()</code> to write to an output that supports UTF8.
699+
* Returns a copy of the object where all Unicode escape sequences, in keys and values, have
700+
* been decoded into their actual Unicode characters. This is useful when using <code>store()
701+
* </code> to write to an output that supports UTF8.
700702
*
701703
* @return A <code>Properties</code> without Unicode escape sequences in its keys and values
702704
*/
703705
public Properties unescaped() {
704-
return new Properties(defaults != null ? defaults.unescaped() : null, unescapeTokens(tokens));
706+
return new Properties(
707+
defaults != null ? defaults.unescaped() : null, unescapeTokens(tokens));
705708
}
706709

707-
private static List<PropertiesParser.Token> unescapeTokens(List<PropertiesParser.Token> tokens) {
708-
return mapKeyValues(tokens, ts -> Arrays.asList(unescapeToken(ts.get(0)), ts.get(1), unescapeToken(ts.get(2))));
710+
private static List<PropertiesParser.Token> unescapeTokens(
711+
List<PropertiesParser.Token> tokens) {
712+
return mapKeyValues(
713+
tokens,
714+
ts -> Arrays.asList(unescapeToken(ts.get(0)), ts.get(1), unescapeToken(ts.get(2))));
709715
}
710716

711717
private static PropertiesParser.Token unescapeToken(PropertiesParser.Token token) {
@@ -719,36 +725,43 @@ private static PropertiesParser.Token unescapeToken(PropertiesParser.Token token
719725
private static List<PropertiesParser.Token> mapKeyValues(
720726
List<PropertiesParser.Token> tokens,
721727
Function<List<PropertiesParser.Token>, List<PropertiesParser.Token>> mapper) {
722-
return combined(tokens).map(ts -> {
723-
if (ts.get(0).type == PropertiesParser.Type.KEY) {
724-
return mapper.apply(ts);
725-
} else {
726-
return ts;
727-
}
728-
}).flatMap(Collection::stream).collect(Collectors.toList());
728+
return combined(tokens)
729+
.map(
730+
ts -> {
731+
if (ts.get(0).type == PropertiesParser.Type.KEY) {
732+
return mapper.apply(ts);
733+
} else {
734+
return ts;
735+
}
736+
})
737+
.flatMap(Collection::stream)
738+
.collect(Collectors.toList());
729739
}
730740

731-
private static Stream<List<PropertiesParser.Token>> combined(List<PropertiesParser.Token> tokens) {
732-
Iterator<List<PropertiesParser.Token>> iter = new Iterator<List<PropertiesParser.Token>>() {
733-
Iterator<PropertiesParser.Token> i = tokens.iterator();
741+
private static Stream<List<PropertiesParser.Token>> combined(
742+
List<PropertiesParser.Token> tokens) {
743+
Iterator<List<PropertiesParser.Token>> iter =
744+
new Iterator<List<PropertiesParser.Token>>() {
745+
Iterator<PropertiesParser.Token> i = tokens.iterator();
734746

735-
@Override
736-
public boolean hasNext() {
737-
return i.hasNext();
738-
}
747+
@Override
748+
public boolean hasNext() {
749+
return i.hasNext();
750+
}
739751

740-
@Override
741-
public List<PropertiesParser.Token> next() {
742-
PropertiesParser.Token t = i.next();
743-
if (t.type == PropertiesParser.Type.KEY) {
744-
return Arrays.asList(t, i.next(), i.next());
745-
} else {
746-
return Collections.singletonList(t);
747-
}
748-
}
749-
};
752+
@Override
753+
public List<PropertiesParser.Token> next() {
754+
PropertiesParser.Token t = i.next();
755+
if (t.type == PropertiesParser.Type.KEY) {
756+
return Arrays.asList(t, i.next(), i.next());
757+
} else {
758+
return Collections.singletonList(t);
759+
}
760+
}
761+
};
750762

751-
return StreamSupport.stream(Spliterators.spliterator(iter, tokens.size(), Spliterator.SORTED), false);
763+
return StreamSupport.stream(
764+
Spliterators.spliterator(iter, tokens.size(), Spliterator.SORTED), false);
752765
}
753766

754767
/**

src/main/java/org/codejive/properties/PropertiesParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class PropertiesParser {
2121
public enum Type {
2222
/** The key part of a key-value pair */
2323
KEY,
24-
/** The separator between a key and a value. This will include any whitespace that exists
24+
/**
25+
* The separator between a key and a value. This will include any whitespace that exists
2526
* before and after the separator!
2627
*/
2728
SEPARATOR,
@@ -296,8 +297,8 @@ private String string() {
296297
}
297298

298299
/**
299-
* Returns a copy of the given string where all escape sequences
300-
* have been turned into their representative values.
300+
* Returns a copy of the given string where all escape sequences have been turned into their
301+
* representative values.
301302
*
302303
* @param escape Input string
303304
* @return Decoded string

src/test/java/org/codejive/properties/TestProperties.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ void testPutUnicode() throws IOException, URISyntaxException {
389389
p.put("text", "\u0627\u0644\u0623\u0644\u0628\u0627\u0646\u064a\u0629");
390390
StringWriter sw = new StringWriter();
391391
p.store(sw);
392-
assertThat(sw.toString())
393-
.isEqualTo(readAll(getResource("/test-putunicode.properties")));
392+
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-putunicode.properties")));
394393
}
395394

396395
@Test

0 commit comments

Comments
 (0)