Skip to content

Commit 405c447

Browse files
authored
Sync with underscore-java
1 parent 07f93cc commit 405c447

File tree

1 file changed

+58
-46
lines changed

1 file changed

+58
-46
lines changed

README.md

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ U.of(1, 2, 3) // or java.util.Arrays.asList(1, 2, 3) or new Integer[] {1, 2, 3}
7171
})
7272
.forEach(System.out::println);
7373
// "a1", "a2", "a2", "a3", "a3", "a3"
74-
74+
7575
U.formatXml("<a><b>data</b></a>", Xml.XmlStringBuilder.Step.TWO_SPACES);
7676
// <a>
7777
// <b>data</b>
@@ -84,16 +84,17 @@ U.formatJson("{\"a\":{\"b\":\"data\"}}", Json.JsonStringBuilder.Step.TWO_SPACES)
8484
// }
8585
// }
8686

87-
U.xmlToJson("<mydocument has=\"an attribute\">\n" +
88-
" <and>\n" +
89-
" <many>elements</many>\n" +
90-
" <many>more elements</many>\n" +
91-
" </and>\n" +
92-
" <plus a=\"complex\">\n" +
93-
" element as well\n" +
94-
" </plus>\n" +
95-
"</mydocument>", Json.JsonStringBuilder.Step.TWO_SPACES);
96-
87+
U.xmlToJson(
88+
"<mydocument has=\"an attribute\">\n"
89+
+ " <and>\n"
90+
+ " <many>elements</many>\n"
91+
+ " <many>more elements</many>\n"
92+
+ " </and>\n"
93+
+ " <plus a=\"complex\">\n"
94+
+ " element as well\n"
95+
+ " </plus>\n"
96+
+ "</mydocument>",
97+
Json.JsonStringBuilder.Step.TWO_SPACES);
9798
// {
9899
// "mydocument": {
99100
// "-has": "an attribute",
@@ -111,23 +112,24 @@ U.xmlToJson("<mydocument has=\"an attribute\">\n" +
111112
// "#omit-xml-declaration": "yes"
112113
// }
113114

114-
U.jsonToXml("{\n" +
115-
" \"mydocument\": {\n" +
116-
" \"-has\": \"an attribute\",\n" +
117-
" \"and\": {\n" +
118-
" \"many\": [\n" +
119-
" \"elements\",\n" +
120-
" \"more elements\"\n" +
121-
" ]\n" +
122-
" },\n" +
123-
" \"plus\": {\n" +
124-
" \"-a\": \"complex\",\n" +
125-
" \"#text\": \"\\n element as well\\n \"\n" +
126-
" }\n" +
127-
" },\n" +
128-
" \"#omit-xml-declaration\": \"yes\"\n" +
129-
"}", Xml.XmlStringBuilder.Step.TWO_SPACES);
130-
115+
U.jsonToXml(
116+
"{\n"
117+
+ " \"mydocument\": {\n"
118+
+ " \"-has\": \"an attribute\",\n"
119+
+ " \"and\": {\n"
120+
+ " \"many\": [\n"
121+
+ " \"elements\",\n"
122+
+ " \"more elements\"\n"
123+
+ " ]\n"
124+
+ " },\n"
125+
+ " \"plus\": {\n"
126+
+ " \"-a\": \"complex\",\n"
127+
+ " \"#text\": \"\\n element as well\\n \"\n"
128+
+ " }\n"
129+
+ " },\n"
130+
+ " \"#omit-xml-declaration\": \"yes\"\n"
131+
+ "}",
132+
Xml.XmlStringBuilder.Step.TWO_SPACES);
131133
// <mydocument has="an attribute">
132134
// <and>
133135
// <many>elements</many>
@@ -138,24 +140,32 @@ U.jsonToXml("{\n" +
138140
// </plus>
139141
// </mydocument>
140142

141-
U.Builder builder = U.objectBuilder()
142-
.add("firstName", "John")
143-
.add("lastName", "Smith")
144-
.add("age", 25)
145-
.add("address", U.arrayBuilder()
146-
.add(U.objectBuilder()
147-
.add("streetAddress", "21 2nd Street")
148-
.add("city", "New York")
149-
.addNull("cityId")
150-
.add("state", "NY")
151-
.add("postalCode", "10021")))
152-
.add("phoneNumber", U.arrayBuilder()
153-
.add(U.objectBuilder()
154-
.add("type", "home")
155-
.add("number", "212 555-1234"))
156-
.add(U.objectBuilder()
157-
.add("type", "fax")
158-
.add("number", "646 555-4567")));
143+
U.Builder builder =
144+
U.objectBuilder()
145+
.add("firstName", "John")
146+
.add("lastName", "Smith")
147+
.add("age", 25)
148+
.add(
149+
"address",
150+
U.arrayBuilder()
151+
.add(
152+
U.objectBuilder()
153+
.add("streetAddress", "21 2nd Street")
154+
.add("city", "New York")
155+
.addNull("cityId")
156+
.add("state", "NY")
157+
.add("postalCode", "10021")))
158+
.add(
159+
"phoneNumber",
160+
U.arrayBuilder()
161+
.add(
162+
U.objectBuilder()
163+
.add("type", "home")
164+
.add("number", "212 555-1234"))
165+
.add(
166+
U.objectBuilder()
167+
.add("type", "fax")
168+
.add("number", "646 555-4567")));
159169
System.out.println(builder.toJson());
160170
System.out.println(builder.toXml());
161171
```
@@ -283,6 +293,8 @@ List<String> names = U.selectTokens(U.fromJsonMap(json), "//Products[Price>=50]/
283293
// [Anvil, Elbow Grease]
284294
```
285295

296+
Underscore-java is a java port of [Underscore.js](https://underscorejs.org/).
297+
286298
In addition to porting Underscore's functionality, Underscore-java includes matching unit tests.
287299

288300
For docs, license, tests, and downloads, see:

0 commit comments

Comments
 (0)