sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1405052 - in /sis/branches/JDK6: ./ sis-utility/src/main/java/org/apache/sis/internal/jaxb/ sis-utility/src/main/java/org/apache/sis/internal/simple/ sis-utility/src/main/java/org/apache/sis/internal/util/ sis-utility/src/main/java/org/apa...
Date Fri, 02 Nov 2012 17:04:20 GMT
Author: desruisseaux
Date: Fri Nov  2 17:04:19 2012
New Revision: 1405052

URL: http://svn.apache.org/viewvc?rev=1405052&view=rev
Log:
Merge from the JDK7 branch (derived collections work).

Added:
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/math/FunctionProperty.java
      - copied unchanged from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/FunctionProperty.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/IdentityConverter.java
      - copied, changed from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/IdentityConverter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/ObjectConverter.java
      - copied unchanged from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/ObjectConverter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/ObjectConverters.java
      - copied unchanged from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/ObjectConverters.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/UnconvertibleObjectException.java
      - copied unchanged from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/UnconvertibleObjectException.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedIterator.java
      - copied unchanged from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedIterator.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedMap.java
      - copied, changed from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedMap.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedSet.java
      - copied, changed from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedSet.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedMapTest.java
      - copied, changed from r1405048, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedMapTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedSetTest.java
      - copied, changed from r1405048, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedSetTest.java
Modified:
    sis/branches/JDK6/   (props changed)
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/util/X364.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/AppendableWriter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Arrays.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Static.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/Collections.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Propchange: sis/branches/JDK6/
------------------------------------------------------------------------------
  Merged /sis/branches/JDK7:r1403768-1405048

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
Fri Nov  2 17:04:19 2012
@@ -27,8 +27,6 @@ import org.apache.sis.internal.simple.Si
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.xml.IdentifierSpace;
 
-import static org.apache.sis.util.collection.Collections.addIfNonNull;
-
 
 /**
  * The {@linkplain Identifier#getAuthority() authority of identifiers} that are not expected
to be
@@ -160,7 +158,9 @@ public final class NonMarshalledAuthorit
             }
             it.remove();
         }
-        addIfNonNull(identifiers, id);
+        if (id != null) {
+            identifiers.add(id);
+        }
     }
 
     /**

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
Fri Nov  2 17:04:19 2012
@@ -18,6 +18,7 @@ package org.apache.sis.internal.simple;
 
 import java.io.Serializable;
 import java.text.CharacterIterator;
+import org.apache.sis.util.Decorator;
 import org.apache.sis.util.ArgumentChecks;
 
 
@@ -30,6 +31,7 @@ import org.apache.sis.util.ArgumentCheck
  * @version 0.3
  * @module
  */
+@Decorator(CharSequence.class)
 public class SimpleCharacterIterator implements CharacterIterator, CharSequence, Serializable
{
     /**
      * For cross-version compatibility.

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/util/X364.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/util/X364.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/util/X364.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/util/X364.java Fri
Nov  2 17:04:19 2012
@@ -83,7 +83,7 @@ public enum X364 {
     /**
      * The X3.64 escape sequence, built when first needed.
      */
-    private transient volatile String sequence;
+    private transient String sequence;
 
     /**
      * Foreground or background flavors of this enum.
@@ -136,11 +136,14 @@ public enum X364 {
      * @return The X3.64 escape sequence.
      */
     public String sequence() {
-        String s = sequence;
-        if (s == null) {
-            sequence = s = START + code + END;
+        if (sequence == null) {
+            sequence = (START + code + END).intern();
+            // We used the string.intern() method in order to avoid worrying about memory
barrier
+            // (synchronization or volatile variable) since intern() does its own synchronization.
+            // The String will live for the whole library lifetime anyway, and if there is
other
+            // X3.64 libraries on the JVM we may share the strings with them as a side effect.
         }
-        return s;
+        return sequence;
     }
 
     /**

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/AppendableWriter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/AppendableWriter.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/AppendableWriter.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/AppendableWriter.java Fri
Nov  2 17:04:19 2012
@@ -139,7 +139,7 @@ final class AppendableWriter extends Wri
     }
 
     /**
-     * IF {@link #out} implements {@link Flushable}, or is a {@link FilteredAppendable}
wrapper
+     * If {@link #out} implements {@link Flushable}, or is a {@link FilteredAppendable}
wrapper
      * around a flushable object, delegates to that object. Otherwise do nothing.
      */
     @Override
@@ -150,7 +150,7 @@ final class AppendableWriter extends Wri
     }
 
     /**
-     * IF {@link #out} implements {@link Closeable}, or is a {@link FilteredAppendable}
wrapper
+     * If {@link #out} implements {@link Closeable}, or is a {@link FilteredAppendable}
wrapper
      * around a closeable object, delegates to that object. Otherwise just flush (if possible).
      */
     @Override

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java Fri Nov
 2 17:04:19 2012
@@ -28,7 +28,7 @@
  * Some formatters in this package make extensive use of Unicode characters. This may produce
  * unexpected results in a Windows console, unless the underlying output stream uses the
correct
  * encoding (e.g. {@code new OutputStreamWriter(System.out, "Cp437")}). To display the appropriate
- * code page for a Windows console, type <code>chcp</code> on the command line.
+ * code page for a Windows console, type {@code chcp} on the command line.
  *
  * {@section Supplementary Unicode characters}
  * This package can handle the {@linkplain java.lang.Character#isSupplementaryCodePoint(int)

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Arrays.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Arrays.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Arrays.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Arrays.java Fri Nov  2
17:04:19 2012
@@ -1433,7 +1433,7 @@ public final class Arrays extends Static
      *                    elements are not allowed), or {@code false} otherwise.
      * @return {@code true} if all elements in the given array are sorted in increasing order.
      */
-    public static <E> boolean isSorted(final E[] array, final Comparator<E> comparator,
final boolean strict) {
+    public static <E> boolean isSorted(final E[] array, final Comparator<? super
E> comparator, final boolean strict) {
         for (int i=1; i<array.length; i++) {
             final int c = comparator.compare(array[i], array[i-1]);
             if (strict ? c <= 0 : c < 0) {

Copied: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/IdentityConverter.java
(from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/IdentityConverter.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/IdentityConverter.java?p2=sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/IdentityConverter.java&p1=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/IdentityConverter.java&r1=1405048&r2=1405052&rev=1405052&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/IdentityConverter.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/IdentityConverter.java
Fri Nov  2 17:04:19 2012
@@ -47,7 +47,7 @@ final class IdentityConverter<T> impleme
      * Identity converters created in the JVM, for sharing unique instances.
      * Use weak keys in order to allow class unloading.
      */
-    private static final Map<Class<?>, IdentityConverter<?>> CACHE = new
WeakHashMap<>();
+    private static final Map<Class<?>, IdentityConverter<?>> CACHE = new
WeakHashMap<Class<?>, IdentityConverter<?>>();
 
     /**
      * Returns an identity converter for the given type.
@@ -56,7 +56,7 @@ final class IdentityConverter<T> impleme
         @SuppressWarnings("unchecked")
         IdentityConverter<T> converter = (IdentityConverter<T>) CACHE.get(type);
         if (converter == null) {
-            converter = new IdentityConverter<>(type);
+            converter = new IdentityConverter<T>(type);
             CACHE.put(type, converter);
         }
         return converter;

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Static.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Static.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Static.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Static.java Fri Nov  2
17:04:19 2012
@@ -40,6 +40,10 @@ package org.apache.sis.util;
  * <tr><td>{@link Arrays}</td>
  *     <td>Insert or remove elements in the middle of arrays.</td></tr>
  *
+ * <tr><th colspan="2" class="hsep">Input / Output (including CRS, XML, images)</th></tr>
+ * <tr><td>{@link org.apache.sis.io.IO}</td>
+ *     <td>Methods working on {@link Appendable} instances.</td></tr>
+ *
  * <tr><th colspan="2" class="hsep">Loggings and exceptions</th></tr>
  * <tr><td>{@link ArgumentChecks}</td>
  *     <td>Perform argument checks and throw {@link IllegalArgumentException} if needed.</td></tr>
@@ -48,6 +52,10 @@ package org.apache.sis.util;
  * <tr><td>{@link org.apache.sis.util.logging.Logging}</td>
  *     <td>Get a JDK {@linkplain java.util.logging.Logger logger}, which may be a wrapper
around
  *         the <cite>Apache Commons Logging</cite> or <cite>Log4J</cite>
framework.</td></tr>
+ *
+ * <tr><th colspan="2" class="hsep">Factories</th></tr>
+ * <tr><td>{@link ObjectConverters}</td>
+ *     <td>Creates {@link ObjectConverter} instances, or collection views using object
converters.</td></tr>
  * </table>
  *
  * @author Martin Desruisseaux (Geomatys)

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/Collections.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/Collections.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/Collections.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/Collections.java
Fri Nov  2 17:04:19 2012
@@ -18,9 +18,9 @@ package org.apache.sis.util.collection;
 
 import java.util.*;
 import java.io.Serializable;
-import java.util.logging.Logger;
 import org.apache.sis.util.Static;
-import org.apache.sis.util.logging.Logging;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.ObjectConverter;
 
 import static java.util.Collections.list;
 import static java.util.Collections.emptySet;
@@ -38,9 +38,8 @@ import static java.util.Collections.unmo
  * This is an extension to the Java {@link java.util.Collections} utility class providing:
  *
  * <ul>
- *   <li>Null-safe {@link #clear(Collection) clear}, {@link #isNullOrEmpty(Collection)
isNullOrEmpty}
- *       and {@link #addIfNonNull(Collection, Object) addIfNonNull} methods, for the convenience
of
- *       classes using the <cite>lazy instantiation</cite> pattern.</li>
+ *   <li>Null-safe {@link #isNullOrEmpty(Collection) isNullOrEmpty} method,
+ *       for the convenience of classes using the <cite>lazy instantiation</cite>
pattern.</li>
  *   <li>{@link #asCollection(Object) asCollection} for wrapping arbitrary objects
to list or collection.</li>
  *   <li>List and collection {@linkplain #listComparator() comparators}.</li>
  *   <li>{@link #modifiableCopy(Collection) modifiableCopy} method for taking a snapshot
of an arbitrary
@@ -57,54 +56,21 @@ import static java.util.Collections.unmo
  */
 public final class Collections extends Static {
     /**
-     * The logger where to logs collection events, if logging at the finest level is enabled.
-     */
-    static final Logger LOGGER = Logging.getLogger(Collections.class);
-
-    /**
      * Do not allow instantiation of this class.
      */
     private Collections() {
     }
 
     /**
-     * Clears the given collection, if non-null.
-     * If the given collection is null, then this method does nothing.
-     *
-     * <p>This is a convenience method for classes implementing the <cite>lazy
instantiation</cite>
-     * pattern. In such cases, null collections (i.e. collections not yet instantiated) are
typically
-     * considered as {@linkplain Collection#isEmpty() empty}.</p>
-     *
-     * @param collection The collection to clear, or {@code null}.
-     */
-    public static void clear(final Collection<?> collection) {
-        if (collection != null) {
-            collection.clear();
-        }
-    }
-
-    /**
-     * Clears the given map, if non-null.
-     * If the given map is null, then this method does nothing.
-     *
-     * <p>This is a convenience method for classes implementing the <cite>lazy
instantiation</cite>
-     * pattern. In such cases, null maps (i.e. maps not yet instantiated) are typically considered
-     * as {@linkplain Map#isEmpty() empty}.</p>
-     *
-     * @param map The map to clear, or {@code null}.
-     */
-    public static void clear(final Map<?,?> map) {
-        if (map != null) {
-            map.clear();
-        }
-    }
-
-    /**
      * Returns {@code true} if the given collection is either null or
      * {@linkplain Collection#isEmpty() empty}. If this method returns {@code false},
      * then the given collection is guaranteed to be non-null and to contain at least
      * one element.
      *
+     * <p>This is a convenience method for classes implementing the <cite>lazy
instantiation</cite>
+     * pattern. In such cases, null collections (i.e. collections not yet instantiated) are
typically
+     * considered as {@linkplain Collection#isEmpty() empty}.</p>
+     *
      * @param collection The collection to test, or {@code null}.
      * @return {@code true} if the given collection is null or empty, or {@code false} otherwise.
      */
@@ -117,6 +83,10 @@ public final class Collections extends S
      * If this method returns {@code false}, then the given map is guaranteed to be non-null
and
      * to contain at least one element.
      *
+     * <p>This is a convenience method for classes implementing the <cite>lazy
instantiation</cite>
+     * pattern. In such cases, null maps (i.e. maps not yet instantiated) are typically considered
+     * as {@linkplain Map#isEmpty() empty}.</p>
+     *
      * @param map The map to test, or {@code null}.
      * @return {@code true} if the given map is null or empty, or {@code false} otherwise.
      */
@@ -125,19 +95,6 @@ public final class Collections extends S
     }
 
     /**
-     * Adds the given element to the given collection only if the element is non-null.
-     * If any of the given argument is null, then this method does nothing.
-     *
-     * @param  <E>        The type of elements in the collection.
-     * @param  collection The collection in which to add elements, or {@code null}.
-     * @param  element    The element to add in the collection, or {@code null}.
-     * @return {@code true} if the given element has been added, or {@code false} otherwise.
-     */
-    public static <E> boolean addIfNonNull(final Collection<E> collection, final
E element) {
-        return (collection != null && element != null) && collection.add(element);
-    }
-
-    /**
      * Returns a {@linkplain Queue queue} which is always empty and accepts no element.
      *
      * @param <E> The type of elements in the empty collection.
@@ -169,6 +126,95 @@ public final class Collections extends S
     }
 
     /**
+     * Returns a set whose elements are derived <cite>on-the-fly</cite> from
the given set.
+     * Conversions from the original elements to the derived elements are performed when
needed
+     * by invoking the {@link ObjectConverter#convert(Object)} method on the given converter.
+     * Those conversions are repeated every time a {@code Set} method is invoked; there is
no cache.
+     * Consequently, any change in the original set is immediately visible in the derived
set,
+     * and conversely.
+     *
+     * <p>The {@link Set#add(Object) Set.add(E)} method is supported only if the given
converter
+     * is {@linkplain org.apache.sis.math.FunctionProperty#INVERTIBLE invertible}.
+     * An invertible converter is not mandatory for other {@code Set} operations.
+     * However {@link Set#contains(Object) contains} and {@link #remove(Object) remove}
+     * operations are likely to be faster if the inverse converter is available.</p>
+     *
+     * <p>The derived set may contain fewer elements than the original set if some
elements
+     * are not convertible. Non-convertible elements are <var>S</var> values
for which
+     * {@code converter.convert(S)} returns {@code null}. As a consequence of this sentinel
+     * value usage, the derived set can not contain {@code null} elements.</p>
+     *
+     * <p>The returned set can be serialized if the given set and converter are serializable.
+     * The returned set is not synchronized by itself, but is nevertheless thread-safe if
the
+     * given set (including its iterator) and converter are thread-safe.</p>
+     *
+     * @param  <S>       The type of elements in the storage (original) set.
+     * @param  <E>       The type of elements in the derived set.
+     * @param  storage   The storage set containing the original elements, or {@code null}.
+     * @param  converter The converter from the elements in the storage set to the elements
+     *                   in the derived set.
+     * @return A view over the {@code storage} set containing all elements converted by the
given
+     *         converter, or {@code null} if {@code storage} was null.
+     *
+     * @see org.apache.sis.util.ObjectConverters#derivedSet(Set, ObjectConverter)
+     */
+    public static <S,E> Set<E> derivedSet(final Set<S> storage, final ObjectConverter<S,E>
converter) {
+        ArgumentChecks.ensureNonNull("converter", converter);
+        if (storage == null) {
+            return null;
+        }
+        return DerivedSet.create(storage, converter);
+    }
+
+    /**
+     * Returns a map whose whose keys and values are derived <cite>on-the-fly</cite>
from the given map.
+     * Conversions from the original entries to the derived entries are performed when needed
+     * by invoking the {@link ObjectConverter#convert(Object)} method on the given converters.
+     * Those conversions are repeated every time a {@code Map} method is invoked; there is
no cache.
+     * Consequently, any change in the original map is immediately visible in the derived
map,
+     * and conversely.
+     *
+     * <p>The {@link Map#put(Object,Object) Map.put(K,V)} method is supported only
if the given
+     * converters are {@linkplain org.apache.sis.math.FunctionProperty#INVERTIBLE invertible}.
+     * An invertible converter is not mandatory for other {@code Map} operations.
+     * However some of them are likely to be faster if the inverse converters are available.</p>
+     *
+     * <p>The derived map may contain fewer entries than the original map if some keys
+     * are not convertible. Non-convertible keys are <var>K</var> values for
which
+     * {@code keyConverter.convert(K)} returns {@code null}. As a consequence of this sentinel
+     * value usage, the derived map can not contain {@code null} keys.
+     * It may contain {@code null} values however.</p>
+     *
+     * <p>The returned map can be serialized if the given map and converters are serializable.
+     * The returned map is <strong>not</strong> thread-safe.</p>
+     *
+     * @param <SK>         The type of keys   in the storage map.
+     * @param <SV>         The type of values in the storage map.
+     * @param <K>          The type of keys   in the derived map.
+     * @param <V>          The type of values in the derived map.
+     * @param storage      The storage map containing the original entries, or {@code null}.
+     * @param keyConverter The converter from the keys in the storage map to the keys in
the derived map.
+     * @param valueConverter The converter from the values in the storage map to the values
in the derived map.
+     * @return A view over the {@code storage} map containing all entries converted by the
given
+     *         converters, or {@code null} if {@code storage} was null.
+     *
+     * @see org.apache.sis.util.ObjectConverters#derivedMap(Map, ObjectConverter, ObjectConverter)
+     * @see org.apache.sis.util.ObjectConverters#derivedKeys(Map, ObjectConverter, Class)
+     * @see org.apache.sis.util.ObjectConverters#derivedValues(Map, Class, ObjectConverter)
+     */
+    public static <SK,SV,K,V> Map<K,V> derivedMap(final Map<SK,SV> storage,
+                                                  final ObjectConverter<SK,K> keyConverter,
+                                                  final ObjectConverter<SV,V> valueConverter)
+    {
+        ArgumentChecks.ensureNonNull("keyConverter",   keyConverter);
+        ArgumentChecks.ensureNonNull("valueConverter", valueConverter);
+        if (storage == null) {
+            return null;
+        }
+        return DerivedMap.create(storage, keyConverter, valueConverter);
+    }
+
+    /**
      * Returns the specified array as an immutable set, or {@code null} if the array is null.
      * If the given array contains duplicated elements, i.e. elements that are equal in the
      * sense of {@link Object#equals(Object)}, then only the last instance of the duplicated
@@ -532,14 +578,14 @@ public final class Collections extends S
      * <p>The same calculation can be used for {@link java.util.LinkedHashMap} and
      * {@link java.util.HashSet} as well, which are built on top of {@code HashMap}.</p>
      *
-     * @param elements The number of elements to be put into the hash map or hash set.
-     * @return The optimal initial capacity to be given to the hash map constructor.
+     * @param count The number of elements to be put into the hash map or hash set.
+     * @return The minimal initial capacity to be given to the hash map constructor.
      */
-    public static int hashMapCapacity(int elements) {
-        final int r = elements >>> 2;
-        if (elements != (r << 2)) {
-            elements++;
+    public static int hashMapCapacity(final int count) {
+        int r = count >>> 2;
+        if ((count & 0x3) != 0) {
+            r++;
         }
-        return elements + r;
+        return count + r;
     }
 }

Copied: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedMap.java
(from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedMap.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedMap.java?p2=sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedMap.java&p1=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedMap.java&r1=1405048&r2=1405052&rev=1405052&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedMap.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedMap.java
Fri Nov  2 17:04:19 2012
@@ -119,14 +119,14 @@ class DerivedMap<SK,SV,K,V> extends Abst
         final Set<FunctionProperty> vp = valueConverter.properties();
         if (kp.contains(FunctionProperty.INVERTIBLE)) {
             if (vp.contains(FunctionProperty.INVERTIBLE)) {
-                return new Invertible<>(storage, keyConverter, valueConverter);
+                return new Invertible<SK,SV,K,V>(storage, keyConverter, valueConverter);
             }
-            return new InvertibleKey<>(storage, keyConverter, valueConverter);
+            return new InvertibleKey<SK,SV,K,V>(storage, keyConverter, valueConverter);
         }
         if (vp.contains(FunctionProperty.INVERTIBLE)) {
-            return new InvertibleValue<>(storage, keyConverter, valueConverter);
+            return new InvertibleValue<SK,SV,K,V>(storage, keyConverter, valueConverter);
         }
-        return new DerivedMap<>(storage, keyConverter, valueConverter);
+        return new DerivedMap<SK,SV,K,V>(storage, keyConverter, valueConverter);
     }
 
     /**
@@ -295,7 +295,7 @@ class DerivedMap<SK,SV,K,V> extends Abst
         @Override
         public ObjectConverter<Entry<K,V>, Entry<SK,SV>> inverse() {
             if (inverse == null) {
-                inverse = new DerivedMap<>(null, keyInverse, valueInverse);
+                inverse = new DerivedMap<K,V,SK,SV>(null, keyInverse, valueInverse);
             }
             return inverse;
         }
@@ -365,7 +365,7 @@ class DerivedMap<SK,SV,K,V> extends Abst
     public final Entry<K,V> convert(final Entry<SK,SV> entry) {
         final K key   =   keyConverter.convert(entry.getKey());
         final V value = valueConverter.convert(entry.getValue());
-        return (key != null) ? new SimpleEntry<>(key, value) : null;
+        return (key != null) ? new SimpleEntry<K,V>(key, value) : null;
     }
 
     /**

Copied: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedSet.java
(from r1405048, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedSet.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedSet.java?p2=sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedSet.java&p1=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedSet.java&r1=1405048&r2=1405052&rev=1405052&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedSet.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedSet.java
Fri Nov  2 17:04:19 2012
@@ -89,11 +89,11 @@ class DerivedSet<S,E> extends AbstractSe
         final Set<FunctionProperty> properties = converter.properties();
         if (properties.contains(FunctionProperty.INVERTIBLE)) {
             if (FunctionProperty.isBijective(properties)) {
-                return new Bijective<>(storage, converter);
+                return new Bijective<S,E>(storage, converter);
             }
-            return new Invertible<>(storage, converter);
+            return new Invertible<S,E>(storage, converter);
         }
-        return new DerivedSet<>(storage, converter);
+        return new DerivedSet<S,E>(storage, converter);
     }
 
     /**
@@ -123,7 +123,7 @@ class DerivedSet<S,E> extends AbstractSe
      */
     @Override
     public final Iterator<E> iterator() {
-        return new DerivedIterator<>(storage.iterator(), converter);
+        return new DerivedIterator<S,E>(storage.iterator(), converter);
     }
 
     /**

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
Fri Nov  2 17:04:19 2012
@@ -23,6 +23,7 @@ import java.lang.ref.WeakReference;
 import java.lang.reflect.Array;
 
 import org.apache.sis.util.Disposable;
+import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.internal.util.ReferenceQueueConsumer;
 import org.apache.sis.math.MathFunctions;
@@ -61,6 +62,11 @@ abstract class WeakEntry<E> extends Weak
     static final long REHASH_DELAY = 4000000000L;
 
     /**
+     * The logger where to logs collection events, if logging at the finest level is enabled.
+     */
+    private static final Logger LOGGER = Logging.getLogger(WeakEntry.class);
+
+    /**
      * The next entry, or {@code null} if there is none.
      */
     WeakEntry<E> next;
@@ -166,14 +172,13 @@ abstract class WeakEntry<E> extends Weak
         /*
          * We are done. Log the operation if logging is enabled at that level.
          */
-        final Logger logger = Collections.LOGGER;
-        if (logger.isLoggable(Level.FINEST)) {
+        if (LOGGER.isLoggable(Level.FINEST)) {
             final LogRecord record = Messages.getResources(null).getLogRecord(Level.FINEST,
                     Messages.Keys.ChangedContainerCapacity_2, oldTable.length, table.length);
             record.setSourceMethodName(callerMethod);
             record.setSourceClassName(entryType.getEnclosingClass().getName());
-            record.setLoggerName(logger.getName());
-            logger.log(record);
+            record.setLoggerName(LOGGER.getName());
+            LOGGER.log(record);
         }
         return table;
     }

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
Fri Nov  2 17:04:19 2012
@@ -44,9 +44,10 @@
  *     a hook for making the collections read-only and allow the caller to specify the synchronization
  *     lock of his choice.
  *   </li><li>
- *     {@link org.apache.sis.util.collection.DerivedMap} and
- *     {@link org.apache.sis.util.collection.DerivedSet} are wrapper collections in which
the
- *     keys or the values are derived on-the-fly from the content of an other collection.
+ *     {@linkplain org.apache.sis.util.collection.Collections#derivedMap Derived Map} and
+ *     {@linkplain org.apache.sis.util.collection.Collections#derivedSet derived Set} are
wrapper collections
+ *     in which the keys or the values are derived on-the-fly from the content of an other
collection.
+ *     The can also be used for creating filtered views.
  *   </li><li>
  *     {@link org.apache.sis.util.collection.IntegerList} and
  *     {@link org.apache.sis.util.collection.RangeSet} are collections specialized for a
particular kind

Modified: sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1405052&r1=1405051&r2=1405052&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
(original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
Fri Nov  2 17:04:19 2012
@@ -49,6 +49,8 @@ import org.junit.runners.Suite;
   org.apache.sis.util.collection.WeakHashSetTest.class,
   org.apache.sis.util.collection.WeakValueHashMapTest.class,
   org.apache.sis.util.collection.CacheTest.class,
+  org.apache.sis.util.collection.DerivedSetTest.class,
+  org.apache.sis.util.collection.DerivedMapTest.class,
 
   // GeoAPI most basic types.
   org.apache.sis.util.type.TypesTest.class,

Copied: sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedMapTest.java
(from r1405048, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedMapTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedMapTest.java?p2=sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedMapTest.java&p1=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedMapTest.java&r1=1405048&r2=1405052&rev=1405052&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedMapTest.java
(original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedMapTest.java
Fri Nov  2 17:04:19 2012
@@ -68,8 +68,8 @@ public final strictfp class DerivedMapTe
      */
     @Test
     public void testNoExclusion() {
-        final Map<Integer,Integer> source = new HashMap<>();
-        final Map<Integer,Integer> target = new HashMap<>();
+        final Map<Integer,Integer> source = new HashMap<Integer,Integer>();
+        final Map<Integer,Integer> target = new HashMap<Integer,Integer>();
         final Map<Integer,Integer> tested = DerivedMap.create(source, this, new DerivedSetTest());
         fill(source, target);
         assertEquals(target.size(),     tested.size());
@@ -95,8 +95,8 @@ public final strictfp class DerivedMapTe
      */
     @Test
     public void testWithExclusion() {
-        final Map<Integer,Integer> source = new HashMap<>();
-        final Map<Integer,Integer> target = new HashMap<>();
+        final Map<Integer,Integer> source = new HashMap<Integer,Integer>();
+        final Map<Integer,Integer> target = new HashMap<Integer,Integer>();
         final Map<Integer,Integer> tested = DerivedMap.create(source, this, new DerivedSetTest());
         fill(source, target);
         assertNull(source.put(EXCLUDED, 4));

Copied: sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedSetTest.java
(from r1405048, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedSetTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedSetTest.java?p2=sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedSetTest.java&p1=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedSetTest.java&r1=1405048&r2=1405052&rev=1405052&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedSetTest.java
(original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/collection/DerivedSetTest.java
Fri Nov  2 17:04:19 2012
@@ -50,8 +50,8 @@ public final strictfp class DerivedSetTe
      */
     @Test
     public void testNoExclusion() {
-        final Set<Integer> source = new HashSet<>(Arrays.asList(2,  7,  12, 
17,  20 ));
-        final Set<Integer> target = new HashSet<>(Arrays.asList(20, 70, 120,
170, 200));
+        final Set<Integer> source = new HashSet<Integer>(Arrays.asList(2,  7,
 12,  17,  20 ));
+        final Set<Integer> target = new HashSet<Integer>(Arrays.asList(20, 70,
120, 170, 200));
         final Set<Integer> tested = DerivedSet.create(source, this);
         assertEquals(target.size(), tested.size());
         assertEquals(target, tested);
@@ -76,8 +76,8 @@ public final strictfp class DerivedSetTe
      */
     @Test
     public void testWithExclusion() {
-        final Set<Integer> source = new HashSet<>(Arrays.asList(2,  7,  12, 
EXCLUDED, 20));
-        final Set<Integer> target = new HashSet<>(Arrays.asList(20, 70, 120,
200));
+        final Set<Integer> source = new HashSet<Integer>(Arrays.asList(2,  7,
 12,  EXCLUDED, 20));
+        final Set<Integer> target = new HashSet<Integer>(Arrays.asList(20, 70,
120, 200));
         final Set<Integer> tested = DerivedSet.create(source, this);
         assertEquals(target.size(), tested.size());
         assertEquals(target, tested);



Mime
View raw message