sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1450122 - in /sis/branches/JDK7/sis-utility/src: main/java/org/apache/sis/util/collection/ main/java/org/apache/sis/util/resources/ test/java/org/apache/sis/test/suite/ test/java/org/apache/sis/util/collection/
Date Tue, 26 Feb 2013 10:47:46 GMT
Author: desruisseaux
Date: Tue Feb 26 10:47:45 2013
New Revision: 1450122

URL: http://svn.apache.org/r1450122
Log:
Added a test case for CodeListSet.

Added:
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/CodeListSetTest.java
  (with props)
Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CodeListSet.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CodeListSet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CodeListSet.java?rev=1450122&r1=1450121&r2=1450122&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CodeListSet.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CodeListSet.java
[UTF-8] Tue Feb 26 10:47:45 2013
@@ -21,9 +21,9 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.io.Serializable;
+import java.lang.reflect.Modifier;
 import org.opengis.util.CodeList;
 import org.apache.sis.util.iso.Types;
-import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -38,7 +38,7 @@ import org.apache.sis.util.resources.Err
  * {@note The standard <code>EnumSet</code> class uses different implementations
depending on
  *        whether the enumeration contains more or less than 64 elements. We can not apply
the
  *        same strategy for <code>CodeListSet</code>, because new code list elements
can be created
- *        at runtime. Consequently this implementation needs to be able to handle every cases.}
+ *        at runtime. Consequently this implementation needs to be able to growth its capacity.}
  *
  * @param <E> The type of code list elements in the set.
  *
@@ -74,11 +74,15 @@ public class CodeListSet<E extends CodeL
 
     /**
      * Creates an initially empty set for code lists of the given type.
+     * The given {@code CodeList} type shall be final.
      *
-     * @param elementType The type of code list elements to be included in this set.
+     * @param  elementType The type of code list elements to be included in this set.
+     * @throws IllegalArgumentException If the given class is not final.
      */
-    public CodeListSet(final Class<E> elementType) {
-        ArgumentChecks.ensureNonNull("elementType", elementType);
+    public CodeListSet(final Class<E> elementType) throws IllegalArgumentException
{
+        if (!Modifier.isFinal(elementType.getModifiers())) {
+            throw new IllegalArgumentException(Errors.format(Errors.Keys.ClassNotFinal_1,
elementType));
+        }
         this.elementType = elementType;
     }
 
@@ -278,7 +282,7 @@ public class CodeListSet<E extends CodeL
          */
         @Override
         public E next() {
-            final int index = Long.numberOfLeadingZeros(remaining);
+            final int index = Long.numberOfTrailingZeros(remaining);
             if (index >= Long.SIZE) {
                 throw new NoSuchElementException();
             }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1450122&r1=1450121&r2=1450122&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Tue Feb 26 10:47:45 2013
@@ -68,6 +68,11 @@ public final class Errors extends Indexe
         public static final int CanNotComputeDerivative = 44;
 
         /**
+         * Class ‘{0}’ is not final.
+         */
+        public static final int ClassNotFinal_1 = 71;
+
+        /**
          * Can not clone an object of type ‘{0}’.
          */
         public static final int CloneNotSupported_1 = 42;

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1450122&r1=1450121&r2=1450122&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Tue Feb 26 10:47:45 2013
@@ -24,8 +24,8 @@
 # programmatic parameters do not have to be last in the formatted text, since each localized
message
 # can reorder the parameters as they want.
 #
-
 CanNotComputeDerivative         = Can not compute the derivative.
+ClassNotFinal_1                 = Class \u2018{0}\u2019 is not final.
 CloneNotSupported_1             = Can not clone an object of type \u2018{0}\u2019.
 DeadThread_1                    = Thread \u201c{0}\u201d is dead.
 DuplicatedValue_1               = Value \u201c{0}\u201d is duplicated.

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1450122&r1=1450121&r2=1450122&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Tue Feb 26 10:47:45 2013
@@ -15,6 +15,7 @@
 # limitations under the License.
 #
 CanNotComputeDerivative         = La d\u00e9riv\u00e9 ne peut pas \u00eatre calcul\u00e9e.
+ClassNotFinal_1                 = La classe \u2018{0}\u2019 n\u2019est pas finale.
 CloneNotSupported_1             = Un objet de type \u2018{0}\u2019 ne peut pas \u00eatre
clon\u00e9.
 DeadThread_1                    = La t\u00e2che \u201c{0}\u201d est morte.
 DuplicatedValue_1               = La valeur \u201c{0}\u201d est dupliqu\u00e9e.

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1450122&r1=1450121&r2=1450122&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Tue Feb 26 10:47:45 2013
@@ -60,6 +60,7 @@ import org.junit.runners.Suite;
     org.apache.sis.util.collection.TableColumnTest.class,
     org.apache.sis.util.collection.DefaultTreeTableTest.class,
     org.apache.sis.util.collection.TreeTablesTest.class,
+    org.apache.sis.util.collection.CodeListSetTest.class,
 
     // GeoAPI most basic types.
     org.apache.sis.util.iso.TypesTest.class,

Added: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/CodeListSetTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/CodeListSetTest.java?rev=1450122&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/CodeListSetTest.java
(added)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/CodeListSetTest.java
[UTF-8] Tue Feb 26 10:47:45 2013
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.util.collection;
+
+import org.opengis.referencing.cs.AxisDirection;
+import org.apache.sis.test.TestCase;
+import org.apache.sis.test.DependsOnMethod;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.opengis.referencing.cs.AxisDirection.*;
+
+
+/**
+ * Test the {@link CodeListSet} implementation.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final strictfp class CodeListSetTest extends TestCase {
+    /**
+     * Creates a new set filled with up to 4 axis directions.
+     * The directions are (NORTH, EAST, UP, FUTURE) in that order.
+     *
+     * @param n Number of code list to add.
+     */
+    @SuppressWarnings("fallthrough")
+    private CodeListSet<AxisDirection> create(final int n) {
+        final CodeListSet<AxisDirection> c = new CodeListSet<>(AxisDirection.class);
+        assertTrue(c.isEmpty());
+        switch (n) {
+            default: throw new AssertionError(n);
+            case 4: assertTrue(c.add(FUTURE)); // Fallthrough everywhere.
+            case 3: assertTrue(c.add(UP));
+            case 2: assertTrue(c.add(EAST));
+            case 1: assertTrue(c.add(NORTH));
+            case 0: break;
+        }
+        assertEquals("SortedSet.size()", n, c.size());
+        return c;
+    }
+
+    /**
+     * Tests the {@link CodeListSet#toArray()} method.
+     * This will indirectly tests the iterator.
+     */
+    @Test
+    public void testToArray() {
+        final CodeListSet<AxisDirection> c = create(4);
+        assertArrayEquals(new Object[] {NORTH, EAST, UP, FUTURE}, c.toArray());
+    }
+
+    /**
+     * Tests the {@link CodeListSet#clear()} method.
+     */
+    @Test
+    public void testClear() {
+        final CodeListSet<AxisDirection> c = create(2);
+        assertFalse(c.isEmpty());
+        c.clear();
+        assertTrue(c.isEmpty());
+    }
+
+    /**
+     * Tests the {@link CodeListSet#contains(Object)} method.
+     */
+    @Test
+    public void testContains() {
+        final CodeListSet<AxisDirection> c = create(4);
+        assertTrue ("NORTH",  c.contains(NORTH));
+        assertFalse("SOUTH",  c.contains(SOUTH));
+        assertTrue ("FUTURE", c.contains(FUTURE));
+        assertFalse("PAST",   c.contains(PAST));
+        assertTrue ("EAST",   c.contains(EAST));
+        assertFalse("WEST",   c.contains(WEST));
+        assertTrue ("UP",     c.contains(UP));
+        assertFalse("DOWN",   c.contains(DOWN));
+    }
+
+    /**
+     * Tests the {@link CodeListSet#remove(Object)} method.
+     */
+    @Test
+    @DependsOnMethod("testContains")
+    public void testRemove() {
+        final CodeListSet<AxisDirection> c = create(4);
+        assertTrue ("NORTH",  c.remove  (NORTH));
+        assertFalse("SOUTH",  c.remove  (SOUTH));
+        assertFalse("NORTH",  c.contains(NORTH));
+        assertEquals(3, c.size());
+
+        assertTrue ("FUTURE", c.remove  (FUTURE));
+        assertFalse("FUTURE", c.contains(FUTURE));
+        assertFalse("PAST",   c.remove  (PAST));
+        assertEquals(2, c.size());
+
+        assertTrue ("EAST",   c.remove  (EAST));
+        assertTrue ("UP",     c.remove  (UP));
+        assertTrue (c.isEmpty());
+    }
+
+    /**
+     * Tests the {@link CodeListSet#containsAll(Collection)} method.
+     */
+    @Test
+    @DependsOnMethod("testRemove")
+    public void testContainsAll() {
+        final CodeListSet<AxisDirection> c = create(4);
+        final CodeListSet<AxisDirection> o = create(4);
+        assertTrue (c.containsAll(o));
+        assertTrue (o.remove(NORTH));
+        assertTrue (o.remove(FUTURE));
+        assertTrue (c.containsAll(o));
+        assertTrue (o.add(NORTH_EAST));
+        assertFalse(c.containsAll(o));
+    }
+
+    /**
+     * Tests the {@link CodeListSet#removeAll(Collection)} method.
+     */
+    @Test
+    @DependsOnMethod("testToArray")
+    public void testRemoveAll() {
+        final CodeListSet<AxisDirection> c = create(4);
+        final CodeListSet<AxisDirection> o = create(2);
+        assertTrue(o.add(NORTH_EAST)); // Extra value shall be ignored.
+
+        assertTrue(c.removeAll(o));
+        assertArrayEquals(new Object[] {UP, FUTURE}, c.toArray());
+        assertFalse("Invoking a second time should not make any difference.", c.removeAll(o));
+        assertEquals(2, c.size());
+    }
+
+    /**
+     * Tests the {@link CodeListSet#removeAll(Collection)} method.
+     */
+    @Test
+    @DependsOnMethod("testToArray")
+    public void testRetainAll() {
+        final CodeListSet<AxisDirection> c = create(4);
+        final CodeListSet<AxisDirection> o = create(2);
+        assertTrue(o.add(NORTH_EAST)); // Extra value shall be ignored.
+
+        assertTrue(c.retainAll(o));
+        assertArrayEquals(new Object[] {NORTH, EAST}, c.toArray());
+        assertFalse("Invoking a second time should not make any difference.", c.retainAll(o));
+        assertEquals(2, c.size());
+    }
+
+    /**
+     * Tests the {@link CodeListSet#addAll(Collection)} method.
+     */
+    @Test
+    @DependsOnMethod("testToArray")
+    public void testAddAll() {
+        final CodeListSet<AxisDirection> c = create(1);
+        final CodeListSet<AxisDirection> o = create(3);
+        assertTrue(c.add(NORTH_EAST));
+
+        assertTrue(c.addAll(o));
+        assertArrayEquals(new Object[] {NORTH, NORTH_EAST, EAST, UP}, c.toArray());
+        assertFalse("Invoking a second time should not make any difference.", c.addAll(o));
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/CodeListSetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/CodeListSetTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8



Mime
View raw message