diff --git a/README.md b/README.md index 53b1be99..44fc154e 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ java-util Rare, hard-to-write utilities that are thoroughly tested (> 98% code coverage via JUnit tests). This library has no -dependencies on other libraries for runtime. Built purely on JDK. +dependencies on other libraries for runtime. Built purely on JDK. Works with JDK 1.8 through JDK 21. To include in your project: ##### Gradle ``` -implementation 'com.cedarsoftware:java-util:2.1.1' +implementation 'com.cedarsoftware:java-util:2.2.0' ``` ##### Maven @@ -19,22 +19,12 @@ implementation 'com.cedarsoftware:java-util:2.1.1' com.cedarsoftware java-util - 2.1.1 + 2.2.0 ``` -The java-util jar is about 150K in size. +The java-util jar is about **150K** in size. -### Sponsors -[![Alt text](https://www.yourkit.com/images/yklogo.png "YourKit")](https://www.yourkit.com/.net/profiler/index.jsp) - -YourKit supports open source projects with its full-featured Java Profiler. -YourKit, LLC is the creator of YourKit Java Profiler -and YourKit .NET Profiler, -innovative and intelligent tools for profiling Java and .NET applications. - -Intellij IDEA from JetBrains -**Intellij IDEA**
Since Java 1.5, you can statically import classes. Using this technique with many of the classes below, it makes their methods directly accessible in your source code, keeping your source code smaller and easier to read. For example: @@ -85,4 +75,16 @@ Included in java-util: See [changelog.md](/changelog.md) for revision history. +### Sponsors +[![Alt text](https://www.yourkit.com/images/yklogo.png "YourKit")](https://www.yourkit.com/.net/profiler/index.jsp) + +YourKit supports open source projects with its full-featured Java Profiler. +YourKit, LLC is the creator of YourKit Java Profiler +and YourKit .NET Profiler, +innovative and intelligent tools for profiling Java and .NET applications. + +Intellij IDEA from JetBrains +**Intellij IDEA**
+ + By: John DeRegnaucourt and Ken Partlow diff --git a/changelog.md b/changelog.md index af07d11c..7628b92b 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,8 @@ ### Revision History +* 2.2.0 + * Built with JDK 1.8 and runs with JDK 1.8 through JDK 21. + * The 2.2.x will continue to maintain JDK 1.8. The 3.0 branch [not yet created] will be JDK11+ + * Added tests to verify that `GraphComparator` and `DeepEquals` do not count sorted order of Sets for equivalency. It does however, require `Collections` that are not `Sets` to be in order. * 2.1.1 * ReflectionUtils skips static fields, speeding it up and remove runtime warning (field SerialVersionUID). Supports JDK's up through 21. * 2.1.0 diff --git a/pom.xml b/pom.xml index ad3a3f2d..9f21cc38 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.cedarsoftware java-util jar - 2.1.2-SNAPSHOT + 2.2.0 Java Utilities https://github.com/jdereg/java-util @@ -19,15 +19,15 @@ - 11 - 11 - 11 + 1.8 + 1.8 + 5.10.0 3.24.2 4.14.1 - 5.2.0 + 4.11.0 1.19.2 diff --git a/src/main/java/com/cedarsoftware/util/CompactMap.java b/src/main/java/com/cedarsoftware/util/CompactMap.java index 5ac5c8ba..51f503be 100644 --- a/src/main/java/com/cedarsoftware/util/CompactMap.java +++ b/src/main/java/com/cedarsoftware/util/CompactMap.java @@ -609,7 +609,7 @@ public Iterator iterator() public Set> entrySet() { - return new AbstractSet<>() + return new AbstractSet() { public Iterator> iterator() { diff --git a/src/main/java/com/cedarsoftware/util/ReflectionUtils.java b/src/main/java/com/cedarsoftware/util/ReflectionUtils.java index 557f38ca..5e348646 100644 --- a/src/main/java/com/cedarsoftware/util/ReflectionUtils.java +++ b/src/main/java/com/cedarsoftware/util/ReflectionUtils.java @@ -222,7 +222,13 @@ public static void getDeclaredFields(Class c, Collection fields) { } else { - field.trySetAccessible(); + // JDK11+ field.trySetAccessible(); + try + { + field.setAccessible(true); + } + catch(Exception e) { } + // JDK11+ fields.add(field); } } diff --git a/src/main/java/com/cedarsoftware/util/UniqueIdGenerator.java b/src/main/java/com/cedarsoftware/util/UniqueIdGenerator.java index f632b698..790ebf62 100644 --- a/src/main/java/com/cedarsoftware/util/UniqueIdGenerator.java +++ b/src/main/java/com/cedarsoftware/util/UniqueIdGenerator.java @@ -55,16 +55,16 @@ private UniqueIdGenerator() private static long previousTimeMilliseconds = 0; private static long previousTimeMilliseconds2 = 0; private static final int serverId; - private static final Map lastIds = new LinkedHashMap<>() + private static final Map lastIds = new LinkedHashMap() { - protected boolean removeEldestEntry(Map.Entry eldest) + protected boolean removeEldestEntry(Map.Entry eldest) { return size() > 1000; } }; - private static final Map lastIdsFull = new LinkedHashMap<>() + private static final Map lastIdsFull = new LinkedHashMap() { - protected boolean removeEldestEntry(Map.Entry eldest) + protected boolean removeEldestEntry(Map.Entry eldest) { return size() > 10000; } diff --git a/src/test/java/com/cedarsoftware/util/TestCaseInsensitiveMap.java b/src/test/java/com/cedarsoftware/util/TestCaseInsensitiveMap.java index 31112971..badcf890 100644 --- a/src/test/java/com/cedarsoftware/util/TestCaseInsensitiveMap.java +++ b/src/test/java/com/cedarsoftware/util/TestCaseInsensitiveMap.java @@ -1537,7 +1537,7 @@ private CaseInsensitiveMap createSimpleMap() private Map.Entry getEntry(final String key, final Object value) { - return new Map.Entry<>() + return new Map.Entry() { Object myValue = value; diff --git a/src/test/java/com/cedarsoftware/util/TestCompactMap.java b/src/test/java/com/cedarsoftware/util/TestCompactMap.java index ef44b249..fbeea4fb 100644 --- a/src/test/java/com/cedarsoftware/util/TestCompactMap.java +++ b/src/test/java/com/cedarsoftware/util/TestCompactMap.java @@ -32,7 +32,7 @@ public class TestCompactMap @Test public void testSizeAndEmpty() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -67,7 +67,7 @@ protected Map getNewMap() @Test public void testSizeAndEmptyHardOrder() { - Map map = new CompactMap<>() + Map map = new CompactMap() { protected String getSingleValueKey() { @@ -103,7 +103,7 @@ protected Map getNewMap() @Test public void testContainsKey() { - Map map = new CompactMap<>() + Map map = new CompactMap() { protected String getSingleValueKey() { @@ -145,7 +145,7 @@ protected Map getNewMap() @Test public void testContainsKeyHardOrder() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -193,7 +193,7 @@ public void testContainsValue() private void testContainsValueHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map = new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -230,7 +230,7 @@ private void testContainsValueHelper(final String singleKey) @Test public void testContainsValueHardOrder() { - Map map = new CompactMap<>() + Map map = new CompactMap() { protected String getSingleValueKey() { @@ -263,7 +263,7 @@ protected Map getNewMap() @Test public void testGet() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -305,7 +305,7 @@ protected Map getNewMap() @Test public void testGetHardOrder() { - Map map = new CompactMap<>() + Map map = new CompactMap() { protected String getSingleValueKey() { @@ -347,7 +347,7 @@ protected Map getNewMap() @Test public void testPutWithOverride() { - Map map = new CompactMap<>() + Map map = new CompactMap() { protected String getSingleValueKey() { @@ -370,7 +370,7 @@ protected Map getNewMap() @Test public void testPutWithManyEntries() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -409,7 +409,7 @@ protected Map getNewMap() @Test public void testPutWithManyEntriesHardOrder() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -448,7 +448,7 @@ protected Map getNewMap() @Test public void testPutWithManyEntriesHardOrder2() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -487,7 +487,7 @@ protected Map getNewMap() @Test public void testWeirdPuts() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -515,7 +515,7 @@ protected Map getNewMap() @Test public void testWeirdPuts1() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -549,7 +549,7 @@ public void testRemove() private void testRemoveHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -599,7 +599,7 @@ protected Map getNewMap() @Test public void testPutAll() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -653,7 +653,7 @@ protected Map getNewMap() @Test public void testClear() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -676,7 +676,7 @@ protected Map getNewMap() @Test public void testKeySetEmpty() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -717,7 +717,7 @@ protected Map getNewMap() @Test public void testKeySet1Item() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -756,7 +756,7 @@ protected Map getNewMap() @Test public void testKeySet1ItemHardWay() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -796,7 +796,7 @@ protected Map getNewMap() @Test public void testKeySetMultiItem() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -841,7 +841,7 @@ protected Map getNewMap() @Test public void testKeySetMultiItem2() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { @@ -904,7 +904,7 @@ public void testKeySetMultiItemReverseRemove() private void testKeySetMultiItemReverseRemoveHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -961,7 +961,7 @@ public void testKeySetMultiItemForwardRemove() private void testKeySetMultiItemForwardRemoveHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1015,7 +1015,7 @@ public void testKeySetToObjectArray() private void testKeySetToObjectArrayHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1064,7 +1064,7 @@ public void testKeySetToTypedObjectArray() private void testKeySetToTypedObjectArrayHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1123,7 +1123,7 @@ private void testKeySetToTypedObjectArrayHelper(final String singleKey) @Test public void testAddToKeySet() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected int compactSize() { return 3; } @@ -1160,7 +1160,7 @@ public void testKeySetContainsAll() private void testKeySetContainsAllHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1190,7 +1190,7 @@ public void testKeySetRetainAll() private void testKeySetRetainAllHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1228,7 +1228,7 @@ public void testKeySetRemoveAll() private void testKeySetRemoveAllHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1267,7 +1267,7 @@ private void testKeySetRemoveAllHelper(final String singleKey) @Test public void testKeySetClear() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return "field"; } protected int compactSize() { return 3; } @@ -1292,7 +1292,7 @@ public void testValues() private void testValuesHelper(final String singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1346,7 +1346,7 @@ public void testValuesHardWay() private void testValuesHardWayHelper(final String singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1413,7 +1413,7 @@ public void testValuesWith1() private void testValuesWith1Helper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected int compactSize() { return 3; } @@ -1452,7 +1452,7 @@ private void testValuesWith1Helper(final String singleKey) @Test public void testValuesClear() { - Map map = new CompactMap<>() + Map map = new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected int compactSize() { return 3; } @@ -1477,7 +1477,7 @@ public void testWithMapOnRHS() @SuppressWarnings("unchecked") private void testWithMapOnRHSHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1538,7 +1538,7 @@ public void testWithObjectArrayOnRHS() private void testWithObjectArrayOnRHSHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 2; } @@ -1584,7 +1584,8 @@ private void testWithObjectArrayOnRHSHelper(final String singleKey) @Test public void testWithObjectArrayOnRHS1() { - CompactMap map = new CompactMap<>() + + CompactMap map = new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected int compactSize() { return 2; } @@ -1618,7 +1619,7 @@ public void testRemove2To1WithNoMapOnRHS() private void testRemove2To1WithNoMapOnRHSHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected Map getNewMap() { return new LinkedHashMap<>(); } @@ -1643,7 +1644,7 @@ public void testRemove2To1WithMapOnRHS() @SuppressWarnings("unchecked") private void testRemove2To1WithMapOnRHSHelper(final String singleKey) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected Map getNewMap() { return new LinkedHashMap<>(); } @@ -1675,7 +1676,7 @@ public void testEntrySet() private void testEntrySetHelper(final String singleKey, final int compactSize) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected Map getNewMap() { return new LinkedHashMap<>(); } @@ -1743,7 +1744,7 @@ public void testEntrySetIterator() private void testEntrySetIteratorHelper(final String singleKey, final int compactSize) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected Map getNewMap() { return new LinkedHashMap<>(); } @@ -1798,7 +1799,7 @@ public void testEntrySetIteratorHardWay() private void testEntrySetIteratorHardWayHelper(final String singleKey, final int compactSize) { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return compactSize; } @@ -1881,7 +1882,7 @@ private void testEntrySetIteratorHardWayHelper(final String singleKey, final int @Test public void testCompactEntry() { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected int compactSize() { return 3; } @@ -1895,7 +1896,7 @@ public void testCompactEntry() @Test public void testEntrySetClear() { - Map map = new CompactMap<>() + Map map= new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected int compactSize() { return 3; } @@ -1911,7 +1912,7 @@ public void testEntrySetClear() @Test public void testUsingCompactEntryWhenMapOnRHS() { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected int compactSize() { return 3; } @@ -1934,7 +1935,7 @@ public void testEntryValueOverwrite() private void testEntryValueOverwriteHelper(final String singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1959,7 +1960,7 @@ public void testEntryValueOverwriteMultiple() private void testEntryValueOverwriteMultipleHelper(final String singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -1996,7 +1997,7 @@ private void testEntryValueOverwriteMultipleHelper(final String singleKey) @Test public void testMinus() { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected int compactSize() { return 3; } @@ -2027,7 +2028,7 @@ public void testHashCodeAndEquals() private void testHashCodeAndEqualsHelper(final String singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected int compactSize() { return 3; } @@ -2066,7 +2067,7 @@ private void testHashCodeAndEqualsHelper(final String singleKey) @Test public void testCaseInsensitiveMap() { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(); } @@ -2105,7 +2106,7 @@ public void testNullHandling() private void testNullHandlingHelper(final String singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected int compactSize() { return 3; } @@ -2138,7 +2139,7 @@ public void testCaseInsensitive() private void testCaseInsensitiveHelper(final String singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected Map getNewMap() { return new CaseInsensitiveMap<>(); } @@ -2234,7 +2235,7 @@ public void testCaseInsensitiveHardWay() private void testCaseInsensitiveHardwayHelper(final String singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected Map getNewMap() { return new CaseInsensitiveMap<>(); } @@ -2321,7 +2322,7 @@ public void testCaseInsensitiveInteger() private void testCaseInsensitiveIntegerHelper(final Integer singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected Integer getSingleValueKey() { return 16; } protected Map getNewMap() { return new CaseInsensitiveMap<>(); } @@ -2361,7 +2362,7 @@ public void testCaseInsensitiveIntegerHardWay() private void testCaseInsensitiveIntegerHardWayHelper(final Integer singleKey) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected Integer getSingleValueKey() { return 16; } protected Map getNewMap() { return new CaseInsensitiveMap<>(); } @@ -2405,7 +2406,7 @@ public void testContains() public void testContainsHelper(final String singleKey, final int size) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected Map getNewMap() { return new HashMap<>(); } @@ -2453,7 +2454,7 @@ public void testRetainOrder() public void testRetainOrderHelper(final String singleKey, final int size) { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return singleKey; } protected Map getNewMap() { return new TreeMap<>(); } @@ -2495,7 +2496,7 @@ public void testRetainOrderHelper(final String singleKey, final int size) @Test public void testBadNoArgConstructor() { - CompactMap map = new CompactMap<>(); + CompactMap map= new CompactMap(); assert "key".equals(map.getSingleValueKey()); assert map.getNewMap() instanceof HashMap; @@ -2522,7 +2523,7 @@ public void testBadConstructor() @Test public void testEqualsDifferingInArrayPortion() { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return "key1"; } protected Map getNewMap() { return new HashMap<>(); } @@ -2550,7 +2551,7 @@ public void testEqualsDifferingInArrayPortion() @Test public void testIntegerKeysInDefaultMap() { - CompactMap map = new CompactMap<>(); + CompactMap map= new CompactMap(); map.put(6, 10); Object key = map.getSingleValueKey(); assert key instanceof String; // "key" is the default @@ -2700,7 +2701,7 @@ public void testCompactCILinkedMap() @Test public void testCaseInsensitiveEntries2() { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -2718,7 +2719,7 @@ public void testCaseInsensitiveEntries2() @Test public void testIdentityEquals() { - Map compact = new CompactMap<>(); + Map compact= new CompactMap(); compact.put("foo", "bar"); assert compact.equals(compact); } @@ -2726,7 +2727,7 @@ public void testIdentityEquals() @Test public void testCI() { - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -2744,7 +2745,7 @@ public void testCI() @Test public void testWrappedTreeMap() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new TreeMap<>(String.CASE_INSENSITIVE_ORDER); } @@ -2768,7 +2769,7 @@ public void testWrappedTreeMap() @Test public void testMultipleSortedKeysetIterators() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new TreeMap<>(String.CASE_INSENSITIVE_ORDER); } @@ -2805,7 +2806,7 @@ public void testMultipleSortedKeysetIterators() @Test public void testMultipleSortedValueIterators() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new TreeMap<>(String.CASE_INSENSITIVE_ORDER); } @@ -2842,7 +2843,7 @@ public void testMultipleSortedValueIterators() @Test public void testMultipleSortedEntrySetIterators() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new TreeMap<>(String.CASE_INSENSITIVE_ORDER); } @@ -2879,7 +2880,7 @@ public void testMultipleSortedEntrySetIterators() @Test public void testMultipleNonSortedKeysetIterators() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new HashMap<>(); } @@ -2916,7 +2917,7 @@ public void testMultipleNonSortedKeysetIterators() @Test public void testMultipleNonSortedValueIterators() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new HashMap<>(); } @@ -2953,7 +2954,7 @@ public void testMultipleNonSortedValueIterators() @Test public void testMultipleNonSortedEntrySetIterators() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new HashMap<>(); } @@ -2990,7 +2991,7 @@ public void testMultipleNonSortedEntrySetIterators() @Test public void testKeySetRemoveAll2() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3024,7 +3025,7 @@ public void testKeySetRemoveAll2() @Test public void testEntrySetContainsAll() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3051,7 +3052,7 @@ public void testEntrySetContainsAll() @Test public void testEntrySetRemoveAll() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3091,7 +3092,7 @@ public void testEntrySetRemoveAll() @Test public void testEntrySetRetainAll() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3121,7 +3122,7 @@ public void testEntrySetRetainAll() @Test public void testPutAll2() { - CompactMap stringMap = new CompactMap<>() + CompactMap stringMap= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3144,7 +3145,7 @@ public void testPutAll2() assertEquals("four", stringMap.get("three")); assertEquals("Eight", stringMap.get("seven")); - CompactMap a = new CompactMap<>() + CompactMap a= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3157,7 +3158,7 @@ public void testPutAll2() @Test public void testKeySetRetainAll2() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3177,7 +3178,7 @@ public void testKeySetRetainAll2() assertTrue(s.contains("three")); assertTrue(m.containsKey("three")); - m = new CompactMap<>() + m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3203,11 +3204,11 @@ public void testKeySetRetainAll2() public void testEqualsWithNullOnRHS() { // Must have 2 entries and <= compactSize() in the 2 maps: - Map compact = new CompactMap<>(); + Map compact= new CompactMap(); compact.put("foo", null); compact.put("bar", null); assert compact.hashCode() != 0; - Map compact2 = new CompactMap<>(); + Map compact2= new CompactMap(); compact2.put("foo", null); compact2.put("bar", null); assert compact.equals(compact2); @@ -3225,14 +3226,14 @@ public void testEqualsWithNullOnRHS() @Test public void testToStringOnEmptyMap() { - Map compact = new CompactMap<>(); + Map compact= new CompactMap(); assert compact.toString().equals("{}"); } @Test public void testToStringDoesNotRecurseInfinitely() { - Map compact = new CompactMap<>(); + Map compact= new CompactMap(); compact.put("foo", compact); assert compact.toString() != null; assert compact.toString().contains("this Map"); @@ -3299,7 +3300,7 @@ public void testEntrySetKeyInsensitive() @Test public void testEntrySetEquals() { - CompactMap m = new CompactMap<>() + CompactMap m= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3342,7 +3343,7 @@ public void testEntrySetEquals() s4.add(getEntry("five","Six")); assertEquals(s, s4); - CompactMap secondStringMap = new CompactMap<>() + CompactMap secondStringMap= new CompactMap() { protected String getSingleValueKey() { return "a"; } protected Map getNewMap() { return new CaseInsensitiveMap<>(compactSize() + 1); } @@ -3478,7 +3479,7 @@ public void testPerformance() for (int i = lower; i < upper; i++) { compactSize[0] = i; - CompactMap map = new CompactMap<>() + CompactMap map= new CompactMap() { protected String getSingleValueKey() { diff --git a/src/test/java/com/cedarsoftware/util/TestCompactSet.java b/src/test/java/com/cedarsoftware/util/TestCompactSet.java index 732beb5d..877da636 100644 --- a/src/test/java/com/cedarsoftware/util/TestCompactSet.java +++ b/src/test/java/com/cedarsoftware/util/TestCompactSet.java @@ -71,7 +71,7 @@ public void testBadNoArgConstructor() { try { - new CompactSet<>() { protected int compactSize() { return 1; } }; + new CompactSet() { protected int compactSize() { return 1; } }; fail(); } catch (IllegalStateException e) { } @@ -126,7 +126,7 @@ public void testHeterogeneuousItems() assert set.contains(true); assert set.contains(null); - set = new CompactSet<>() { protected boolean isCaseInsensitive() { return true; } }; + set = new CompactSet() { protected boolean isCaseInsensitive() { return true; } }; assert set.add(16); assert set.add("Foo"); assert set.add(true); diff --git a/src/test/java/com/cedarsoftware/util/TestGraphComparator.java b/src/test/java/com/cedarsoftware/util/TestGraphComparator.java index 5258a560..5e60068a 100644 --- a/src/test/java/com/cedarsoftware/util/TestGraphComparator.java +++ b/src/test/java/com/cedarsoftware/util/TestGraphComparator.java @@ -2,6 +2,7 @@ import com.cedarsoftware.util.io.JsonReader; import com.cedarsoftware.util.io.JsonWriter; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.util.*; @@ -1943,6 +1944,55 @@ public void testTwoPointersToSameInstanceOrderedMap() throws Exception assertEquals(2, deltas.size()); } + @Test + public void testSortedAndUnsortedMap() + { + Map map1 = new LinkedHashMap<>(); + Map map2 = new TreeMap<>(); + map1.put("C", "charlie"); + map1.put("A", "alpha"); + map1.put("B", "beta"); + map2.put("C", "charlie"); + map2.put("B", "beta"); + map2.put("A", "alpha"); + List deltas = GraphComparator.compare(map1, map2, null); + assertEquals(0, deltas.size()); + + map1 = new TreeMap<>(Comparator.naturalOrder()); + map1.put("a", "b"); + map1.put("c", "d"); + map2 = new TreeMap<>(Comparator.reverseOrder()); + map2.put("a", "b"); + map2.put("c", "d"); + deltas = GraphComparator.compare(map1, map2, null); + assertEquals(0, deltas.size()); + } + + @Test + public void testSortedAndUnsortedSet() + { + SortedSet set1 = new TreeSet<>(); + Set set2 = new HashSet<>(); + List deltas = GraphComparator.compare(set1, set2, null); + assertEquals(0, deltas.size()); + + set1 = new TreeSet<>(); + set1.add("a"); + set1.add("b"); + set1.add("c"); + set1.add("d"); + set1.add("e"); + + set2 = new LinkedHashSet<>(); + set2.add("e"); + set2.add("d"); + set2.add("c"); + set2.add("b"); + set2.add("a"); + deltas = GraphComparator.compare(set1, set2, null); + assertEquals(0, deltas.size()); + } + // ---------------------------------------------------------- // Helper classes (not tests) // ---------------------------------------------------------- diff --git a/src/test/java/com/cedarsoftware/util/TestReflectionUtils.java b/src/test/java/com/cedarsoftware/util/TestReflectionUtils.java index fb68ce3e..ab7a3257 100644 --- a/src/test/java/com/cedarsoftware/util/TestReflectionUtils.java +++ b/src/test/java/com/cedarsoftware/util/TestReflectionUtils.java @@ -190,7 +190,7 @@ public void testMethodAnnotation() throws Exception @Test public void testGetDeclaredFields() throws Exception { - var fields = mock(ArrayList.class); + List fields = mock(ArrayList.class); when(fields.add(any())).thenThrow(ThreadDeath.class); assertThatExceptionOfType(ThreadDeath.class)