sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1397139 - in /sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util: collection/Cache.java resources/Errors.java resources/Errors.properties resources/Errors_fr.properties
Date Thu, 11 Oct 2012 16:13:40 GMT
Author: desruisseaux
Date: Thu Oct 11 16:13:40 2012
New Revision: 1397139

URL: http://svn.apache.org/viewvc?rev=1397139&view=rev
Log:
Removed the tolerance to key collisions from the Cache class. We will try to be strict, and
maybe re-introduce this tolerance if we really can't avoid it.

Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.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

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java?rev=1397139&r1=1397138&r2=1397139&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
Thu Oct 11 16:13:40 2012
@@ -177,13 +177,6 @@ public class Cache<K,V> extends Abstract
     private final boolean soft;
 
     /**
-     * {@code true} if different values may be assigned to the same key. This is usually
-     * an error, so the default {@code Cache} behavior is to thrown an exception in such
-     * case.
-     */
-    private volatile boolean keyCollisionAllowed;
-
-    /**
      * A view over the entries in the cache.
      */
     private transient Set<Entry<K,V>> entries;
@@ -523,18 +516,6 @@ public class Cache<K,V> extends Abstract
             @SuppressWarnings("unchecked")
             final Work work = (Work) value;
             if (work.isHeldByCurrentThread()) {
-                if (isKeyCollisionAllowed()) {
-                    /*
-                     * Example of key collision: the EPSG database defines the CoordinateOperation
-                     * 8653 ("ED50 to WGS84" using polynomial equations).  The EPSG factory
sets a
-                     * lock for this code, then searches for OperationParameters associated
to this
-                     * operation. One of those parameters ("Bu0v4") has the same key (EPSG:8653).
-                     * So we get a key collision. If we ignore the second occurrence, its
value will
-                     * not be cached. This is okay since the value that we really want to
cache is
-                     * CoordinateOperation, which is associated to the first occurrence of
that key.
-                     */
-                    return new Simple<>(null);
-                }
                 throw new IllegalStateException(Errors.format(Errors.Keys.RecursiveCreateCallForKey_1,
key));
             }
             return work.new Wait();
@@ -629,8 +610,6 @@ public class Cache<K,V> extends Abstract
 
         /**
          * Do nothing (except checking for programming error), since we don't hold any lock.
-         * We do not localize the exception message since it is targeted to the developer
-         * rather than the end user.
          *
          * {@note An alternative would have been to store the result in the map anyway.
          *        But doing so is unsafe because we have no lock; we have no guarantee that
@@ -638,8 +617,8 @@ public class Cache<K,V> extends Abstract
          */
         @Override
         public void putAndUnlock(final V result) throws IllegalStateException {
-            if (result != value && !isKeyCollisionAllowed()) {
-                throw new IllegalStateException("Key collision: the cache already has a value.");
+            if (result != value) {
+                throw new IllegalStateException(Errors.format(Errors.Keys.KeyCollision_1,
"<unknown>"));
             }
         }
     }
@@ -653,7 +632,7 @@ public class Cache<K,V> extends Abstract
         /**
          * The key to use for storing the result in the map.
          */
-        private final K key;
+        final K key;
 
         /**
          * The result. This is initially null, as we expect since the value has not yet
@@ -737,8 +716,6 @@ public class Cache<K,V> extends Abstract
 
             /**
              * Do nothing (except checking for programming error), since we don't hold any
lock.
-             * We do not localize the exception message since it is targeted to the developer
-             * rather than the end user.
              *
              * {@note An alternative would have been to store the result in the map anyway.
              *        But doing so is unsafe because we have no lock; we have no guarantee
and
@@ -746,8 +723,8 @@ public class Cache<K,V> extends Abstract
              */
             @Override
             public void putAndUnlock(final V result) throws IllegalStateException {
-                if (result != get() && !isKeyCollisionAllowed()) {
-                    throw new IllegalStateException("Key collision: the cache already has
a value.");
+                if (result != get()) {
+                    throw new IllegalStateException(Errors.format(Errors.Keys.KeyCollision_1,
key));
                 }
             }
         }
@@ -876,40 +853,6 @@ public class Cache<K,V> extends Abstract
     }
 
     /**
-     * Returns {@code true} if different values may be assigned to the same key.
-     * The default value is {@code false}.
-     *
-     * @return {@code true} if key collisions are allowed.
-     */
-    public boolean isKeyCollisionAllowed() {
-        return keyCollisionAllowed;
-    }
-
-    /**
-     * If set to {@code true}, different values may be assigned to the same key. This is
usually an
-     * error, so the default {@code Cache} behavior is to thrown an {@link IllegalStateException}
-     * in such cases, typically when {@link Handler#putAndUnlock(Object)} is invoked. However
in
-     * some cases we may want to relax this check. For example the EPSG database sometime
assigns
-     * the same key to different kind of objects.
-     * <p>
-     * If key collisions are allowed, then if two threads invoke {@link #lock(Object)} concurrently
-     * for the same key, then the value to be stored in the map will be the one computed
by the first
-     * thread to get the lock. The value computed by any other concurrent thread will be
ignored by
-     * this {@code Cache} class (however that thread would still return its computed value
to its
-     * user).
-     * <p>
-     * This property can also be set in order to allow some recursivity. If during the creation
of
-     * an object, the program asks to this {@code Cache} for the same object (using the
same key),
-     * then the default {@code Cache} implementation will consider this situation as a key
collision
-     * unless this property has been set to {@code true}.
-     *
-     * @param allowed {@code true} if key collisions should be allowed.
-     */
-    public void setKeyCollisionAllowed(final boolean allowed) {
-        keyCollisionAllowed = allowed;
-    }
-
-    /**
      * Computes an estimation of the cost of the given value. The default implementation
returns 1
      * in all cases. Subclasses should override this method if they have some easy way to
measure
      * the relative cost of value objects.

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=1397139&r1=1397138&r2=1397139&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
Thu Oct 11 16:13:40 2012
@@ -97,6 +97,11 @@ public final class Errors extends Indexe
         public static final int IndexOutOfBounds_1 = 4;
 
         /**
+         * A different value is already associated to the “{0}” key.
+         */
+        public static final int KeyCollision_1 = 19;
+
+        /**
          * Argument ‘{0}’ shall not be negative. The given value was {1}.
          */
         public static final int NegativeArgument_2 = 8;

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=1397139&r1=1397138&r2=1397139&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
Thu Oct 11 16:13:40 2012
@@ -24,6 +24,7 @@ IllegalClass_2                  = Class 
 IllegalLanguageCode_1           = The \u201c{0}\u201d language is not recognized.
 IllegalRange_2                  = Range [{0} \u2026 {1}] is not valid.
 IndexOutOfBounds_1              = Index {0} is out of bounds.
+KeyCollision_1                  = A different value is already associated to the \u201c{0}\u201d
key.
 NegativeArgument_2              = Argument \u2018{0}\u2019 shall not be negative. The given
value was {1}.
 NotANumber_1                    = Argument \u2018{0}\u2019 shall not be NaN (Not-a-Number).
 NotAPrimitiveWrapper_1          = Class \u2018{0}\u2019 is not a primitive type wrapper.

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=1397139&r1=1397138&r2=1397139&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
Thu Oct 11 16:13:40 2012
@@ -24,6 +24,7 @@ IllegalClass_2                  = La cla
 IllegalLanguageCode_1           = Le code de langue \u201c{0}\u201d n\u2019est pas reconnu.
 IllegalRange_2                  = La plage [{0} \u2026 {1}] n\u2019est pas valide.
 IndexOutOfBounds_1              = L\u2019index {0} est en dehors des limites permises.
+KeyCollision_1                  = Une valeur diff\u00e9rente est d\u00e9j\u00e0 associ\u00e9e
\u00e0 la cl\u00e9 \u201c{0}\u201d.
 NegativeArgument_2              = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre n\u00e9gatif.
La valeur donn\u00e9e \u00e9tait {1}.
 NotANumber_1                    = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre NaN
(Not-a-Number).
 NotAPrimitiveWrapper_1          = La classe \u2018{0}\u2019 n\u2019est pas un adaptateur
d\u2019un type primitif.



Mime
View raw message