sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1596949 - in /sis/branches/JDK8/core: sis-feature/src/main/java/org/apache/sis/feature/ sis-utility/src/main/java/org/apache/sis/internal/util/ sis-utility/src/test/java/org/apache/sis/internal/util/
Date Thu, 22 May 2014 19:37:19 GMT
Author: desruisseaux
Date: Thu May 22 19:37:18 2014
New Revision: 1596949

URL: http://svn.apache.org/r1596949
Log:
Renamed an erroneous method name, and added test.

Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CheckedArrayListTest.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java?rev=1596949&r1=1596948&r2=1596949&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
[UTF-8] Thu May 22 19:37:18 2014
@@ -371,29 +371,28 @@ public abstract class AbstractFeature im
      */
     final Object verifyValueType(final String name, final Object value) {
         final PropertyType pt = getPropertyType(name);
-        /*
-         * Attribute :
-         *   - May be a singleton,  in which case the value class is verified.
-         *   - May be a collection, in which case the class each elemets in the collection
is verified.
-         */
         if (pt instanceof DefaultAttributeType<?>) {
+            /*
+             * Attribute :
+             *   - May be a singleton,  in which case the value class is verified.
+             *   - May be a collection, in which case the class each elemets in the collection
is verified.
+             */
             if (value != null) {
                 final Class<?> valueClass = ((DefaultAttributeType<?>) pt).getValueClass();
                 if (!valueClass.isInstance(value)) {
                     if (value instanceof Collection<?>) {
-                        return CheckedArrayList.wrapOrCopy((Collection<?>) value, valueClass);
+                        return CheckedArrayList.castOrCopy((Collection<?>) value, valueClass);
+                    } else {
+                        throw new ClassCastException(Errors.format(Errors.Keys.IllegalPropertyClass_2,
+                                name, value.getClass()));
                     }
-                    throw new ClassCastException(Errors.format(Errors.Keys.IllegalPropertyClass_2,
-                            name, value.getClass()));
                 }
             }
-            return value;
-        }
-        /*
-         * Association:
-         *   - May be a singleton,  in which case the feature type is verified.
-         */
-        if (pt instanceof DefaultAssociationRole) {
+        } else if (pt instanceof DefaultAssociationRole) {
+            /*
+             * Association:
+             *   - May be a singleton,  in which case the feature type is verified.
+             */
             if (value != null) {
                 if (value instanceof AbstractFeature) {
                     final DefaultFeatureType valueType = ((AbstractFeature) value).getType();
@@ -406,9 +405,14 @@ public abstract class AbstractFeature im
                             name, value.getClass()));
                 }
             }
-            return value;
+        } else {
+            /*
+             * Operation (or any other type):
+             *   - Legal in FeatureType, but not expected in Feature instance.
+             */
+            throw new IllegalArgumentException(unsupportedPropertyType(pt.getName()));
         }
-        throw new IllegalArgumentException(unsupportedPropertyType(pt.getName()));
+        return value;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java?rev=1596949&r1=1596948&r2=1596949&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
[UTF-8] Thu May 22 19:37:18 2014
@@ -101,7 +101,7 @@ public final class CheckedArrayList<E> e
      * @since 0.5
      */
     @SuppressWarnings("unchecked")
-    public static <E> CheckedArrayList<E> wrapOrCopy(final Collection<?>
collection, final Class<E> type) {
+    public static <E> CheckedArrayList<E> castOrCopy(final Collection<?>
collection, final Class<E> type) {
         if (collection == null) {
             return null;
         }

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CheckedArrayListTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CheckedArrayListTest.java?rev=1596949&r1=1596948&r2=1596949&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CheckedArrayListTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CheckedArrayListTest.java
[UTF-8] Thu May 22 19:37:18 2014
@@ -128,4 +128,34 @@ public final strictfp class CheckedArray
         testAddWrongType(list.subList(1, 3));
         // Exception message is JDK-dependent, so we can not test it.
     }
+
+    /**
+     * Tests {@link CheckedArrayList#castOrCopy(Collection, Class)}.
+     */
+    @Test
+    @DependsOnMethod("testAddAll")
+    public void testCastOrCopy() {
+        assertNull(CheckedArrayList.castOrCopy(null, String.class));
+        final List<String> fruits = Arrays.asList("Apple", "Orange", "Raisin");
+        final CheckedArrayList<String> asStrings = CheckedArrayList.castOrCopy(fruits,
String.class);
+        assertEquals ("Should have the given element type.", String.class, asStrings.getElementType());
+        assertNotSame("Should have created a new instance.", fruits, asStrings);
+        assertEquals ("Should contain the same data.",       fruits, asStrings);
+        assertSame   ("Should cast existing instance.", asStrings, CheckedArrayList.castOrCopy(asStrings,
String.class));
+
+        final CheckedArrayList<CharSequence> asChars = CheckedArrayList.castOrCopy(asStrings,
CharSequence.class);
+        assertEquals ("Should have the given element type.", CharSequence.class, asChars.getElementType());
+        assertNotSame("Should have created a new instance.", asStrings, asChars);
+        assertEquals ("Should contain the same data.",       asStrings, asChars);
+        assertEquals ("Should contain the same data.",       fruits,    asChars);
+
+        try {
+            CheckedArrayList.castOrCopy(asChars, Integer.class);
+            fail("Should not be allowed to cast String to Integer.");
+        } catch (ClassCastException e) {
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("String"));
+            assertTrue(message, message.contains("Integer"));
+        }
+    }
 }



Mime
View raw message