sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1479150 - in /sis/branches/JDK7: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/ sis-metadata/src/main/java/org...
Date Sat, 04 May 2013 18:20:09 GMT
Author: desruisseaux
Date: Sat May  4 18:20:09 2013
New Revision: 1479150

URL: http://svn.apache.org/r1479150
Log:
Removed 'asMap' and 'identifierMap' cached values, since their use are not very frequent.

Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultObjective.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java?rev=1479150&r1=1479149&r2=1479150&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] Sat May  4 18:20:09 2013
@@ -78,13 +78,6 @@ public abstract class AbstractMetadata i
     protected static final Logger LOGGER = Logging.getLogger(AbstractMetadata.class);
 
     /**
-     * A view of this metadata as a map. Will be created only when first needed.
-     *
-     * @see #asMap()
-     */
-    private transient Map<String,Object> asMap;
-
-    /**
      * Creates an initially empty metadata.
      */
     protected AbstractMetadata() {
@@ -194,10 +187,7 @@ public abstract class AbstractMetadata i
      * @see MetadataStandard#asValueMap(Object, KeyNamePolicy, ValueExistencePolicy)
      */
     public Map<String,Object> asMap() {
-        if (asMap == null) {
-            asMap = getStandard().asValueMap(this, KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_EMPTY);
-        }
-        return asMap;
+        return getStandard().asValueMap(this, KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_EMPTY);
     }
 
     /**

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java?rev=1479150&r1=1479149&r2=1479150&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] Sat May  4 18:20:09 2013
@@ -51,14 +51,6 @@ public class ISOMetadata extends Modifia
     protected Collection<Identifier> identifiers;
 
     /**
-     * The {@linkplain #getIdentifierMap() identifier map} as a wrapper around the
-     * {@linkplain #identifiers} collection. This map is created only when first needed.
-     *
-     * @see #getIdentifierMap()
-     */
-    private transient IdentifierMap identifierMap;
-
-    /**
      * Constructs an initially empty metadata.
      */
     protected ISOMetadata() {
@@ -102,19 +94,20 @@ public class ISOMetadata extends Modifia
     /**
      * {@inheritDoc}
      *
-     * <p>The default implementation returns a wrapper around the {@linkplain #identifiers}
list.
+     * <p>The default implementation returns a wrapper around the list returned by
{@link #getIdentifiers()}.
      * That map is <cite>live</cite>: changes in the identifiers list will be
reflected in the map,
      * and conversely.</p>
      */
     @Override
     public IdentifierMap getIdentifierMap() {
-        if (identifierMap == null) {
-            final Collection<Identifier> identifiers = getIdentifiers();
-            if (identifiers == null) {
-                return IdentifierMapWithSpecialCases.EMPTY;
-            }
-            identifierMap = new IdentifierMapWithSpecialCases(identifiers);
+        /*
+         * We do not cache (for now) the IdentifierMap because it is cheap to create, and
if were
+         * caching it we would need anyway to check if 'identifiers' still references the
same list.
+         */
+        final Collection<Identifier> identifiers = getIdentifiers();
+        if (identifiers == null) {
+            return IdentifierMapWithSpecialCases.EMPTY;
         }
-        return identifierMap;
+        return new IdentifierMapWithSpecialCases(identifiers);
     }
 }

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultObjective.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultObjective.java?rev=1479150&r1=1479149&r2=1479150&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultObjective.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultObjective.java
[UTF-8] Sat May  4 18:20:09 2013
@@ -162,8 +162,7 @@ public class DefaultObjective extends IS
     @Override
     @XmlElement(name = "identifier", required = true)
     public Collection<Identifier> getIdentifiers() {
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        return NonMarshalledAuthority.excludeOnMarshalling(identifiers);
+        return NonMarshalledAuthority.excludeOnMarshalling(super.getIdentifiers());
     }
 
     /**

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java?rev=1479150&r1=1479149&r2=1479150&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
[UTF-8] Sat May  4 18:20:09 2013
@@ -365,8 +365,7 @@ public class DefaultCitation extends ISO
     @Override
     @XmlElement(name = "identifier")
     public Collection<Identifier> getIdentifiers() {
-        identifiers = nonNullCollection(identifiers, Identifier.class);
-        return NonMarshalledAuthority.excludeOnMarshalling(identifiers);
+        return NonMarshalledAuthority.excludeOnMarshalling(super.getIdentifiers());
     }
 
     /**

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java?rev=1479150&r1=1479149&r2=1479150&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
[UTF-8] Sat May  4 18:20:09 2013
@@ -101,11 +101,6 @@ public class IdentifierMapAdapter extend
     public final Collection<Identifier> identifiers;
 
     /**
-     * A view over the entries, created only when first needed.
-     */
-    private transient Set<Entry<Citation,String>> entries;
-
-    /**
      * Creates a new map which will be a view over the given identifiers.
      *
      * @param identifiers The identifiers to wrap in a map view.
@@ -329,11 +324,14 @@ public class IdentifierMapAdapter extend
      * @return A view over the collection of identifiers.
      */
     @Override
-    public synchronized Set<Entry<Citation,String>> entrySet() {
-        if (entries == null) {
-            entries = new Entries(identifiers);
-        }
-        return entries;
+    public Set<Entry<Citation,String>> entrySet() {
+        /*
+         * Do not cache the entries set because if is very cheap to create and not needed
very often.
+         * Not caching allows this implementation to be thread-safe without synchronization
or volatile
+         * fields if the underlying list is thread-safe. Furthermore, IdentifierMapAdapter
are temporary
+         * objects anyway in the current ISOMetadata implementation.
+         */
+        return new Entries(identifiers);
     }
 
     /**



Mime
View raw message