sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1795677 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/metadata/sql/ sis-utility/src/main/java/org/apache/sis/internal/util/ sis-utility/src/main/java/org/apache/sis/util/
Date Sat, 20 May 2017 17:20:56 GMT
Author: desruisseaux
Date: Sat May 20 17:20:56 2017
New Revision: 1795677

URL: http://svn.apache.org/viewvc?rev=1795677&view=rev
Log:
Handle empty collections of various types in a new CollectionsExt method instead than inline
other methods.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java?rev=1795677&r1=1795676&r2=1795677&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
[UTF-8] Sat May 20 17:20:56 2017
@@ -923,15 +923,7 @@ public class MetadataSource implements A
          */
         if (value == null) {
             if (wantCollection) {
-                if (Set.class.isAssignableFrom(returnType)) {
-                    if (SortedSet.class.isAssignableFrom(returnType)) {
-                        return Collections.emptySortedSet();
-                    } else {
-                        return Collections.EMPTY_SET;
-                    }
-                } else {
-                    return Collections.EMPTY_LIST;
-                }
+                return CollectionsExt.empty(returnType);
             }
         } else {
             if (isMetadata) {

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java?rev=1795677&r1=1795676&r2=1795677&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] Sat May 20 17:20:56 2017
@@ -60,6 +60,32 @@ public final class CollectionsExt extend
     }
 
     /**
+     * Returns an empty collection of the given type, or {@code null} if the given type is
unknown to this method.
+     *
+     * @param  type  the desired collection type.
+     * @return an empty collection of the given type, or {@code null} if the type is unknown.
+     *
+     * @since 0.8
+     */
+    public static Collection<?> empty(final Class<?> type) {
+        if (type.isAssignableFrom(List.class)) {                    // Most common case first.
+            return Collections.EMPTY_LIST;
+        } else if (type.isAssignableFrom(Set.class)) {
+            return Collections.EMPTY_SET;
+        } else if (type.isAssignableFrom(NavigableSet.class)) {     // Rarely used case (at
least in SIS).
+            if (type.isAssignableFrom(SortedSet.class)) {
+                return Collections.emptySortedSet();
+            } else {
+                return Collections.emptyNavigableSet();
+            }
+        } else if (type.isAssignableFrom(Queue.class)) {
+            return emptyQueue();
+        } else {
+            return null;
+        }
+    }
+
+    /**
      * Returns the first element of the given iterable, or {@code null} if none.
      * This method does not emit warning if more than one element is found.
      * Consequently, this method should be used only when multi-occurrence is not ambiguous.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java?rev=1795677&r1=1795676&r2=1795677&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java [UTF-8]
Sat May 20 17:20:56 2017
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Queue;
 import java.util.Set;
 import java.util.SortedSet;
+import java.util.NavigableSet;
 import java.util.Collections;
 import java.lang.reflect.Array;
 import java.math.BigDecimal;
@@ -692,10 +693,11 @@ public final class Numbers extends Stati
                 return (T) mapping.nullValue;
             }
         } else if (type != null && type != Object.class) {
-            if (type == Map      .class) return (T) Collections.EMPTY_MAP;
-            if (type == List     .class) return (T) Collections.EMPTY_LIST;
-            if (type == Queue    .class) return (T) CollectionsExt.emptyQueue();
-            if (type == SortedSet.class) return (T) Collections.emptySortedSet();
+            if (type == Map         .class) return (T) Collections.EMPTY_MAP;
+            if (type == List        .class) return (T) Collections.EMPTY_LIST;
+            if (type == Queue       .class) return (T) CollectionsExt.emptyQueue();
+            if (type == SortedSet   .class) return (T) Collections.emptySortedSet();
+            if (type == NavigableSet.class) return (T) Collections.emptyNavigableSet();
             if (type.isAssignableFrom(Set.class)) {
                 return (T) Collections.EMPTY_SET;
             }



Mime
View raw message