sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1398222 - in /sis/trunk: ./ sis-utility/src/main/java/org/apache/sis/util/ sis-utility/src/main/java/org/apache/sis/util/collection/ sis-utility/src/main/java/org/apache/sis/util/resources/ sis-utility/src/main/java/org/apache/sis/util/typ...
Date Mon, 15 Oct 2012 08:53:39 GMT
Author: desruisseaux
Date: Mon Oct 15 08:53:38 2012
New Revision: 1398222

URL: http://svn.apache.org/viewvc?rev=1398222&view=rev
Log:
Merge from the JDK6 branch.

Added:
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/Decorator.java
      - copied unchanged from r1398219, sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Decorator.java
Removed:
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/SynchronizedIterator.java
Modified:
    sis/trunk/   (props changed)
    sis/trunk/pom.xml
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashMap.java
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/type/Types.java
    sis/trunk/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java
    sis/trunk/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java

Propchange: sis/trunk/
------------------------------------------------------------------------------
  Merged /sis/branches/JDK7:r1397091-1398215
  Merged /sis/branches/JDK6:r1397092-1398219

Modified: sis/trunk/pom.xml
URL: http://svn.apache.org/viewvc/sis/trunk/pom.xml?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/pom.xml (original)
+++ sis/trunk/pom.xml Mon Oct 15 08:53:38 2012
@@ -412,6 +412,11 @@ Apache SIS is a toolkit for describing l
     <pluginManagement>
       <plugins>
         <plugin>
+          <groupId>org.codehaus.mojo</groupId>
+          <artifactId>build-helper-maven-plugin</artifactId>
+          <version>1.7</version>
+        </plugin>
+        <plugin>
           <groupId>org.mortbay.jetty</groupId>
           <artifactId>jetty-maven-plugin</artifactId>
           <version>8.0.0.M2</version>

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java Mon Oct
15 08:53:38 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<V>(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/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java
(original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java
Mon Oct 15 08:53:38 2012
@@ -18,22 +18,24 @@ package org.apache.sis.util.collection;
 
 import java.util.List;
 import java.util.Iterator;
+import java.util.ListIterator;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import net.jcip.annotations.ThreadSafe;
+import org.apache.sis.util.Decorator;
 import org.apache.sis.util.resources.Errors;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
 
 /**
- * A {@linkplain Collections#checkedList(List) checked} and
- * {@linkplain Collections#synchronizedList(List) synchronized} {@link ArrayList}.
+ * A {@linkplain java.util.Collections#checkedList(List) checked} and
+ * {@linkplain java.util.Collections#synchronizedList(List) synchronized} {@link ArrayList}.
  * The type checks are performed at run-time in addition to the compile-time checks.
  *
  * <p>Using this class is similar to wrapping an {@link ArrayList} using the methods
provided
- * in the standard {@link Collections} class, except for the following advantages:</p>
+ * in the standard {@link java.util.Collections} class, except for the following advantages:</p>
  *
  * <ul>
  *   <li>Avoid the two levels of indirection (for type check and synchronization).</li>
@@ -58,8 +60,8 @@ import static org.apache.sis.util.Argume
  * @version 0.3
  * @module
  *
- * @see Collections#checkedList(List)
- * @see Collections#synchronizedList(List)
+ * @see java.util.Collections#checkedList(List)
+ * @see java.util.Collections#synchronizedList(List)
  */
 @ThreadSafe
 public class CheckedArrayList<E> extends ArrayList<E> implements CheckedContainer<E>,
Cloneable {
@@ -157,7 +159,7 @@ public class CheckedArrayList<E> extends
      *
      * {@section Note for subclass implementors}
      * Subclasses that override this method must be careful to update the lock reference
-     * when this list is {@linkplain #clone() cloned}.
+     * (if needed) when this list is {@linkplain #clone() cloned}.
      *
      * @return The synchronization lock.
      */
@@ -166,20 +168,69 @@ public class CheckedArrayList<E> extends
     }
 
     /**
+     * A synchronized iterator with a check for write permission prior element removal.
+     */
+    @ThreadSafe
+    @Decorator(Iterator.class)
+    private class Iter<E,I extends Iterator<E>> implements Iterator<E>
{
+        final I iterator;
+        Iter(final I iterator)                   {this.iterator = iterator;}
+        @Override public final boolean hasNext() {synchronized (getLock()) {return      
           iterator.hasNext();}}
+        @Override public final E       next()    {synchronized (getLock()) {return      
           iterator.next();}}
+        @Override public final void    remove()  {synchronized (getLock()) {checkWritePermission();
iterator.remove();}}
+    }
+
+    /**
+     * A synchronized list iterator with a check for write permission prior element removal.
+     */
+    @Decorator(ListIterator.class)
+    private class ListIter<E> extends Iter<E,ListIterator<E>> implements
ListIterator<E> {
+        ListIter(final ListIterator<E> iterator) {super(iterator);}
+        @Override public int     nextIndex()     {synchronized (getLock()) {return      
           iterator.nextIndex();}}
+        @Override public int     previousIndex() {synchronized (getLock()) {return      
           iterator.previousIndex();}}
+        @Override public boolean hasPrevious()   {synchronized (getLock()) {return      
           iterator.hasPrevious();}}
+        @Override public E       previous()      {synchronized (getLock()) {return      
           iterator.previous();}}
+        @Override public void    set(final E e)  {synchronized (getLock()) {checkWritePermission();
iterator.set(e);}}
+        @Override public void    add(final E e)  {synchronized (getLock()) {checkWritePermission();
iterator.add(e);}}
+    }
+
+    /**
      * Returns an iterator over the elements in this list.
+     * The returned iterator will support {@linkplain Iterator#remove() element removal}
+     * only if the {@link #checkWritePermission()} method does not throw exception.
      */
     @Override
     public Iterator<E> iterator() {
-        final Object lock = getLock();
-        synchronized (lock) {
-            return new SynchronizedIterator<E>(super.iterator(), lock);
+        synchronized (getLock()) {
+            return new Iter<E,Iterator<E>>(super.iterator());
+        }
+    }
+
+    /**
+     * Returns an iterator over the elements in this list.
+     * The returned iterator will support {@linkplain ListIterator#remove() element removal},
+     * {@linkplain ListIterator#add(Object) addition} or {@linkplain ListIterator#set(Object)
+     * modification} only if the {@link #checkWritePermission()} method does not throw exception.
+     */
+    @Override
+    public ListIterator<E> listIterator() {
+        synchronized (getLock()) {
+            return new ListIter<E>(super.listIterator());
         }
     }
 
-    // Note: providing a synchronized iterator is a little bit of paranoia because the ArrayList
-    // implementation inherits the default AbstractList implementation, which delegate its
work
-    // to the public List methods. All the later are already synchronized. We do not override
-    // ListIterator for this reason and because it is less used.
+    /**
+     * Returns an iterator over the elements in this list, starting at the given index.
+     * The returned iterator will support {@linkplain ListIterator#remove() element removal},
+     * {@linkplain ListIterator#add(Object) addition} or {@linkplain ListIterator#set(Object)
+     * modification} only if the {@link #checkWritePermission()} method does not throw exception.
+     */
+    @Override
+    public ListIterator<E> listIterator(final int index) {
+        synchronized (getLock()) {
+            return new ListIter<E>(super.listIterator(index));
+        }
+    }
 
     /**
      * Returns the number of elements in this list.

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashMap.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashMap.java?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashMap.java
(original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashMap.java
Mon Oct 15 08:53:38 2012
@@ -17,21 +17,25 @@
 package org.apache.sis.util.collection;
 
 import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import net.jcip.annotations.ThreadSafe;
+import org.apache.sis.util.Decorator;
 import org.apache.sis.util.resources.Errors;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
 
 /**
- * A {@linkplain Collections#checkedMap(Map) checked} and
- * {@linkplain Collections#synchronizedMap(Map) synchronized} {@link LinkedHashMap}.
+ * A {@linkplain java.util.Collections#checkedMap(Map) checked} and
+ * {@linkplain java.util.Collections#synchronizedMap(Map) synchronized} {@link LinkedHashMap}.
  * The type checks are performed at run-time in addition to the compile-time checks.
  *
  * <p>Using this class is similar to wrapping a {@link LinkedHashMap} using the methods
provided
- * in the standard {@link Collections} class, except for the following advantages:</p>
+ * in the standard {@link java.util.Collections} class, except for the following advantages:</p>
  *
  * <ul>
  *   <li>Avoid the two levels of indirection (for type check and synchronization).</li>
@@ -48,9 +52,6 @@ import static org.apache.sis.util.Argume
  * {@note The above is the reason why the name of this class emphases the <cite>checked</cite>
  * aspect rather than the <cite>synchronized</cite> aspect of the map.}
  *
- * @todo Current implementation do not synchronize the {@linkplain #entrySet entry set},
- *       {@linkplain #keySet key set} and {@linkplain #values values} collection.
- *
  * @param <K> The type of keys in the map.
  * @param <V> The type of values in the map.
  *
@@ -59,8 +60,8 @@ import static org.apache.sis.util.Argume
  * @version 0.3
  * @module
  *
- * @see Collections#checkedMap(Map)
- * @see Collections#synchronizedMap(Map)
+ * @see java.util.Collections#checkedMap(Map)
+ * @see java.util.Collections#synchronizedMap(Map)
  */
 @ThreadSafe
 public class CheckedHashMap<K,V> extends LinkedHashMap<K,V> implements Cloneable
{
@@ -132,7 +133,7 @@ public class CheckedHashMap<K,V> extends
      *
      * {@section Note for subclass implementors}
      * Subclasses that override this method must be careful to update the lock reference
-     * when this map is {@linkplain #clone() cloned}.
+     * (if needed) when this map is {@linkplain #clone() cloned}.
      *
      * @return The synchronization lock.
      */
@@ -257,6 +258,48 @@ public class CheckedHashMap<K,V> extends
     }
 
     /**
+     * Returns a view of the keys in the map.
+     * The returned set will support {@linkplain Set#remove(Object) element removal}
+     * only if the {@link #checkWritePermission()} method does not throw exception.
+     *
+     * @return A synchronized view of the keys in the map.
+     */
+    @Override
+    public Set<K> keySet() {
+        synchronized (getLock()) {
+            return new SyncSet<K>(super.keySet());
+        }
+    }
+
+    /**
+     * Returns a view of the values in the map.
+     * The returned collection will support {@linkplain Collection#remove(Object) element
removal}
+     * only if the {@link #checkWritePermission()} method does not throw exception.
+     *
+     * @return A synchronized view of the values in the map.
+     */
+    @Override
+    public Collection<V> values() {
+        synchronized (getLock()) {
+            return new Sync<V>(super.values());
+        }
+    }
+
+    /**
+     * Returns a view of the entries in the map.
+     * The returned set will support {@linkplain Set#remove(Object) element removal}
+     * only if the {@link #checkWritePermission()} method does not throw exception.
+     *
+     * @return A synchronized view of the keys in the map.
+     */
+    @Override
+    public Set<Map.Entry<K,V>> entrySet() {
+        synchronized (getLock()) {
+            return new SyncSet<Map.Entry<K,V>>(super.entrySet());
+        }
+    }
+
+    /**
      * Returns a string representation of this map.
      */
     @Override
@@ -298,4 +341,69 @@ public class CheckedHashMap<K,V> extends
             return (CheckedHashMap<K,V>) super.clone();
         }
     }
+
+    /**
+     * A synchronized iterator with a check for write permission prior element removal.
+     */
+    @ThreadSafe
+    @Decorator(Iterator.class)
+    private final class Iter<E> implements Iterator<E> {
+        final Iterator<E> iterator;
+        Iter(final Iterator<E> iterator)   {this.iterator = iterator;}
+        @Override public boolean hasNext() {synchronized (getLock()) {return            
     iterator.hasNext();}}
+        @Override public E       next()    {synchronized (getLock()) {return            
     iterator.next();}}
+        @Override public void    remove()  {synchronized (getLock()) {checkWritePermission();
iterator.remove();}}
+    }
+
+    /**
+     * A collection or a set synchronized on the enclosing map {@linkplain #getLock() lock}.
+     * This is used directly for wrapping {@link Map#values()}, or indirectly for wrapping
+     * {@link Map#keySet()} or {@link Map#entrySet()} views.
+     */
+    @ThreadSafe
+    @Decorator(Collection.class)
+    private class Sync<E> implements Collection<E> {
+        /**
+         * The {@link Map#keySet()}, {@link Map#values()} or {@link Map#entrySet()} view.
+         */
+        private final Collection<E> view;
+
+        /**
+         * Create a new synchronized wrapper for the given view.
+         */
+        Sync(final Collection<E> view) {
+            this.view = view;
+        }
+
+        @Override public final void     clear()                           {synchronized (getLock())
{                               view.clear      ( );}}
+        @Override public final int      size()                            {synchronized (getLock())
{                        return view.size       ( );}}
+        @Override public final boolean  isEmpty()                         {synchronized (getLock())
{                        return view.isEmpty    ( );}}
+        @Override public final boolean  contains(Object o)                {synchronized (getLock())
{                        return view.contains   (o);}}
+        @Override public final boolean  containsAll(Collection<?> c)      {synchronized
(getLock()) {                        return view.containsAll(c);}}
+        @Override public final boolean  add(E e)                          {synchronized (getLock())
{checkWritePermission(); return view.add        (e);}}
+        @Override public final boolean  addAll(Collection<? extends E> c) {synchronized
(getLock()) {checkWritePermission(); return view.addAll     (c);}}
+        @Override public final boolean  remove(Object o)                  {synchronized (getLock())
{checkWritePermission(); return view.remove     (o);}}
+        @Override public final boolean  removeAll(Collection<?> c)        {synchronized
(getLock()) {checkWritePermission(); return view.removeAll  (c);}}
+        @Override public final boolean  retainAll(Collection<?> c)        {synchronized
(getLock()) {checkWritePermission(); return view.retainAll  (c);}}
+        @Override public final Object[] toArray()                         {synchronized (getLock())
{                        return view.toArray    ( );}}
+        @Override public final <T> T[]  toArray(T[] a)                    {synchronized
(getLock()) {                        return view.toArray    (a);}}
+        @Override public final String   toString()                        {synchronized (getLock())
{                        return view.toString   ( );}}
+        @Override public final boolean  equals(Object o)                  {synchronized (getLock())
{                        return view.equals     (o);}}
+        @Override public final int      hashCode()                        {synchronized (getLock())
{                        return view.hashCode   ( );}}
+        @Override public final Iterator<E> iterator()                     {synchronized
(getLock()) {return new Iter<E>(view.iterator());}}
+    }
+
+    /**
+     * A set synchronized on the enclosing map {@linkplain #getLock() lock}.
+     * This is used for wrapping {@link Map#keySet()} or {@link Map#entrySet()} views.
+     */
+    @Decorator(Set.class)
+    private final class SyncSet<E> extends Sync<E> implements Set<E> {
+        /**
+         * Create a new synchronized wrapper for the given view.
+         */
+        SyncSet(final Set<E> set) {
+            super(set);
+        }
+    }
 }

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java
(original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java
Mon Oct 15 08:53:38 2012
@@ -22,18 +22,19 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashSet;
 import net.jcip.annotations.ThreadSafe;
+import org.apache.sis.util.Decorator;
 import org.apache.sis.util.resources.Errors;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
 
 /**
- * A {@linkplain Collections#checkedSet(Set) checked} and
- * {@linkplain Collections#synchronizedSet(Set) synchronized} {@link LinkedHashSet}.
+ * A {@linkplain java.util.Collections#checkedSet(Set) checked} and
+ * {@linkplain java.util.Collections#synchronizedSet(Set) synchronized} {@link LinkedHashSet}.
  * The type checks are performed at run-time in addition to the compile-time checks.
  *
  * <p>Using this class is similar to wrapping a {@link LinkedHashSet} using the methods
provided
- * in the standard {@link Collections} class, except for the following advantages:</p>
+ * in the standard {@link java.util.Collections} class, except for the following advantages:</p>
  *
  * <ul>
  *   <li>Avoid the two levels of indirection (for type check and synchronization).</li>
@@ -43,7 +44,7 @@ import static org.apache.sis.util.Argume
  * </ul>
  *
  * <p>The synchronization is provided mostly in order to prevent damages
- * to the set in case of concurrent accesses. It does <strong>not</strong> prevent
+ * to the set in case of concurrent access. It does <strong>not</strong> prevent
  * {@link java.util.ConcurrentModificationException} to be thrown during iterations,
  * unless the whole iteration is synchronized on this set {@linkplain #getLock() lock}.
  * For real concurrency, see the {@link java.util.concurrent} package instead.</p>
@@ -58,8 +59,8 @@ import static org.apache.sis.util.Argume
  * @version 0.3
  * @module
  *
- * @see Collections#checkedSet(Set)
- * @see Collections#synchronizedSet(Set)
+ * @see java.util.Collections#checkedSet(Set)
+ * @see java.util.Collections#synchronizedSet(Set)
  */
 @ThreadSafe
 public class CheckedHashSet<E> extends LinkedHashSet<E> implements CheckedContainer<E>,
Cloneable {
@@ -157,7 +158,7 @@ public class CheckedHashSet<E> extends L
      *
      * {@section Note for subclass implementors}
      * Subclasses that override this method must be careful to update the lock reference
-     * when this set is {@linkplain #clone() cloned}.
+     * (if needed) when this set is {@linkplain #clone() cloned}.
      *
      * @return The synchronization lock.
      */
@@ -166,13 +167,27 @@ public class CheckedHashSet<E> extends L
     }
 
     /**
+     * A synchronized iterator with a check for write permission prior element removal.
+     */
+    @ThreadSafe
+    @Decorator(Iterator.class)
+    private final class Iter<E> implements Iterator<E> {
+        final Iterator<E> iterator;
+        Iter(final Iterator<E> iterator)   {this.iterator = iterator;}
+        @Override public boolean hasNext() {synchronized (getLock()) {return            
     iterator.hasNext();}}
+        @Override public E       next()    {synchronized (getLock()) {return            
     iterator.next();}}
+        @Override public void    remove()  {synchronized (getLock()) {checkWritePermission();
iterator.remove();}}
+    }
+
+    /**
      * Returns an iterator over the elements in this set.
+     * The returned iterator will support {@linkplain Iterator#remove() element removal}
+     * only if the {@link #checkWritePermission()} method does not throw exception.
      */
     @Override
     public Iterator<E> iterator() {
-        final Object lock = getLock();
-        synchronized (lock) {
-            return new SynchronizedIterator<E>(super.iterator(), lock);
+        synchronized (getLock()) {
+            return new Iter<E>(super.iterator());
         }
     }
 

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java Mon
Oct 15 08:53:38 2012
@@ -33,7 +33,7 @@
  *     and supports concurrency, while the other implementations are more lightweight, sometime
  *     thread-safe but without concurrency support.
  *   </p></li><li><p>
- *     {@link org.apache.sis.util.collection.CheckedCollection},
+ *     {@link org.apache.sis.util.collection.CheckedContainer},
  *     {@link org.apache.sis.util.collection.CheckedArrayList},
  *     {@link org.apache.sis.util.collection.CheckedHashSet} and
  *     {@link org.apache.sis.util.collection.CheckedHashMap} can be used for combining <em>runtime</em>

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java Mon Oct
15 08:53:38 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/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties Mon
Oct 15 08:53:38 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/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
(original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
Mon Oct 15 08:53:38 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.

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/type/Types.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/type/Types.java?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/type/Types.java (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/type/Types.java Mon Oct 15 08:53:38
2012
@@ -152,7 +152,7 @@ public final class Types extends Static 
      * If the given array is null or an instance of {@code InternationalString[]}, then this
method
      * returns it unchanged. Otherwise a new array of type {@code InternationalString[]}
is created
      * and every elements from the given array is copied or
-     * {@linkplain #InternationalString(CharSequence) converted} in the new array.
+     * {@linkplain #toInternationalString(CharSequence) converted} in the new array.
      * <p>
      * If a defensive copy of the {@code strings} array is wanted, then the caller needs
to check
      * if the returned array is the same instance than the one given in argument to this
method.

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java Mon Oct 15 08:53:38
2012
@@ -120,8 +120,8 @@ public final class TestRunner extends Bl
 
     /**
      * Validates all tests methods in the test class. This method first performs the default
-     * verification documented in {@link BlockJUnit4ClassRunner#validateTestMethods()}, then
-     * ensures that all {@link DependsOnMethod} annotations refer to an existing method.
+     * verification documented in {@link BlockJUnit4ClassRunner#validateTestMethods(List)},
+     * then ensures that all {@link DependsOnMethod} annotations refer to an existing method.
      *
      * @param errors The list where to report any problem found.
      */

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java?rev=1398222&r1=1398221&r2=1398222&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java
(original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java
Mon Oct 15 08:53:38 2012
@@ -39,7 +39,7 @@ import static org.junit.Assert.*;
  */
 public final strictfp class IndexedResourceBundleTest extends TestCase {
     /**
-     * Tests the {@link Errors#getResources()} method on different locales.
+     * Tests the {@link Errors#getResources(Locale)} method on different locales.
      */
     @Test
     public void testGetResources() {



Mime
View raw message