sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1470021 - in /sis/branches/JDK7: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-metadata/src/test/java/org/apache/sis/metadata/ sis-utility/src/main/java/org/apache/sis/internal/util/
Date Fri, 19 Apr 2013 20:25:31 GMT
Author: desruisseaux
Date: Fri Apr 19 20:25:30 2013
New Revision: 1470021

URL: http://svn.apache.org/r1470021
Log:
Slightly more efficient previous value returned by ValueMap.put(...) in the common case where
it is a List.

Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.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/ValueMapTest.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java?rev=1470021&r1=1470020&r2=1470021&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
[UTF-8] Fri Apr 19 20:25:30 2013
@@ -582,11 +582,11 @@ public abstract class ModifiableMetadata
     private final class MutableSet<E> extends CheckedHashSet<E> {
         private static final long serialVersionUID = 3032602282358733056L;
 
-        public MutableSet(Class<E> type) {
+        MutableSet(Class<E> type) {
             super(type, 4); // Use a small capacity because we typically have few elements.
         }
 
-        public MutableSet(Class<E> type, int capacity) {
+        MutableSet(Class<E> type, int capacity) {
             super(type, hashMapCapacity(capacity));
         }
 
@@ -614,11 +614,11 @@ public abstract class ModifiableMetadata
     private final class MutableList<E> extends CheckedArrayList<E> {
         private static final long serialVersionUID = 5800381255701183058L;
 
-        public MutableList(Class<E> type) {
+        MutableList(Class<E> type) {
             super(type, 4); // Use a small capacity because we typically have few elements.
         }
 
-        public MutableList(Class<E> type, int capacity) {
+        MutableList(Class<E> type, int capacity) {
             super(type, capacity);
         }
 

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=1470021&r1=1470020&r2=1470021&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] Fri Apr 19 20:25:30 2013
@@ -18,6 +18,7 @@ package org.apache.sis.metadata;
 
 import java.util.Set;
 import java.util.Map;
+import java.util.List;
 import java.util.Arrays;
 import java.util.Locale;
 import java.util.HashMap;
@@ -49,6 +50,7 @@ import org.apache.sis.xml.IdentifiedObje
 
 import static org.apache.sis.metadata.PropertyComparator.*;
 import static org.apache.sis.internal.util.Utilities.floatEpsilonEqual;
+import static org.apache.sis.internal.util.CollectionsExt.snapshot;
 import static org.apache.sis.internal.util.CollectionsExt.modifiableCopy;
 import static org.apache.sis.util.collection.Containers.hashMapCapacity;
 
@@ -668,7 +670,11 @@ final class PropertyAccessor {
                 if (getOld) {
                     old = get(getter, metadata);
                     if (old instanceof Collection<?>) {
-                        old = modifiableCopy((Collection<?>) old);
+                        if (old instanceof List<?>) {
+                            old = snapshot((List<?>) old);
+                        } else {
+                            old = modifiableCopy((Collection<?>) old);
+                        }
                     } else if (old instanceof Map<?,?>) {
                         old = modifiableCopy((Map<?,?>) old);
                     }

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=1470021&r1=1470020&r2=1470021&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] Fri Apr 19 20:25:30 2013
@@ -55,8 +55,12 @@ import static org.opengis.test.Assert.*;
  * @version 0.3
  * @module
  */
-@DependsOn({PropertyAccessorTest.class, InformationMapTest.class,
-    NameMapTest.class, TypeMapTest.class, ValueMapTest.class})
+@DependsOn({
+    PropertyAccessorTest.class,
+    InformationMapTest.class,
+    NameMapTest.class,
+    TypeMapTest.class,
+    ValueMapTest.class})
 public final strictfp class MetadataStandardTest extends TestCase {
     /**
      * Tests {@link MetadataStandard#getInterface(Class)}.

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java?rev=1470021&r1=1470020&r2=1470021&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
[UTF-8] Fri Apr 19 20:25:30 2013
@@ -200,13 +200,13 @@ public final strictfp class ValueMapTest
     }
 
     /**
-     * Tests the {@link ValueMap#add(String,Object)} and {@link ValueMap#remove(Object)}
methods.
+     * Tests the {@link ValueMap#put(String,Object)} and {@link ValueMap#remove(Object)}
methods.
      * Note that this test is intentionally sensitive to iteration order.
      * That order shall be fixed by the {@code XmlType} annotation.
      */
     @Test
     @DependsOnMethod("testEntrySet")
-    public void testAddAndRemove() {
+    public void testPutAndRemove() {
         final Map<String,Object> map = createCitation();
         /*
          * Remove the ISBN value. Result shall be:

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java?rev=1470021&r1=1470020&r2=1470021&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] Fri Apr 19 20:25:30 2013
@@ -281,6 +281,27 @@ public final class CollectionsExt extend
     }
 
     /**
+     * Returns a snapshot of the given list. The returned list will not be affected by changes
+     * in the given list after this method call. This method makes no guaranteed about whether
+     * the returned list is modifiable or not.
+     *
+     * @param  <E>  The type of elements in the list.
+     * @param  list The list for which to take a snapshot, or {@code null} if none.
+     * @return A snapshot of the given list, or {@code list} itself if null or unmodifiable.
+     */
+    @SuppressWarnings("unchecked")
+    public static <E> List<E> snapshot(final List<E> list) {
+        if (list != null && !(list instanceof UnmodifiableArrayList<?>)) {
+            switch (list.size()) {
+                case 0:  return Collections.emptyList();
+                case 1:  return Collections.singletonList(list.get(0));
+                default: return (List<E>) Arrays.asList(list.toArray());
+            }
+        }
+        return list;
+    }
+
+    /**
      * Returns the given value as a collection. Special cases:
      *
      * <ul>



Mime
View raw message