sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1763328 - in /sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util: ArgumentChecks.java Numbers.java collection/IntegerList.java
Date Tue, 04 Oct 2016 20:45:38 GMT
Author: desruisseaux
Date: Tue Oct  4 20:45:38 2016
New Revision: 1763328

URL: http://svn.apache.org/viewvc?rev=1763328&view=rev
Log:
Javadoc formatting. There is no significant code change in this commit, except the replacement
of 'bitCount' loop by a call to:
Math.max(1, Integer.SIZE - Integer.numberOfLeadingZeros(maximalValue)); which produces the
same result in a more efficient way.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/IntegerList.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java?rev=1763328&r1=1763327&r2=1763328&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
[UTF-8] Tue Oct  4 20:45:38 2016
@@ -95,8 +95,8 @@ public final class ArgumentChecks extend
      * Makes sure that an argument is non-null. If the given {@code object} is null, then
a
      * {@link NullArgumentException} is thrown with a localized message containing the given
name.
      *
-     * @param  name The name of the argument to be checked. Used only if an exception is
thrown.
-     * @param  object The user argument to check against null value.
+     * @param  name    the name of the argument to be checked. Used only if an exception
is thrown.
+     * @param  object  the user argument to check against null value.
      * @throws NullArgumentException if {@code object} is null.
      */
     public static void ensureNonNull(final String name, final Object object)
@@ -121,9 +121,9 @@ public final class ArgumentChecks extend
      *       then the formatted message will contain {@code "axes[2]"}.</li>
      * </ul>
      *
-     * @param  name    The name of the argument to be checked. Used only if an exception
is thrown.
-     * @param  index   The Index of the element to check in an array or a list. Used only
if an exception is thrown.
-     * @param  element The array or list element to check against null value.
+     * @param  name     the name of the argument to be checked. Used only if an exception
is thrown.
+     * @param  index    the Index of the element to check in an array or a list. Used only
if an exception is thrown.
+     * @param  element  the array or list element to check against null value.
      * @throws NullArgumentException if {@code element} is null.
      */
     public static void ensureNonNullElement(final String name, final int index, final Object
element)
@@ -148,8 +148,8 @@ public final class ArgumentChecks extend
      * a {@linkplain CharSequence#length() length} equals to 0, then an {@link IllegalArgumentException}
      * is thrown.
      *
-     * @param  name The name of the argument to be checked. Used only if an exception is
thrown.
-     * @param  text The user argument to check against null value and empty sequences.
+     * @param  name  the name of the argument to be checked. Used only if an exception is
thrown.
+     * @param  text  the user argument to check against null value and empty sequences.
      * @throws NullArgumentException if {@code text} is null.
      * @throws IllegalArgumentException if {@code text} is empty.
      */
@@ -169,10 +169,10 @@ public final class ArgumentChecks extend
      * If this method does not thrown an exception, then the value can be casted to the class
      * represented by {@code expectedType} without throwing a {@link ClassCastException}.
      *
-     * @param  name The name of the argument to be checked, used only if an exception is
thrown.
+     * @param  name  the name of the argument to be checked, used only if an exception is
thrown.
      *         Can be {@code null} if the name is unknown.
      * @param  expectedType the expected type (class or interface).
-     * @param  value The value to check, or {@code null}.
+     * @param  value  the value to check, or {@code null}.
      * @throws IllegalArgumentException if {@code value} is non-null and is not assignable
to the given type.
      *
      * @see org.apache.sis.util.collection.Containers#property(Map, Object, Class)
@@ -202,9 +202,9 @@ public final class ArgumentChecks extend
      * upper value. This method is designed for methods that expect an index value as the
only
      * argument. For this reason, this method does not take the argument name.
      *
-     * @param  upper The maximal index value, exclusive.
-     * @param  index The index to check.
-     * @throws IndexOutOfBoundsException If the given index is negative or not lower than
the
+     * @param  upper  the maximal index value, exclusive.
+     * @param  index  the index to check.
+     * @throws IndexOutOfBoundsException if the given index is negative or not lower than
the
      *         given upper value.
      *
      * @see #ensurePositive(String, int)
@@ -225,10 +225,10 @@ public final class ArgumentChecks extend
      * because this information is assumed to be provided by the implementation rather than
      * the user.</p>
      *
-     * @param  length The length of the sequence (array, {@link CharSequence}, <i>etc.</i>).
-     * @param  lower  The user-specified lower index, inclusive.
-     * @param  upper  The user-specified upper index, exclusive.
-     * @throws IndexOutOfBoundsException If the given [{@code lower} … {@code upper}]
+     * @param  length  the length of the sequence (array, {@link CharSequence}, <i>etc.</i>).
+     * @param  lower   the user-specified lower index, inclusive.
+     * @param  upper   the user-specified upper index, exclusive.
+     * @throws IndexOutOfBoundsException if the given [{@code lower} … {@code upper}]
      *         range is out of the sequence index range.
      *
      * @see #ensureSizeBetween(String, int, int, int)
@@ -244,8 +244,8 @@ public final class ArgumentChecks extend
      * This method is used for checking values that are <strong>not</strong>
index.
      * For checking index values, use {@link #ensureValidIndex(int, int)} instead.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is negative.
      *
      * @see #ensureValidIndex(int, int)
@@ -263,8 +263,8 @@ public final class ArgumentChecks extend
     /**
      * Ensures that the given long value is greater than or equals to zero.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is negative.
      *
      * @see #ensureStrictlyPositive(String, long)
@@ -283,8 +283,8 @@ public final class ArgumentChecks extend
      * {@linkplain Float#isNaN(float) NaN} and is greater than or equals to zero. Note that
      * {@linkplain Float#POSITIVE_INFINITY positive infinity} is considered a valid value.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is NaN or negative.
      *
      * @see #ensureStrictlyPositive(String, float)
@@ -292,7 +292,7 @@ public final class ArgumentChecks extend
     public static void ensurePositive(final String name, final float value)
             throws IllegalArgumentException
     {
-        if (!(value >= 0)) { // Use '!' for catching NaN.
+        if (!(value >= 0)) {                                                // Use '!'
for catching NaN.
             throw new IllegalArgumentException(Float.isNaN(value) ?
                     Errors.format(Errors.Keys.NotANumber_1, name) :
                     Errors.format(Errors.Keys.NegativeArgument_2, name, value));
@@ -304,8 +304,8 @@ public final class ArgumentChecks extend
      * {@linkplain Double#isNaN(double) NaN} and is greater than or equals to zero. Note
that
      * {@linkplain Double#POSITIVE_INFINITY positive infinity} is considered a valid value.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is NaN or negative.
      *
      * @see #ensureStrictlyPositive(String, double)
@@ -313,7 +313,7 @@ public final class ArgumentChecks extend
     public static void ensurePositive(final String name, final double value)
             throws IllegalArgumentException
     {
-        if (!(value >= 0)) { // Use '!' for catching NaN.
+        if (!(value >= 0)) {                                                // Use '!'
for catching NaN.
             throw new IllegalArgumentException(Double.isNaN(value) ?
                     Errors.format(Errors.Keys.NotANumber_1, name)  :
                     Errors.format(Errors.Keys.NegativeArgument_2, name, value));
@@ -323,8 +323,8 @@ public final class ArgumentChecks extend
     /**
      * Ensures that the given integer value is greater than zero.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is negative or equals to zero.
      *
      * @see #ensurePositive(String, int)
@@ -341,8 +341,8 @@ public final class ArgumentChecks extend
     /**
      * Ensures that the given long value is greater than zero.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is negative or equals to zero.
      *
      * @see #ensurePositive(String, long)
@@ -361,8 +361,8 @@ public final class ArgumentChecks extend
      * {@linkplain Float#isNaN(float) NaN} and is greater than zero. Note that
      * {@linkplain Float#POSITIVE_INFINITY positive infinity} is considered a valid value.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is NaN, zero or negative.
      *
      * @see #ensurePositive(String, float)
@@ -370,7 +370,7 @@ public final class ArgumentChecks extend
     public static void ensureStrictlyPositive(final String name, final float value)
             throws IllegalArgumentException
     {
-        if (!(value > 0)) { // Use '!' for catching NaN.
+        if (!(value > 0)) {                                                 // Use '!'
for catching NaN.
             throw new IllegalArgumentException(Float.isNaN(value) ?
                     Errors.format(Errors.Keys.NotANumber_1, name) :
                     Errors.format(Errors.Keys.ValueNotGreaterThanZero_2, name, value));
@@ -382,8 +382,8 @@ public final class ArgumentChecks extend
      * {@linkplain Double#isNaN(double) NaN} and is greater than zero. Note that
      * {@linkplain Double#POSITIVE_INFINITY positive infinity} is considered a valid value.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is NaN, zero or negative.
      *
      * @see #ensurePositive(String, double)
@@ -391,7 +391,7 @@ public final class ArgumentChecks extend
     public static void ensureStrictlyPositive(final String name, final double value)
             throws IllegalArgumentException
     {
-        if (!(value > 0)) { // Use '!' for catching NaN.
+        if (!(value > 0)) {                                                 // Use '!'
for catching NaN.
             throw new IllegalArgumentException(Double.isNaN(value) ?
                     Errors.format(Errors.Keys.NotANumber_1, name)  :
                     Errors.format(Errors.Keys.ValueNotGreaterThanZero_2, name, value));
@@ -403,8 +403,8 @@ public final class ArgumentChecks extend
      * {@linkplain Float#isNaN(float) NaN} neither {@linkplain Float#isInfinite(float)}.
      * The value can be negative, zero or positive.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is NaN or infinite.
      */
     public static void ensureFinite(final String name, final float value) {
@@ -420,8 +420,8 @@ public final class ArgumentChecks extend
      * {@linkplain Double#isNaN(double) NaN} neither {@linkplain Double#isInfinite(double)}.
      * The value can be negative, zero or positive.
      *
-     * @param  name   The name of the argument to be checked, used only if an exception is
thrown.
-     * @param  value  The user argument to check.
+     * @param  name   the name of the argument to be checked, used only if an exception is
thrown.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is NaN or infinite.
      */
     public static void ensureFinite(final String name, final double value) {
@@ -445,10 +445,10 @@ public final class ArgumentChecks extend
      *       argument is an index in a list or an array.</li>
      * </ul>
      *
-     * @param  name  The name of the argument to be checked. Used only if an exception is
thrown.
-     * @param  min   The minimal value, inclusive.
-     * @param  max   The maximal value, inclusive.
-     * @param  value The user argument to check.
+     * @param  name   the name of the argument to be checked. Used only if an exception is
thrown.
+     * @param  min    the minimal value, inclusive.
+     * @param  max    the maximal value, inclusive.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is not in the given range.
      *
      * @see #ensureSizeBetween(String, int, int, int)
@@ -467,10 +467,10 @@ public final class ArgumentChecks extend
     /**
      * Ensures that the given long value is between the given bounds, inclusive.
      *
-     * @param  name  The name of the argument to be checked. Used only if an exception is
thrown.
-     * @param  min   The minimal value, inclusive.
-     * @param  max   The maximal value, inclusive.
-     * @param  value The user argument to check.
+     * @param  name   the name of the argument to be checked. Used only if an exception is
thrown.
+     * @param  min    the minimal value, inclusive.
+     * @param  max    the maximal value, inclusive.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is not in the given range.
      */
     public static void ensureBetween(final String name, final long min, final long max, final
long value)
@@ -485,10 +485,10 @@ public final class ArgumentChecks extend
     /**
      * Ensures that the given floating point value is between the given bounds, inclusive.
      *
-     * @param  name  The name of the argument to be checked. Used only if an exception is
thrown.
-     * @param  min   The minimal value, inclusive.
-     * @param  max   The maximal value, inclusive.
-     * @param  value The user argument to check.
+     * @param  name   the name of the argument to be checked. Used only if an exception is
thrown.
+     * @param  min    the minimal value, inclusive.
+     * @param  max    the maximal value, inclusive.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is NaN or not in the given range.
      */
     public static void ensureBetween(final String name, final float min, final float max,
final float value)
@@ -504,10 +504,10 @@ public final class ArgumentChecks extend
     /**
      * Ensures that the given floating point value is between the given bounds, inclusive.
      *
-     * @param  name  The name of the argument to be checked. Used only if an exception is
thrown.
-     * @param  min   The minimal value, inclusive.
-     * @param  max   The maximal value, inclusive.
-     * @param  value The user argument to check.
+     * @param  name   the name of the argument to be checked. Used only if an exception is
thrown.
+     * @param  min    the minimal value, inclusive.
+     * @param  max    the maximal value, inclusive.
+     * @param  value  the user argument to check.
      * @throws IllegalArgumentException if the given value is NaN or not in the given range.
      */
     public static void ensureBetween(final String name, final double min, final double max,
final double value)
@@ -525,10 +525,10 @@ public final class ArgumentChecks extend
      * This method performs the same check than {@link #ensureBetween(String, int, int, int)
      * ensureBetween(…)}, but the error message is different in case of failure.
      *
-     * @param  name  The name of the argument to be checked. Used only if an exception is
thrown.
-     * @param  min   The minimal size (inclusive), or 0 if none.
-     * @param  max   The maximal size (inclusive), or {@link Integer#MAX_VALUE} if none.
-     * @param  size  The user collection size or array length to be checked.
+     * @param  name  the name of the argument to be checked. Used only if an exception is
thrown.
+     * @param  min   the minimal size (inclusive), or 0 if none.
+     * @param  max   the maximal size (inclusive), or {@link Integer#MAX_VALUE} if none.
+     * @param  size  the user collection size or array length to be checked.
      * @throws IllegalArgumentException if the given value is not in the given range.
      *
      * @see #ensureBetween(String, int, int, int)
@@ -556,8 +556,8 @@ public final class ArgumentChecks extend
      * Ensures that the given integer is a valid Unicode code point. The range of valid code
points goes
      * from {@link Character#MIN_CODE_POINT U+0000} to {@link Character#MAX_CODE_POINT U+10FFFF}
inclusive.
      *
-     * @param  name The name of the argument to be checked. Used only if an exception is
thrown.
-     * @param  code The Unicode code point to verify.
+     * @param  name  the name of the argument to be checked. Used only if an exception is
thrown.
+     * @param  code  the Unicode code point to verify.
      * @throws IllegalArgumentException if the given value is not a valid Unicode code point.
      *
      * @since 0.4
@@ -573,9 +573,9 @@ public final class ArgumentChecks extend
      * Ensures that the given CRS, if non-null, has the expected number of dimensions.
      * This method does nothing if the given coordinate reference system is null.
      *
-     * @param  name     The name of the argument to be checked. Used only if an exception
is thrown.
-     * @param  expected The expected number of dimensions.
-     * @param  crs      The coordinate reference system to check for its dimension, or {@code
null}.
+     * @param  name      the name of the argument to be checked. Used only if an exception
is thrown.
+     * @param  expected  the expected number of dimensions.
+     * @param  crs       the coordinate reference system to check for its dimension, or {@code
null}.
      * @throws MismatchedDimensionException if the given coordinate reference system is non-null
      *         and does not have the expected number of dimensions.
      */
@@ -598,9 +598,9 @@ public final class ArgumentChecks extend
      * Ensures that the given coordinate system, if non-null, has the expected number of
dimensions.
      * This method does nothing if the given coordinate system is null.
      *
-     * @param  name     The name of the argument to be checked. Used only if an exception
is thrown.
-     * @param  expected The expected number of dimensions.
-     * @param  cs       The coordinate system to check for its dimension, or {@code null}.
+     * @param  name      the name of the argument to be checked. Used only if an exception
is thrown.
+     * @param  expected  the expected number of dimensions.
+     * @param  cs        the coordinate system to check for its dimension, or {@code null}.
      * @throws MismatchedDimensionException if the given coordinate system is non-null
      *         and does not have the expected number of dimensions.
      *
@@ -622,10 +622,10 @@ public final class ArgumentChecks extend
      * Ensures that the given vector, if non-null, has the expected number of dimensions
      * (taken as its length). This method does nothing if the given vector is null.
      *
-     * @param  name     The name of the argument to be checked. Used only if an exception
is thrown.
-     * @param  expected The expected number of dimensions.
-     * @param  vector   The vector to check for its number of dimensions, or {@code null}.
-     * @throws MismatchedDimensionException If the given vector is non-null and does not
have the
+     * @param  name      the name of the argument to be checked. Used only if an exception
is thrown.
+     * @param  expected  the expected number of dimensions.
+     * @param  vector    the vector to check for its number of dimensions, or {@code null}.
+     * @throws MismatchedDimensionException if the given vector is non-null and does not
have the
      *         expected number of dimensions (taken as its length).
      */
     public static void ensureDimensionMatches(final String name, final int expected, final
double[] vector)
@@ -644,10 +644,10 @@ public final class ArgumentChecks extend
      * Ensures that the given direct position, if non-null, has the expected number of dimensions.
      * This method does nothing if the given direct position is null.
      *
-     * @param  name     The name of the argument to be checked. Used only if an exception
is thrown.
-     * @param  expected The expected number of dimensions.
-     * @param  position The direct position to check for its dimension, or {@code null}.
-     * @throws MismatchedDimensionException If the given direct position is non-null and
does
+     * @param  name      the name of the argument to be checked. Used only if an exception
is thrown.
+     * @param  expected  the expected number of dimensions.
+     * @param  position  the direct position to check for its dimension, or {@code null}.
+     * @throws MismatchedDimensionException if the given direct position is non-null and
does
      *         not have the expected number of dimensions.
      */
     public static void ensureDimensionMatches(final String name, final int expected, final
DirectPosition position)
@@ -666,10 +666,10 @@ public final class ArgumentChecks extend
      * Ensures that the given envelope, if non-null, has the expected number of dimensions.
      * This method does nothing if the given envelope is null.
      *
-     * @param  name     The name of the argument to be checked. Used only if an exception
is thrown.
-     * @param  expected The expected number of dimensions.
-     * @param  envelope The envelope to check for its dimension, or {@code null}.
-     * @throws MismatchedDimensionException If the given envelope is non-null and does
+     * @param  name      the name of the argument to be checked. Used only if an exception
is thrown.
+     * @param  expected  the expected number of dimensions.
+     * @param  envelope  the envelope to check for its dimension, or {@code null}.
+     * @throws MismatchedDimensionException if the given envelope is non-null and does
      *         not have the expected number of dimensions.
      */
     public static void ensureDimensionMatches(final String name, final int expected, final
Envelope envelope)

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java?rev=1763328&r1=1763327&r2=1763328&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java [UTF-8]
Tue Oct  4 20:45:38 2016
@@ -50,6 +50,15 @@ import static java.lang.Double.doubleToL
 public final class Numbers extends Static {
     /**
      * Constant of value {@value} used in {@code switch} statements or as index in arrays.
+     * This enumeration provides the following guarantees (some Apache SIS code rely on them):
+     *
+     * <ul>
+     *   <li>{@code OTHER} value is 0.</li>
+     *   <li>Primitive types are enumerated in this exact order (from lower value to
higher value):
+     *       {@code BYTE}, {@code SHORT}, {@code INTEGER}, {@code LONG}, {@code FLOAT}, {@code
DOUBLE}.</li>
+     *   <li>{@link java.math} types of greater capacity that primitive types ({@code
BIG_DECIMAL}
+     *       and {@code BIG_INTEGER}) have higher enumeration values.</li>
+     * </ul>
      */
     public static final byte
             BIG_DECIMAL=10, BIG_INTEGER=9,
@@ -84,7 +93,7 @@ public final class Numbers extends Stati
     /** The wrapper for the primitive type.     */ private final Class<?> wrapper;
     /** {@code true} for floating point number. */ private final boolean  isFloat;
     /** {@code true} for integer number.        */ private final boolean  isInteger;
-    /** The size in bytes, or -1 if variable.   */ private final byte     size;
+    /** The size in bits, or -1 if variable.    */ private final byte     size;
     /** Constant to be used in switch statement.*/ private final byte     ordinal;
     /** The internal form of the primitive name.*/ private final char     internal;
     /** The null, NaN, 0 or false value.        */ private final Object   nullValue;
@@ -220,8 +229,8 @@ public final class Numbers extends Stati
      * {@link Byte}, {@link Short}, {@link Integer}, {@link Long}, {@link Float}, {@link
Double},
      * {@link BigInteger} or {@link BigDecimal} types.
      *
-     * <p>If one of the given argument is null, then this method returns the class
of the
-     * non-null argument. If both arguments are null, then this method returns {@code null}.</p>
+     * <p>If one of the given argument is null, then this method returns the class
of the non-null argument.
+     * If both arguments are null, then this method returns {@code null}.</p>
      *
      * @param  n1  the first number, or {@code null}.
      * @param  n2  the second number, or {@code null}.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/IntegerList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/IntegerList.java?rev=1763328&r1=1763327&r2=1763328&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/IntegerList.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/IntegerList.java
[UTF-8] Tue Oct  4 20:45:38 2016
@@ -83,8 +83,8 @@ public class IntegerList extends Abstrac
     /**
      * Creates an initially empty list with the given initial capacity.
      *
-     * @param initialCapacity The initial capacity.
-     * @param maximalValue The maximal value to be allowed, inclusive.
+     * @param initialCapacity  the initial capacity.
+     * @param maximalValue     the maximal value to be allowed, inclusive.
      */
     public IntegerList(int initialCapacity, int maximalValue) {
         this(initialCapacity, maximalValue, false);
@@ -94,22 +94,17 @@ public class IntegerList extends Abstrac
      * Creates a new list with the given initial size.
      * The value of all elements are initialized to 0.
      *
-     * @param initialCapacity The initial capacity.
-     * @param maximalValue The maximal value to be allowed, inclusive.
-     * @param fill If {@code true}, the initial {@linkplain #size() size} is set to the initial
capacity
+     * @param initialCapacity  the initial capacity.
+     * @param maximalValue     the maximal value to be allowed, inclusive.
+     * @param fill if {@code true}, the initial {@linkplain #size() size} is set to the initial
capacity
      *        with all values set to 0.
      */
-    public IntegerList(final int initialCapacity, int maximalValue, final boolean fill) {
+    public IntegerList(final int initialCapacity, final int maximalValue, final boolean fill)
{
         ArgumentChecks.ensureStrictlyPositive("initialCapacity", initialCapacity);
         ArgumentChecks.ensureStrictlyPositive("maximalValue",    maximalValue);
-        int bitCount = 0;
-        do {
-            bitCount++;
-            maximalValue >>>= 1;
-        } while (maximalValue != 0);
-        this.bitCount = bitCount;
-        mask = (1 << bitCount) - 1;
-        values = new long[length(initialCapacity)];
+        bitCount = Math.max(1, Integer.SIZE - Integer.numberOfLeadingZeros(maximalValue));
+        mask     = (1 << bitCount) - 1;
+        values   = new long[length(initialCapacity)];
         if (fill) {
             size = initialCapacity;
         }
@@ -118,8 +113,8 @@ public class IntegerList extends Abstrac
     /**
      * Returns the array length required for holding a list of the given size.
      *
-     * @param size The list size.
-     * @return The array length for holding a list of the given size.
+     * @param  size  the list size.
+     * @return the array length for holding a list of the given size.
      */
     private int length(int size) {
         size *= bitCount;
@@ -134,7 +129,7 @@ public class IntegerList extends Abstrac
      * Returns the maximal value that can be stored in this list.
      * May be slightly higher than the value given to the constructor.
      *
-     * @return The maximal value, inclusive.
+     * @return the maximal value, inclusive.
      */
     public int maximalValue() {
         return mask;
@@ -143,7 +138,7 @@ public class IntegerList extends Abstrac
     /**
      * Returns the current number of values in this list.
      *
-     * @return The number of values.
+     * @return the number of values.
      */
     @Override
     public int size() {
@@ -155,7 +150,7 @@ public class IntegerList extends Abstrac
      * then the elements after the new size are discarded. If the new size is greater than
      * the previous one, then the extra elements are initialized to 0.
      *
-     * @param size The new size.
+     * @param  size  the new size.
      */
     public void resize(final int size) {
         ArgumentChecks.ensurePositive("size", size);
@@ -180,7 +175,7 @@ public class IntegerList extends Abstrac
      * Fills the list with the given value.
      * Every existing values are overwritten from index 0 inclusive up to {@link #size} exclusive.
      *
-     * @param value The value to set.
+     * @param  value  the value to set.
      */
     @SuppressWarnings("fallthrough")
     public void fill(int value) {
@@ -197,7 +192,7 @@ public class IntegerList extends Abstrac
             case  8: value |= (value << 8);     // Fall through
             case 16: value |= (value << 16);    // Fall through
             case 32: p = (value & 0xFFFFFFFFL) | ((long) value << 32); break;
-            default: {    // General case (unoptimized)
+            default: {                          // General case (unoptimized)
                 for (int i=0; i<size; i++) {
                     setUnchecked(i, value);
                 }
@@ -218,8 +213,8 @@ public class IntegerList extends Abstrac
     /**
      * Adds the given element to this list.
      *
-     * @param  value The value to add.
-     * @return Always {@code true}.
+     * @param  value  the value to add.
+     * @return always {@code true}.
      * @throws NullPointerException if the given value is null.
      * @throws IllegalArgumentException if the given value is out of bounds.
      */
@@ -232,7 +227,7 @@ public class IntegerList extends Abstrac
     /**
      * Adds the given element as the {@code int} primitive type.
      *
-     * @param  value The value to add.
+     * @param  value  the value to add.
      * @throws IllegalArgumentException if the given value is out of bounds.
      *
      * @see #removeLast()
@@ -250,8 +245,8 @@ public class IntegerList extends Abstrac
     /**
      * Returns the element at the given index.
      *
-     * @param  index The element index.
-     * @return The value at the given index.
+     * @param  index  the element index.
+     * @return the value at the given index.
      * @throws IndexOutOfBoundsException if the given index is out of bounds.
      */
     @Override
@@ -262,8 +257,8 @@ public class IntegerList extends Abstrac
     /**
      * Returns the element at the given index as the {@code int} primitive type.
      *
-     * @param  index The element index.
-     * @return The value at the given index.
+     * @param  index  the element index.
+     * @return the value at the given index.
      * @throws IndexOutOfBoundsException if the given index is out of bounds.
      */
     public int getInt(final int index) throws IndexOutOfBoundsException {
@@ -275,8 +270,8 @@ public class IntegerList extends Abstrac
      * Returns the element at the given index as the {@code int} primitive type.
      * This argument does not check argument validity, since it is assumed already done.
      *
-     * @param  index The element index.
-     * @return The value at the given index.
+     * @param  index  the element index.
+     * @return the value at the given index.
      */
     private int getUnchecked(int index) {
         index *= bitCount;
@@ -295,9 +290,9 @@ public class IntegerList extends Abstrac
     /**
      * Sets the element at the given index.
      *
-     * @param  index The element index.
-     * @param  value The value at the given index.
-     * @return The previous value at the given index.
+     * @param  index  the element index.
+     * @param  value  the value at the given index.
+     * @return the previous value at the given index.
      * @throws IndexOutOfBoundsException if the given index is out of bounds.
      * @throws IllegalArgumentException if the given value is out of bounds.
      * @throws NullPointerException if the given value is null.
@@ -312,8 +307,8 @@ public class IntegerList extends Abstrac
     /**
      * Sets the element at the given index as the {@code int} primitive type.
      *
-     * @param  index The element index.
-     * @param  value The value at the given index.
+     * @param  index  the element index.
+     * @param  value  the value at the given index.
      * @throws IndexOutOfBoundsException if the given index is out of bounds.
      * @throws IllegalArgumentException if the given value is out of bounds.
      */
@@ -327,8 +322,8 @@ public class IntegerList extends Abstrac
      * Sets the element at the given index as the {@code int} primitive type.
      * This argument does not check argument validity, since it is assumed already done.
      *
-     * @param index The element index.
-     * @param value The value at the given index.
+     * @param  index  the element index.
+     * @param  value  the value at the given index.
      */
     private void setUnchecked(int index, int value) {
         index *= bitCount;
@@ -347,8 +342,8 @@ public class IntegerList extends Abstrac
     /**
      * Removes the element at the given index.
      *
-     * @param  index The index of the element to remove.
-     * @return The previous value of the element at the given index.
+     * @param  index  the index of the element to remove.
+     * @return the previous value of the element at the given index.
      * @throws IndexOutOfBoundsException if the given index is out of bounds.
      */
     @Override
@@ -361,7 +356,7 @@ public class IntegerList extends Abstrac
     /**
      * Retrieves and remove the last element of this list.
      *
-     * @return The tail of this list.
+     * @return the tail of this list.
      * @throws NoSuchElementException if this list is empty.
      */
     public int removeLast() throws NoSuchElementException {
@@ -375,8 +370,8 @@ public class IntegerList extends Abstrac
      * Removes all values in the given range of index.
      * Shifts any succeeding elements to the left (reduces their index).
      *
-     * @param lower Index of the first element to remove, inclusive.
-     * @param upper Index after the last element to be removed.
+     * @param  lower  index of the first element to remove, inclusive.
+     * @param  upper  index after the last element to be removed.
      */
     @Override
     protected void removeRange(int lower, int upper) {
@@ -410,8 +405,8 @@ public class IntegerList extends Abstrac
     /**
      * Returns the occurrence of the given value in this list.
      *
-     * @param  value The value to search for.
-     * @return The number of time the given value occurs in this list.
+     * @param  value  the value to search for.
+     * @return the number of time the given value occurs in this list.
      */
     public int occurrence(final int value) {
         int count = 0;
@@ -434,7 +429,7 @@ public class IntegerList extends Abstrac
     /**
      * Returns a clone of this list.
      *
-     * @return A clone of this list.
+     * @return a clone of this list.
      */
     @Override
     public IntegerList clone() {
@@ -451,8 +446,8 @@ public class IntegerList extends Abstrac
     /**
      * Invokes {@link #trimToSize()} before serialization in order to make the stream more
compact.
      *
-     * @param  out The output stream where to serialize this list.
-     * @throws IOException If an I/O error occurred while writing.
+     * @param  out  the output stream where to serialize this list.
+     * @throws IOException if an I/O error occurred while writing.
      */
     private void writeObject(final ObjectOutputStream out) throws IOException {
         trimToSize();




Mime
View raw message