Skip to content

Commit 4bd7257

Browse files
committed
Sync with underscore-java.
1 parent a1e5b41 commit 4bd7257

File tree

3 files changed

+80
-32
lines changed

3 files changed

+80
-32
lines changed

src/main/java/com/github/underscore/U.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,10 @@ public Builder add(final Object value) {
31163116
return this;
31173117
}
31183118

3119+
public <T> T get(final String path) {
3120+
return U.get(data, path);
3121+
}
3122+
31193123
public Builder set(final String path, final Object value) {
31203124
U.set(data, path, value);
31213125
return this;
@@ -3131,6 +3135,14 @@ public Builder clear() {
31313135
return this;
31323136
}
31333137

3138+
public boolean isEmpty() {
3139+
return data.isEmpty();
3140+
}
3141+
3142+
public int size() {
3143+
return data.size();
3144+
}
3145+
31343146
public Builder add(final Builder builder) {
31353147
data.put(String.valueOf(data.size()), builder.build());
31363148
return this;
@@ -3151,6 +3163,11 @@ public Builder add(final Map<String, Object> map) {
31513163
return this;
31523164
}
31533165

3166+
public Builder update(final Map<String, Object> map) {
3167+
U.update(data, deepCopyMap(map));
3168+
return this;
3169+
}
3170+
31543171
public Builder addNull(final String key) {
31553172
data.put(key, null);
31563173
return this;
@@ -3218,6 +3235,10 @@ public ArrayBuilder addNull() {
32183235
return this;
32193236
}
32203237

3238+
public <T> T get(final String path) {
3239+
return U.get(U.getStringObjectMap(data), "value." + path);
3240+
}
3241+
32213242
public ArrayBuilder set(final int index, final Object value) {
32223243
data.set(index, value);
32233244
return this;
@@ -3233,6 +3254,14 @@ public ArrayBuilder clear() {
32333254
return this;
32343255
}
32353256

3257+
public boolean isEmpty() {
3258+
return data.isEmpty();
3259+
}
3260+
3261+
public int size() {
3262+
return data.size();
3263+
}
3264+
32363265
public ArrayBuilder add(final ArrayBuilder builder) {
32373266
data.addAll(builder.build());
32383267
return this;
@@ -3243,6 +3272,12 @@ public ArrayBuilder add(final Builder builder) {
32433272
return this;
32443273
}
32453274

3275+
@SuppressWarnings("unchecked")
3276+
public ArrayBuilder merge(final List<Object> list) {
3277+
U.merge(data, (List<Object>) ((ArrayList) list).clone());
3278+
return this;
3279+
}
3280+
32463281
@SuppressWarnings("unchecked")
32473282
public List<Object> build() {
32483283
return (List<Object>) ((ArrayList) data).clone();

src/main/javascript/underscore.js

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/java/com/github/underscore/LodashTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,15 @@ void fetchGet() {
497497

498498
@Test
499499
void downloadUrl() throws IOException {
500-
long result =
501-
U.downloadUrl(
502-
"https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json",
503-
"test.json");
504-
assertEquals(65, result);
500+
try {
501+
long result =
502+
U.downloadUrl(
503+
"https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json",
504+
"test.json");
505+
assertEquals(65, result);
506+
} catch (javax.net.ssl.SSLHandshakeException ignored) {
507+
// ignored
508+
}
505509
}
506510

507511
@Test
@@ -1364,15 +1368,20 @@ void objectBuilder() {
13641368
U.Builder.fromXml("<a/>");
13651369
U.Builder.fromMap(U.newLinkedHashMap());
13661370
builder.add(U.newLinkedHashMap());
1371+
builder.update(U.newLinkedHashMap());
13671372
builder.set("1", "3");
13681373
builder.toString();
13691374
assertEquals("{1=3}", builder.build().toString());
1375+
assertEquals("3", builder.<String>get("1"));
13701376
builder.remove("1");
13711377
assertEquals("{}", builder.build().toString());
13721378
builder.clear();
1379+
builder.isEmpty();
1380+
builder.size();
13731381
assertEquals("{}", builder.build().toString());
13741382
builder.toChain();
13751383
builder.addNull("key");
1384+
assertEquals(null, builder.<String>get("key"));
13761385
Map<String, Object> value =
13771386
U.objectBuilder()
13781387
.add("firstName", "John")
@@ -1409,6 +1418,7 @@ void arrayBuilder() {
14091418
U.ArrayBuilder builder = U.arrayBuilder().add("1").add("2");
14101419
builder.add(builder);
14111420
builder.toJson();
1421+
assertEquals("1", builder.<String>get("0"));
14121422
U.ArrayBuilder.fromJson("[]");
14131423
builder.toXml();
14141424
U.ArrayBuilder.fromXml(
@@ -1418,7 +1428,10 @@ void arrayBuilder() {
14181428
assertEquals("[1, 3, 1, 2]", builder.build().toString());
14191429
builder.remove(1);
14201430
assertEquals("[1, 1, 2]", builder.build().toString());
1431+
builder.merge(new ArrayList<>());
14211432
builder.clear();
1433+
builder.isEmpty();
1434+
builder.size();
14221435
assertEquals("[]", builder.build().toString());
14231436
builder.toChain();
14241437
builder.addNull();

0 commit comments

Comments
 (0)