Skip to content

Commit

Permalink
Added methods U.Builder.size(), U.Builder.update(map), U.ArrayBuilder…
Browse files Browse the repository at this point in the history
….size(), U.ArrayBuilder.merge(list).
  • Loading branch information
javadev authored May 24, 2022
1 parent 4e6e418 commit 13f842d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/github/underscore/U.java
Original file line number Diff line number Diff line change
Expand Up @@ -3139,6 +3139,10 @@ public boolean isEmpty() {
return data.isEmpty();
}

public int size() {
return data.size();
}

public Builder add(final Builder builder) {
data.put(String.valueOf(data.size()), builder.build());
return this;
Expand All @@ -3159,6 +3163,11 @@ public Builder add(final Map<String, Object> map) {
return this;
}

public Builder update(final Map<String, Object> map) {
U.update(data, deepCopyMap(map));
return this;
}

public Builder addNull(final String key) {
data.put(key, null);
return this;
Expand Down Expand Up @@ -3249,6 +3258,10 @@ public boolean isEmpty() {
return data.isEmpty();
}

public int size() {
return data.size();
}

public ArrayBuilder add(final ArrayBuilder builder) {
data.addAll(builder.build());
return this;
Expand All @@ -3259,6 +3272,12 @@ public ArrayBuilder add(final Builder builder) {
return this;
}

@SuppressWarnings("unchecked")
public ArrayBuilder merge(final List<Object> list) {
U.merge(data, (List<Object>) ((ArrayList) list).clone());
return this;
}

@SuppressWarnings("unchecked")
public List<Object> build() {
return (List<Object>) ((ArrayList) data).clone();
Expand Down
18 changes: 13 additions & 5 deletions src/test/java/com/github/underscore/LodashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,15 @@ void fetchGet() {

@Test
void downloadUrl() throws IOException {
long result =
U.downloadUrl(
"https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json",
"test.json");
assertEquals(65, result);
try {
long result =
U.downloadUrl(
"https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json",
"test.json");
assertEquals(65, result);
} catch (javax.net.ssl.SSLHandshakeException ignored) {
// ignored
}
}

@Test
Expand Down Expand Up @@ -1364,6 +1368,7 @@ void objectBuilder() {
U.Builder.fromXml("<a/>");
U.Builder.fromMap(U.newLinkedHashMap());
builder.add(U.newLinkedHashMap());
builder.update(U.newLinkedHashMap());
builder.set("1", "3");
builder.toString();
assertEquals("{1=3}", builder.build().toString());
Expand All @@ -1372,6 +1377,7 @@ void objectBuilder() {
assertEquals("{}", builder.build().toString());
builder.clear();
builder.isEmpty();
builder.size();
assertEquals("{}", builder.build().toString());
builder.toChain();
builder.addNull("key");
Expand Down Expand Up @@ -1422,8 +1428,10 @@ void arrayBuilder() {
assertEquals("[1, 3, 1, 2]", builder.build().toString());
builder.remove(1);
assertEquals("[1, 1, 2]", builder.build().toString());
builder.merge(new ArrayList<>());
builder.clear();
builder.isEmpty();
builder.size();
assertEquals("[]", builder.build().toString());
builder.toChain();
builder.addNull();
Expand Down

0 comments on commit 13f842d

Please sign in to comment.