12
12
import java .util .regex .Matcher ;
13
13
import java .util .regex .Pattern ;
14
14
import java .util .stream .Collectors ;
15
- import java .util .stream .IntStream ;
16
15
import java .util .stream .Stream ;
17
16
import java .util .stream .StreamSupport ;
18
17
@@ -42,9 +41,11 @@ private Properties(Properties defaults, List<PropertiesParser.Token> tokens) {
42
41
this .defaults = defaults ;
43
42
values = new LinkedHashMap <>();
44
43
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
+ });
48
49
}
49
50
50
51
/**
@@ -197,8 +198,8 @@ public void storeToXML(OutputStream os, String comment, String encoding) throws
197
198
}
198
199
199
200
/**
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!
202
203
*
203
204
* @return a <code>Properties</code> object
204
205
* @deprecated Use <code>flattened()</code>
@@ -209,8 +210,8 @@ public Properties flatten() {
209
210
}
210
211
211
212
/**
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!
214
215
*
215
216
* @return a <code>Properties</code> object
216
217
*/
@@ -615,8 +616,7 @@ private Cursor indexOf(String key) {
615
616
}
616
617
617
618
private static String escapeValue (String value ) {
618
- return value
619
- .replace ("\\ " , "\\ \\ " )
619
+ return value .replace ("\\ " , "\\ \\ " )
620
620
.replace ("\n " , "\\ n" )
621
621
.replace ("\r " , "\\ r" )
622
622
.replace ("\t " , "\\ t" )
@@ -631,7 +631,7 @@ private static String escapeUnicode(String text) {
631
631
return replace (
632
632
text ,
633
633
"[^\\ 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 )));
635
635
}
636
636
637
637
private static String unescapeUnicode (String escape ) {
@@ -671,9 +671,9 @@ private static String replace(String input, Pattern regex, Function<Matcher, Str
671
671
}
672
672
673
673
/**
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.
677
677
*
678
678
* @return A <code>Properties</code> with encoded keys and values
679
679
*/
@@ -682,7 +682,9 @@ public Properties escaped() {
682
682
}
683
683
684
684
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 ))));
686
688
}
687
689
688
690
private static PropertiesParser .Token escapeToken (PropertiesParser .Token token ) {
@@ -694,18 +696,22 @@ private static PropertiesParser.Token escapeToken(PropertiesParser.Token token)
694
696
}
695
697
696
698
/**
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.
700
702
*
701
703
* @return A <code>Properties</code> without Unicode escape sequences in its keys and values
702
704
*/
703
705
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 ));
705
708
}
706
709
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 ))));
709
715
}
710
716
711
717
private static PropertiesParser .Token unescapeToken (PropertiesParser .Token token ) {
@@ -719,36 +725,43 @@ private static PropertiesParser.Token unescapeToken(PropertiesParser.Token token
719
725
private static List <PropertiesParser .Token > mapKeyValues (
720
726
List <PropertiesParser .Token > tokens ,
721
727
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 ());
729
739
}
730
740
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 ();
734
746
735
- @ Override
736
- public boolean hasNext () {
737
- return i .hasNext ();
738
- }
747
+ @ Override
748
+ public boolean hasNext () {
749
+ return i .hasNext ();
750
+ }
739
751
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
+ };
750
762
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 );
752
765
}
753
766
754
767
/**
0 commit comments