From 4605db9dce2b6a23d937bb963651359820eb6886 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sat, 1 Aug 2020 06:19:05 +0300 Subject: [PATCH] Introduce version 1.14. --- README.md | 4 ++-- pom-central.xml | 8 ++++---- pom-pack.xml | 8 ++++---- pom.xml | 8 ++++---- src/main/java/com/github/underscore/U.java | 6 ++++++ src/main/java/com/github/underscore/lodash/U.java | 9 +++++++-- src/test/java/com/github/underscore/FunctionsTest.java | 2 +- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 605cce3..b1ce07c 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Include the following in your `pom.xml` for Maven: com.github.javadev underscore11 - 1.13 + 1.14 ... @@ -34,7 +34,7 @@ Include the following in your `pom.xml` for Maven: Gradle: ```groovy -compile 'com.github.javadev:underscore11:1.13' +compile 'com.github.javadev:underscore11:1.14' ``` Underscore-java is a java port of [Underscore.js](http://underscorejs.org/). diff --git a/pom-central.xml b/pom-central.xml index c4fc5d1..696a50e 100644 --- a/pom-central.xml +++ b/pom-central.xml @@ -5,7 +5,7 @@ com.github.javadev underscore11 jar - 1.13 + 1.14 java 11 port of Underscore.js The java 11 port of Underscore.js https://github.com/javadev/underscore-java11 @@ -50,7 +50,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.8.1 11 11 @@ -117,13 +117,13 @@ junit junit - 4.12 + 4.13 test org.awaitility awaitility - 4.0.2 + 4.0.3 test diff --git a/pom-pack.xml b/pom-pack.xml index 79462f8..69b56a3 100644 --- a/pom-pack.xml +++ b/pom-pack.xml @@ -5,7 +5,7 @@ com.github.javadev underscore11 jar - 1.13 + 1.14 java 11 port of Underscore.js The java 11 port of Underscore.js https://github.com/javadev/underscore-java11 @@ -51,7 +51,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.8.1 10 10 @@ -240,13 +240,13 @@ junit junit - 4.12 + 4.13 test org.awaitility awaitility - 4.0.2 + 4.0.3 test diff --git a/pom.xml b/pom.xml index 265aa59..41e32e1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.javadev underscore11 jar - 1.13-SNAPSHOT + 1.14-SNAPSHOT java 11 port of Underscore.js The java 11 port of Underscore.js https://github.com/javadev/underscore-java11 @@ -49,7 +49,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.8.1 11 11 @@ -204,13 +204,13 @@ junit junit - 4.12 + 4.13 test org.awaitility awaitility - 4.0.2 + 4.0.3 test diff --git a/src/main/java/com/github/underscore/U.java b/src/main/java/com/github/underscore/U.java index 9ce941a..198d592 100644 --- a/src/main/java/com/github/underscore/U.java +++ b/src/main/java/com/github/underscore/U.java @@ -3652,6 +3652,12 @@ protected static List newArrayList(final Iterable iterable) { return result; } + protected static List newArrayList(final T object) { + final List result = new ArrayList(); + result.add(object); + return result; + } + protected static List newArrayList(final Iterable iterable, final int size) { final List result = new ArrayList(); for (int index = 0; iterable.iterator().hasNext() && index < size; index += 1) { diff --git a/src/main/java/com/github/underscore/lodash/U.java b/src/main/java/com/github/underscore/lodash/U.java index 8a0ff9e..dad7805 100644 --- a/src/main/java/com/github/underscore/lodash/U.java +++ b/src/main/java/com/github/underscore/lodash/U.java @@ -1653,14 +1653,19 @@ private static Object makeObjectForSetValue(Object value, final String key, @SuppressWarnings("unchecked") public static Map update(final Map map1, final Map map2) { Map outMap = newLinkedHashMap(); - for (String key : map2.keySet()) { - Object value2 = map2.get(key); + for (Map.Entry entry : map2.entrySet()) { + String key = entry.getKey(); + Object value2 = entry.getValue(); if (map1.containsKey(key)) { Object value1 = map1.get(key); if (value1 instanceof Map && value2 instanceof Map) { outMap.put(key, update((Map) value1, (Map) value2)); } else if (value1 instanceof List && value2 instanceof List) { outMap.put(key, merge((List) value1, (List) value2)); + } else if (value1 instanceof List) { + outMap.put(key, merge((List) value1, newArrayList(value2))); + } else if (value2 instanceof List) { + outMap.put(key, merge(newArrayList(value1), (List) value2)); } else { outMap.put(key, value2); } diff --git a/src/test/java/com/github/underscore/FunctionsTest.java b/src/test/java/com/github/underscore/FunctionsTest.java index b99a159..979ce88 100644 --- a/src/test/java/com/github/underscore/FunctionsTest.java +++ b/src/test/java/com/github/underscore/FunctionsTest.java @@ -120,7 +120,7 @@ public void throttle() { final Integer[] counter = new Integer[] {0}; Supplier incr = new Supplier() { public Void get() { counter[0]++; return null; } }; - final Supplier throttleIncr = U.throttle(incr, 40); + final Supplier throttleIncr = U.throttle(incr, 50); throttleIncr.get(); throttleIncr.get(); U.delay(throttleIncr, 16);