sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1394579 - in /sis/trunk: ./ sis-utility/src/main/java/org/apache/sis/internal/util/ sis-utility/src/main/java/org/apache/sis/math/ sis-utility/src/main/java/org/apache/sis/util/collection/ sis-utility/src/main/java/org/apache/sis/util/reso...
Date Fri, 05 Oct 2012 15:16:46 GMT
Author: desruisseaux
Date: Fri Oct  5 15:16:45 2012
New Revision: 1394579

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

Added:
    sis/trunk/sis-utility/src/main/java/org/apache/sis/math/
      - copied from r1394573, sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/math/
    sis/trunk/sis-utility/src/test/java/org/apache/sis/math/
      - copied from r1394573, sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/math/
Modified:
    sis/trunk/   (props changed)
    sis/trunk/pom.xml
    sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/Objects.java
    sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.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/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Propchange: sis/trunk/
------------------------------------------------------------------------------
  Merged /sis/branches/JDK6:r1394375-1394573

Modified: sis/trunk/pom.xml
URL: http://svn.apache.org/viewvc/sis/trunk/pom.xml?rev=1394579&r1=1394578&r2=1394579&view=diff
==============================================================================
--- sis/trunk/pom.xml (original)
+++ sis/trunk/pom.xml Fri Oct  5 15:16:45 2012
@@ -471,7 +471,7 @@ Apache SIS is a toolkit for describing l
             </group>
             <group>
               <title>Utilities</title>
-              <packages>org.apache.sis.io*:org.apache.sis.util*</packages>
+              <packages>org.apache.sis.math*:org.apache.sis.util*:org.apache.sis.io*</packages>
             </group>
           </groups>
 

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/Objects.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/Objects.java?rev=1394579&r1=1394578&r2=1394579&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/Objects.java (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/Objects.java Fri Oct
 5 15:16:45 2012
@@ -23,7 +23,7 @@ import java.util.Arrays;
  * Place holder for {@link java.util.Objects}. This class will be deleted when we will be
allowed
  * to compile for JDK7.
  *
- * @author Martin Desruisseaux (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from GeoAPI)
  * @version 0.3
  * @module

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java?rev=1394579&r1=1394578&r2=1394579&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java Fri
Oct  5 15:16:45 2012
@@ -23,7 +23,7 @@
  * This package is for internal use by SIS only. Classes in this package
  * may change in incompatible ways in any future version without notice.
  *
- * @author Martin Desruisseaux (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.0)
  * @version 0.3
  * @module

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java?rev=1394579&r1=1394578&r2=1394579&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java Fri
Oct  5 15:16:45 2012
@@ -25,6 +25,7 @@ import java.lang.reflect.Array;
 import org.apache.sis.util.Disposable;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.internal.util.ReferenceQueueConsumer;
+import org.apache.sis.math.MathFunctions;
 
 
 /**
@@ -42,6 +43,7 @@ import org.apache.sis.internal.util.Refe
 abstract class WeakEntry<E> extends WeakReference<E> implements Disposable {
     /**
      * Minimal capacity for the internal table of entries.
+     * Must be a prime number.
      */
     static final int MIN_CAPACITY = 7;
 
@@ -133,10 +135,22 @@ abstract class WeakEntry<E> extends Weak
      * @return The new table array, or {@code oldTable} if no rehash were needed.
      */
     static <E> WeakEntry<E>[] rehash(final WeakEntry<E>[] oldTable, final
int count, final String callerMethod) {
-        final int capacity = Math.max(count*2, MIN_CAPACITY);
+        /*
+         * Compute the capacity as twice the expected number of elements, then take
+         * (if possible) the first prime number equals or greater to that value.
+         * This is based on classical books saying that prime values reduce the
+         * risk of key collisions.
+         */
+        int capacity = Math.max(count*2, MIN_CAPACITY);
+        if (capacity < MathFunctions.HIGHEST_SUPPORTED_PRIME_NUMBER) {
+            capacity = MathFunctions.nextPrimeNumber(capacity);
+        }
         if (capacity == oldTable.length) {
             return oldTable;
         }
+        /*
+         * Rehash the table.
+         */
         final Class<?> entryType = oldTable.getClass().getComponentType();
         @SuppressWarnings("unchecked")
         final WeakEntry<E>[] table = (WeakEntry<E>[]) Array.newInstance(entryType,
capacity);
@@ -149,6 +163,9 @@ abstract class WeakEntry<E> extends Weak
                 table[index] = e;
             }
         }
+        /*
+         * We are done. Log the operation if logging is enabled at that level.
+         */
         final Logger logger = Collections.LOGGER;
         if (logger.isLoggable(Level.FINEST)) {
             final LogRecord record = Messages.getResources(null).getLogRecord(Level.FINEST,

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java?rev=1394579&r1=1394578&r2=1394579&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java
(original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java
Fri Oct  5 15:16:45 2012
@@ -149,7 +149,7 @@ public class WeakValueHashMap<K,V> exten
         public boolean equals(final Object other) {
             if (other instanceof Map.Entry<?,?>) {
                 final Map.Entry<?,?> that = (Map.Entry<?,?>) other;
-                return equal(key, that.getKey()) && Objects.equals(get(), that.getValue());
+                return keyEquals(key, that.getKey()) && Objects.equals(get(), that.getValue());
             }
             return false;
         }
@@ -160,7 +160,7 @@ public class WeakValueHashMap<K,V> exten
          */
         @Override
         public int hashCode() {
-            int code = hash(key);
+            int code = keyHashCode(key);
             final V val = get();
             if (val != null) {
                 code ^= val.hashCode();
@@ -279,14 +279,14 @@ public class WeakValueHashMap<K,V> exten
     /**
      * Returns the hash code value for the given key.
      */
-    final int hash(final Object key) {
+    final int keyHashCode(final Object key) {
         return mayContainArrays ? Utilities.deepHashCode(key) : key.hashCode();
     }
 
     /**
      * Returns {@code true} if the two given keys are equal.
      */
-    final boolean equal(final Object k1, final Object k2) {
+    final boolean keyEquals(final Object k1, final Object k2) {
         return mayContainArrays ? Objects.deepEquals(k1, k2) : k1.equals(k2);
     }
 
@@ -328,9 +328,9 @@ public class WeakValueHashMap<K,V> exten
         assert isValid();
         if (key != null) {
             final Entry[] table = this.table;
-            final int index = (hash(key) & HASH_MASK) % table.length;
+            final int index = (keyHashCode(key) & HASH_MASK) % table.length;
             for (Entry e = table[index]; e != null; e = (Entry) e.next) {
-                if (equal(key, e.key)) {
+                if (keyEquals(key, e.key)) {
                     return e.get();
                 }
             }
@@ -349,10 +349,10 @@ public class WeakValueHashMap<K,V> exten
          */
         V oldValue = null;
         Entry[] table = this.table;
-        final int hash = hash(key) & HASH_MASK;
+        final int hash = keyHashCode(key) & HASH_MASK;
         int index = hash % table.length;
         for (Entry e = table[index]; e != null; e = (Entry) e.next) {
-            if (equal(key, e.key)) {
+            if (keyEquals(key, e.key)) {
                 oldValue = e.get();
                 e.dispose();
                 table = this.table; // May have changed.

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=1394579&r1=1394578&r2=1394579&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 Fri Oct
 5 15:16:45 2012
@@ -57,6 +57,21 @@ public final class Errors extends Indexe
         public static final int IllegalArgumentClass_3 = 2;
 
         /**
+         * Argument ‘{0}’ can not take the “{1}” value.
+         */
+        public static final int IllegalArgumentValue_2 = 14;
+
+        /**
+         * Illegal value for argument ‘{0}’.
+         */
+        public static final int IllegalArgument_1 = 15;
+
+        /**
+         * Illegal bits pattern: {0}.
+         */
+        public static final int IllegalBitsPattern_1 = 16;
+
+        /**
          * Class ‘{0}’ is illegal. It must be ‘{1}’ or a derived class.
          */
         public static final int IllegalClass_2 = 3;

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=1394579&r1=1394578&r2=1394579&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 Fri
Oct  5 15:16:45 2012
@@ -14,17 +14,20 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-EmptyArgument_1=Argument \u2018{0}\u2019 shall not be empty.
-IllegalArgumentClass_3=Argument \u2018{0}\u2019 can not be an instance of \u2018{1}\u2019.
Expected an instance of \u2018{2}\u2019 or derived type.
-IllegalClass_2=Class \u2018{0}\u2019 is illegal. It must be \u2018{1}\u2019 or a derived
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.
-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.
-NullArgument_1=Argument \u2018{0}\u2019 shall not be null.
-UnexpectedArgumentDimension_3=Argument \u2018{0}\u2019 has {1} dimensions, while {2} was
expected.
-ValueAlreadyDefined_1=A value is already defined for \u201c{0}\u201d.
-ValueNotGreaterThanZero_2=Value \u2018{0}\u2019={1} is invalid. Expected a number greater
than 0.
-ValueOutOfRange_4=Value \u2018{0}\u2019={1} is invalid. Expected a value in the [{2} \u2026
{3}] range.
+EmptyArgument_1                 = Argument \u2018{0}\u2019 shall not be empty.
+IllegalArgument_1               = Illegal value for argument \u2018{0}\u2019.
+IllegalArgumentClass_3          = Argument \u2018{0}\u2019 can not be an instance of \u2018{1}\u2019.
Expected an instance of \u2018{2}\u2019 or derived type.
+IllegalArgumentValue_2          = Argument \u2018{0}\u2019 can not take the \u201c{1}\u201d
value.
+IllegalBitsPattern_1            = Illegal bits pattern: {0}.
+IllegalClass_2                  = Class \u2018{0}\u2019 is illegal. It must be \u2018{1}\u2019
or a derived 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.
+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.
+NullArgument_1                  = Argument \u2018{0}\u2019 shall not be null.
+UnexpectedArgumentDimension_3   = Argument \u2018{0}\u2019 has {1} dimensions, while {2}
was expected.
+ValueAlreadyDefined_1           = A value is already defined for \u201c{0}\u201d.
+ValueNotGreaterThanZero_2       = Value \u2018{0}\u2019={1} is invalid. Expected a number
greater than 0.
+ValueOutOfRange_4               = Value \u2018{0}\u2019={1} is invalid. Expected a value
in the [{2} \u2026 {3}] range.

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=1394579&r1=1394578&r2=1394579&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
Fri Oct  5 15:16:45 2012
@@ -14,17 +14,20 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-EmptyArgument_1=L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre vide.
-IllegalArgumentClass_3=L\u2019argument \u2018{0}\u2019 ne peut pas \u00eatre de type \u2018{1}\u2019.
Une instance de \u2018{2}\u2019 ou d\u2019un type d\u00e9riv\u00e9 \u00e9tait attendue.
-IllegalClass_2=La classe \u2018{0}\u2019 est ill\u00e9gale. Il doit s\u2019agir d\u2019une
classe \u2018{1}\u2019 ou d\u00e9riv\u00e9e.
-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.
-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.
-NullArgument_1=L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre nul.
-UnexpectedArgumentDimension_3=L\u2019argument \u2018{0}\u2019 a {1} dimensions, alors qu\u2019on
en attendait {2}.
-ValueAlreadyDefined_1=Une valeur est d\u00e9j\u00e0 d\u00e9finie pour \u201c{0}\u201d.
-ValueNotGreaterThanZero_2=La valeur \u2018{0}\u2019={1} n\u2019est pas valide. On attendait
un nombre positif non-nul.
-ValueOutOfRange_4=La valeur \u2018{0}\u2019={1} est invalide. Une valeur dans la plage [{2}
\u2026 {3}] \u00e9tait attendue.
+EmptyArgument_1                 = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre vide.
+IllegalArgument_1               = Valeur ill\u00e9gale pour l\u2019argument \u2018{0}\u2019.
+IllegalArgumentClass_3          = L\u2019argument \u2018{0}\u2019 ne peut pas \u00eatre de
type \u2018{1}\u2019. Une instance de \u2018{2}\u2019 ou d\u2019un type d\u00e9riv\u00e9 \u00e9tait
attendue.
+IllegalArgumentValue_2          = L\u2019argument \u2018{0}\u2019 n\u2019accepte pas la valeur
\u201c{1}\u201d.
+IllegalBitsPattern_1            = Pattern de bits invalide: {0}.
+IllegalClass_2                  = La classe \u2018{0}\u2019 est ill\u00e9gale. Il doit s\u2019agir
d\u2019une classe \u2018{1}\u2019 ou d\u00e9riv\u00e9e.
+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.
+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.
+NullArgument_1                  = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre nul.
+UnexpectedArgumentDimension_3   = L\u2019argument \u2018{0}\u2019 a {1} dimensions, alors
qu\u2019on en attendait {2}.
+ValueAlreadyDefined_1           = Une valeur est d\u00e9j\u00e0 d\u00e9finie pour \u201c{0}\u201d.
+ValueNotGreaterThanZero_2       = La valeur \u2018{0}\u2019={1} n\u2019est pas valide. On
attendait un nombre positif non-nul.
+ValueOutOfRange_4               = La valeur \u2018{0}\u2019={1} est invalide. Une valeur
dans la plage [{2} \u2026 {3}] \u00e9tait attendue.

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1394579&r1=1394578&r2=1394579&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java Fri
Oct  5 15:16:45 2012
@@ -46,7 +46,8 @@ import org.junit.runners.Suite;
   org.apache.sis.util.type.DefaultInternationalStringTest.class,
   org.apache.sis.internal.util.ReferenceQueueConsumerTest.class,
   org.apache.sis.util.collection.WeakHashSetTest.class,
-  org.apache.sis.util.collection.WeakValueHashMapTest.class
+  org.apache.sis.util.collection.WeakValueHashMapTest.class,
+  org.apache.sis.math.MathFunctionsTest.class
 })
 public final strictfp class UtilityTestSuite extends TestSuite {
 }



Mime
View raw message