sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/04: Place-holder for JDK 9 methods should have the same behavior than JDK 9, which is to throw IllegalArgumentException if there is duplicated values.
Date Tue, 03 Nov 2020 22:54:53 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit b2c72501f8b3c9ab30fcd3d36dcb361dcf11aa5b
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Nov 3 21:37:27 2020 +0100

    Place-holder for JDK 9 methods should have the same behavior than JDK 9,
    which is to throw IllegalArgumentException if there is duplicated values.
---
 .../src/main/java/org/apache/sis/internal/jdk9/JDK9.java       | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/jdk9/JDK9.java b/core/sis-utility/src/main/java/org/apache/sis/internal/jdk9/JDK9.java
index 63bfd5c..054f4f0 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/jdk9/JDK9.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/jdk9/JDK9.java
@@ -78,8 +78,12 @@ public final class JDK9 {
         switch (elements.length) {
             case 0:  return Collections.emptySet();
             case 1:  return Collections.singleton(elements[0]);
-            default: return Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(elements)));
         }
+        final Set<E> c = new LinkedHashSet<>(Arrays.asList(elements));
+        if (c.size() != elements.length) {
+            throw new IllegalArgumentException("Duplicated elements.");
+        }
+        return Collections.unmodifiableSet(c);
     }
 
     /**
@@ -88,7 +92,9 @@ public final class JDK9 {
     public static <K,V> Map<K,V> mapOf(final Object... entries) {
         final Map map = new HashMap();
         for (int i=0; i<entries.length;) {
-            map.put(entries[i++], entries[i++]);
+            if (map.put(entries[i++], entries[i++]) != null) {
+                throw new IllegalArgumentException("Duplicated elements.");
+            }
         }
         return map;
     }


Mime
View raw message