sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1416113 - in /sis/branches/JDK7: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/ sis-utility/src/main/java/org/apache/sis/util/collection/
Date Sun, 02 Dec 2012 07:02:40 GMT
Author: desruisseaux
Date: Sun Dec  2 07:02:39 2012
New Revision: 1416113

URL: http://svn.apache.org/viewvc?rev=1416113&view=rev
Log:
ModifiableMetadata shall not allow null values in the collections.
Clarified the behavior with null values in other SIS classes.

Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.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=1416113&r1=1416112&r2=1416113&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
(original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
Sun Dec  2 07:02:39 2012
@@ -26,6 +26,7 @@ import org.opengis.util.CodeList;
 import org.apache.sis.util.collection.CheckedHashSet;
 import org.apache.sis.util.collection.CheckedArrayList;
 
+import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 import static org.apache.sis.util.collection.Collections.isNullOrEmpty;
 import static org.apache.sis.util.collection.Collections.hashMapCapacity;
 
@@ -373,6 +374,12 @@ public abstract class ModifiableMetadata
         protected void checkWritePermission() throws UnsupportedOperationException {
             ModifiableMetadata.this.checkWritePermission();
         }
+
+        @Override
+        protected void ensureValid(final E element) throws IllegalArgumentException {
+            ensureNonNull("element", element);
+            super.ensureValid(element);
+        }
     }
 
     /**
@@ -399,6 +406,12 @@ public abstract class ModifiableMetadata
         protected void checkWritePermission() throws UnsupportedOperationException {
             ModifiableMetadata.this.checkWritePermission();
         }
+
+        @Override
+        protected void ensureValid(final E element) throws IllegalArgumentException {
+            ensureNonNull("element", element);
+            super.ensureValid(element);
+        }
     }
 
     /**

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=1416113&r1=1416112&r2=1416113&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
Sun Dec  2 07:02:39 2012
@@ -47,9 +47,10 @@ import static org.apache.sis.util.collec
  * two identifiers, this is considered acceptable.</p>
  *
  * {@section Handling of duplicated authorities}
- * The collection shall not contains more than one identifier for the same
- * {@linkplain Identifier#getAuthority() authority}. Nevertheless if such duplication
- * is found, then this map implementation applies the following rules:
+ * The collection shall not contain more than one identifier for the same
+ * {@linkplain Identifier#getAuthority() authority}. However duplications may happen if the
user
+ * has direct access to the list, for example through {@link Citation#getIdentifiers()}.
If such
+ * duplication is found, then this map implementation applies the following rules:
  *
  * <ul>
  *   <li>All getter methods (including the iterators and the values returned by the
{@code put}
@@ -57,16 +58,21 @@ import static org.apache.sis.util.collec
  *       occurrence of each authority. Any subsequent occurrences of the same authorities
are
  *       silently ignored.</li>
  *   <li>All setter methods <em>may</em> affect <em>all</em>
identifiers previously associated to
- *       the given authority, not just the first occurrence. We do that in order to ensure
that
- *       the effect of setter methods are visible to subsequent calls to getter methods.
Whatever
- *       all occurrences or only the first one will be affected is implementation dependent.</li>
+ *       the given authority, not just the first occurrence. The only guarantee is that the
list
+ *       is update in such a way that the effect of setter methods are visible to subsequent
calls
+ *       to getter methods.</li>
  * </ul>
  *
  * {@section Handling of null identifiers}
- * The collection of identifiers shall not contains any null element. However, in order to
- * make the code more robust, any null element are skipped. Note however that it may cause
some
- * inconsistency, for example {@link #isEmpty()} could returns {@code false} while the more
- * accurate {@link #size()} method returns 0.
+ * The collection of identifiers shall not contains any null element. This is normally ensured
by
+ * the {@link org.apache.sis.metadata.ModifiableMetadata} internal collection implementations.
+ * This class performs opportunist null checks as an additional safety. However because we
perform
+ * those checks only in opportunist ways, the following inconsistencies remain:
+ *
+ * <ul>
+ *   <li>{@link #isEmpty()} may return {@code false} when the more accurate {@link
#size()}
+ *       method returns 0.</li>
+ * </ul>
  *
  * {@section Thread safety}
  * This class is thread safe if the underlying identifier collection is thread safe.
@@ -345,7 +351,7 @@ public class IdentifierMapAdapter extend
         }
 
         /**
-         * Same implementation than {@link IdentifierMap#clear()}.
+         * Same implementation than {@link IdentifierMapAdapter#clear()}.
          */
         @Override
         public void clear() throws UnsupportedOperationException {
@@ -353,7 +359,7 @@ public class IdentifierMapAdapter extend
         }
 
         /**
-         * Same implementation than {@link IdentifierMap#isEmpty()}.
+         * Same implementation than {@link IdentifierMapAdapter#isEmpty()}.
          */
         @Override
         public boolean isEmpty() {

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java?rev=1416113&r1=1416112&r2=1416113&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java
Sun Dec  2 07:02:39 2012
@@ -31,7 +31,7 @@ import java.util.Objects;
 /**
  * A map of identifiers which handles some identifiers in a special way.
  * The identifiers for the following authorities are handled in a special way.
- * See usages of {@link #isSpecialCase(Citation)} for spotting the code where
+ * See usages of {@link #specialCase(Object)} for spotting the code where
  * a special handling is applied.
  *
  * <ul>

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java?rev=1416113&r1=1416112&r2=1416113&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java
Sun Dec  2 07:02:39 2012
@@ -109,15 +109,20 @@ public class CheckedArrayList<E> extends
 
     /**
      * Ensures that the given element can be added to this list.
-     * The default implementation ensures that the object is assignable to the type specified
-     * at construction time. Subclasses can override this method if they need to perform
-     * additional checks.
+     * The default implementation ensures that the object is {@code null} or assignable
+     * to the type specified at construction time. Subclasses can override this method
+     * if they need to perform additional checks.
+     *
+     * {@section Synchronization}
+     * This method is invoked <em>before</em> to get the synchronization {@linkplain
#getLock() lock}.
+     * This is different than the {@link #checkWritePermission()} method, which is invoked
inside the
+     * synchronized block.
      *
      * @param  element the object to check, or {@code null}.
      * @throws IllegalArgumentException if the specified element can not be added to this
list.
      */
     protected void ensureValid(final E element) throws IllegalArgumentException {
-        if (element!=null && !type.isInstance(element)) {
+        if (element != null && !type.isInstance(element)) {
             throw new IllegalArgumentException(Errors.format(
                     Errors.Keys.IllegalArgumentClass_3, "element", element.getClass(), type));
         }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java?rev=1416113&r1=1416112&r2=1416113&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java
Sun Dec  2 07:02:39 2012
@@ -108,15 +108,20 @@ public class CheckedHashSet<E> extends L
 
     /**
      * Ensures that the given element can be added to this set.
-     * The default implementation ensures that the object is assignable to the type specified
-     * at construction time. Subclasses can override this method if they need to perform
-     * additional checks.
+     * The default implementation ensures that the object is {@code null} or assignable
+     * to the type specified at construction time. Subclasses can override this method
+     * if they need to perform additional checks.
+     *
+     * {@section Synchronization}
+     * This method is invoked <em>before</em> to get the synchronization {@linkplain
#getLock() lock}.
+     * This is different than the {@link #checkWritePermission()} method, which is invoked
inside the
+     * synchronized block.
      *
      * @param  element the object to check, or {@code null}.
      * @throws IllegalArgumentException if the specified element can not be added to this
set.
      */
     protected void ensureValid(final E element) throws IllegalArgumentException {
-        if (element!=null && !type.isInstance(element)) {
+        if (element != null && !type.isInstance(element)) {
             throw new IllegalArgumentException(Errors.format(
                     Errors.Keys.IllegalArgumentClass_3, "element", element.getClass(), type));
         }



Mime
View raw message