sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1468909 - in /sis/branches/JDK7: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-metadata/src/test/java/org/apache/sis/metadata/ sis-referencing/src/test/java/org/apache/sis/geometry/ sis-utility/src/main/java/org/apache/sis/intern...
Date Wed, 17 Apr 2013 13:38:25 GMT
Author: desruisseaux
Date: Wed Apr 17 13:38:25 2013
New Revision: 1468909

URL: http://svn.apache.org/r1468909
Log:
Metadata hash code shall be different for different interfaces.

Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
    sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/SubEnvelopeTest.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Containers.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java?rev=1468909&r1=1468908&r2=1468909&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] Wed Apr 17 13:38:25 2013
@@ -553,10 +553,10 @@ public class MetadataStandard {
     }
 
     /**
-     * Computes a hash code for the specified metadata. The hash code is defined as the
-     * sum of hash code values of all non-empty properties. This is a similar contract
-     * than {@link java.util.Set#hashCode()} and ensures that the hash code value is
-     * insensitive to the ordering of properties.
+     * Computes a hash code for the specified metadata. The hash code is defined as the sum
+     * of hash code values of all non-empty properties, plus the hash code of the interface.
+     * This is a similar contract than {@link java.util.Set#hashCode()} (except for the interface)
+     * and ensures that the hash code value is insensitive to the ordering of properties.
      *
      * @param  metadata The metadata object to compute hash code.
      * @return A hash code value for the specified metadata.

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1468909&r1=1468908&r2=1468909&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] Wed Apr 17 13:38:25 2013
@@ -990,16 +990,16 @@ final class PropertyAccessor {
     }
 
     /**
-     * Computes a hash code for the specified metadata. The hash code is defined as the
-     * sum of hash code values of all non-empty properties. This is a similar contract
-     * than {@link java.util.Set#hashCode()} and ensures that the hash code value is
-     * insensitive to the ordering of properties.
+     * Computes a hash code for the specified metadata. The hash code is defined as the sum
+     * of hash code values of all non-empty properties, plus the hash code of the interface.
+     * This is a similar contract than {@link java.util.Set#hashCode()} (except for the interface)
+     * and ensures that the hash code value is insensitive to the ordering of properties.
      *
      * @throws BackingStoreException If the implementation threw a checked exception.
      */
     public int hashCode(final Object metadata) throws BackingStoreException {
         assert type.isInstance(metadata) : metadata;
-        int code = 0;
+        int code = type.hashCode();
         for (int i=0; i<standardCount; i++) {
             final Object value = get(getters[i], metadata);
             if (!isNullOrEmpty(value)) {

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java?rev=1468909&r1=1468908&r2=1468909&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataStandardTest.java
[UTF-8] Wed Apr 17 13:38:25 2013
@@ -27,12 +27,12 @@ import org.apache.sis.metadata.iso.citat
 import org.apache.sis.metadata.iso.quality.AbstractCompleteness;
 import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.opengis.test.Assert.*;
-import org.apache.sis.test.DependsOnMethod;
 
 
 /**
@@ -153,8 +153,9 @@ public final strictfp class MetadataStan
     }
 
     /**
-     * Tests {@link MetadataStandard#hashCode(Object)} using {@link HashSet}
-     * as the reference implementation for hash code values.
+     * Tests {@link MetadataStandard#hashCode(Object)} using {@link HashSet} as the reference
+     * implementation for computing hash code values. The hash code is defined as the sum
of
+     * hash code values of all non-empty properties, plus the hash code of the interface.
      */
     @Test
     @DependsOnMethod("testMap")
@@ -164,6 +165,7 @@ public final strictfp class MetadataStan
         final Map<String,Object> map = std.asMap(instance,
                 KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_EMPTY);
         assertFalse(map.isEmpty()); // Actually 'testMap()' job, but verified for safety.
-        assertEquals("hashCode()", new HashSet<>(map.values()).hashCode(), std.hashCode(instance));
+        assertEquals("hashCode()", new HashSet<>(map.values()).hashCode() + Citation.class.hashCode(),
+                std.hashCode(instance));
     }
 }

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java?rev=1468909&r1=1468908&r2=1468909&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
[UTF-8] Wed Apr 17 13:38:25 2013
@@ -379,17 +379,18 @@ public final strictfp class PropertyAcce
     public void testHashCode() {
         final DefaultCitation  instance = new DefaultCitation();
         final PropertyAccessor accessor = createPropertyAccessor();
+        final int              baseCode = Citation.class.hashCode();
         int hashCode = accessor.hashCode(instance);
-        assertEquals("Empty metadata.", 0, hashCode);
+        assertEquals("Empty metadata.", baseCode, hashCode);
 
         final InternationalString title = new SimpleInternationalString("Some title");
         instance.setTitle(title);
         hashCode = accessor.hashCode(instance);
-        assertEquals("Metadata with a single value.", title.hashCode(), hashCode);
+        assertEquals("Metadata with a single value.", baseCode + title.hashCode(), hashCode);
 
         final InternationalString alternateTitle = new SimpleInternationalString("An other
title");
         instance.setAlternateTitles(singleton(alternateTitle));
         hashCode = accessor.hashCode(instance);
-        assertEquals("Metadata with two values.", title.hashCode() + Arrays.asList(alternateTitle).hashCode(),
hashCode);
+        assertEquals("Metadata with two values.", baseCode + title.hashCode() + Arrays.asList(alternateTitle).hashCode(),
hashCode);
     }
 }

Modified: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/SubEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/SubEnvelopeTest.java?rev=1468909&r1=1468908&r2=1468909&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/SubEnvelopeTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/SubEnvelopeTest.java
[UTF-8] Wed Apr 17 13:38:25 2013
@@ -27,7 +27,7 @@ import static org.apache.sis.geometry.Ge
 
 
 /**
- * Tests the {@link SubEnvelopeTest} class. This method leverage the tests written for
+ * Tests the {@link SubEnvelope} class. This method leverage the tests written for
  * {@link GeneralEnvelope}, but using a sub-envelope instead than a full envelope.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java?rev=1468909&r1=1468908&r2=1468909&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java
[UTF-8] Wed Apr 17 13:38:25 2013
@@ -117,6 +117,9 @@ public class UnmodifiableArrayList<E> ex
      * specified sub-region of the given array shall not be modified after construction if
the
      * returned list is intended to be immutable.
      *
+     * <p>This method does not check the validity of the given index.
+     * The check must be done by the caller.</p>
+     *
      * {@section WARNING! Type safety hole}
      * Callers <strong>must</strong> ensure that the type of array elements in
exactly {@code E},
      * not a subtype of {@code E}. If the caller is okay with {@code List<? extends E>},
then (s)he
@@ -128,13 +131,10 @@ public class UnmodifiableArrayList<E> ex
      * @param  lower Low endpoint (inclusive) of the sublist.
      * @param  upper High endpoint (exclusive) of the sublist.
      * @return The given array wrapped in an unmodifiable list.
-     * @throws IndexOutOfBoundsException If the lower or upper value are out of bounds.
      */
     public static <E> UnmodifiableArrayList<E> wrap(final E[] array, final int
lower, final int upper)
             throws IndexOutOfBoundsException
     {
-        ArgumentChecks.ensureNonNull("array", array);
-        ArgumentChecks.ensureValidIndexRange(array.length, lower, upper);
         if (lower == 0 && upper == array.length) {
             return new UnmodifiableArrayList<>(array);
         }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Containers.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Containers.java?rev=1468909&r1=1468908&r2=1468909&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Containers.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Containers.java
[UTF-8] Wed Apr 17 13:38:25 2013
@@ -117,6 +117,8 @@ public final class Containers extends St
      * @throws IndexOutOfBoundsException If the lower or upper value are out of bounds.
      */
     public static <E> List<? extends E> unmodifiableList(final E[] array, final
int lower, final int upper) {
+        ArgumentChecks.ensureNonNull("array", array);
+        ArgumentChecks.ensureValidIndexRange(array.length, lower, upper);
         return UnmodifiableArrayList.wrap(array, lower, upper);
     }
 



Mime
View raw message