You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/02/14 15:18:06 UTC
svn commit: r1446197 - in
/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure:
MeasurementRange.java NumberRange.java Range.java
Author: desruisseaux
Date: Thu Feb 14 14:18:06 2013
New Revision: 1446197
URL: http://svn.apache.org/r1446197
Log:
Renamed <T> type to <E> for consistency with "element type" name, and for consistency with CheckedContainer parent interface.
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java?rev=1446197&r1=1446196&r2=1446197&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/MeasurementRange.java Thu Feb 14 14:18:06 2013
@@ -43,7 +43,7 @@ import java.util.Objects;
* <li>{@link #castTo(Class)} for casting the range values to an other type.</li>
* </ul>
*
- * @param <T> The type of range elements as a subclass of {@link Number}.
+ * @param <E> The type of range elements as a subclass of {@link Number}.
*
* @author Martin Desruisseaux (IRD)
* @since 0.3 (derived from geotk-2.4)
@@ -51,7 +51,7 @@ import java.util.Objects;
* @module
*/
@Immutable
-public class MeasurementRange<T extends Number & Comparable<? super T>> extends NumberRange<T> {
+public class MeasurementRange<E extends Number & Comparable<? super E>> extends NumberRange<E> {
/**
* Serial number for inter-operability with different versions.
*/
@@ -161,7 +161,7 @@ public class MeasurementRange<T extends
* @param range The range to copy. The elements must be {@link Number} instances.
* @param units The units of measurement, or {@code null} if unknown.
*/
- public MeasurementRange(final Range<T> range, final Unit<?> units) {
+ public MeasurementRange(final Range<E> range, final Unit<?> units) {
super(range);
this.units = units;
}
@@ -174,7 +174,7 @@ public class MeasurementRange<T extends
* @param maxValue The maximum value, <strong>inclusive</strong>, or {@code null} if none.
* @param units The units of measurement, or {@code null} if unknown.
*/
- public MeasurementRange(final Class<T> type, final T minValue, final T maxValue, final Unit<?> units) {
+ public MeasurementRange(final Class<E> type, final E minValue, final E maxValue, final Unit<?> units) {
super(type, minValue, maxValue);
this.units = units;
}
@@ -189,9 +189,9 @@ public class MeasurementRange<T extends
* @param isMaxIncluded {@code true} if the maximal value is inclusive, or {@code false} if exclusive.
* @param units The units of measurement, or {@code null} if unknown.
*/
- public MeasurementRange(final Class<T> type,
- final T minValue, final boolean isMinIncluded,
- final T maxValue, final boolean isMaxIncluded,
+ public MeasurementRange(final Class<E> type,
+ final E minValue, final boolean isMinIncluded,
+ final E maxValue, final boolean isMaxIncluded,
final Unit<?> units)
{
super(type, minValue, isMinIncluded, maxValue, isMaxIncluded);
@@ -207,7 +207,7 @@ public class MeasurementRange<T extends
* @param range The range to copy. The elements must be {@link Number} instances.
* @param units The units of measurement, or {@code null} if unknown.
*/
- private MeasurementRange(final Class<T> type, final Range<? extends Number> range, final Unit<?> units) {
+ private MeasurementRange(final Class<E> type, final Range<? extends Number> range, final Unit<?> units) {
super(type, range);
this.units = units;
}
@@ -216,8 +216,8 @@ public class MeasurementRange<T extends
* Creates a new range using the same element type and the same units than this range.
*/
@Override
- Range<T> create(final T minValue, final boolean isMinIncluded,
- final T maxValue, final boolean isMaxIncluded)
+ Range<E> create(final E minValue, final boolean isMinIncluded,
+ final E maxValue, final boolean isMaxIncluded)
{
return new MeasurementRange<>(elementType, minValue, isMinIncluded, maxValue, isMaxIncluded, units);
}
@@ -242,7 +242,7 @@ public class MeasurementRange<T extends
* @throws ConversionException if the target units are not compatible with
* this {@linkplain #getUnits() range units}.
*/
- public MeasurementRange<T> convertTo(final Unit<?> targetUnits) throws ConversionException {
+ public MeasurementRange<E> convertTo(final Unit<?> targetUnits) throws ConversionException {
return convertAndCast(elementType, targetUnits);
}
@@ -268,7 +268,7 @@ public class MeasurementRange<T extends
* @throws IllegalArgumentException if the given target unit is not compatible with
* the unit of this range.
*/
- private <N extends T> Range<N> convert(final Range<N> range) throws IllegalArgumentException {
+ private <N extends E> Range<N> convert(final Range<N> range) throws IllegalArgumentException {
if (range instanceof MeasurementRange<?>) try {
return ((MeasurementRange<N>) range).convertAndCast(range.elementType, units);
} catch (ConversionException e) {
@@ -350,7 +350,7 @@ public class MeasurementRange<T extends
*/
@Override
@SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
- final Range<T>[] newArray(final int length) {
+ final Range<E>[] newArray(final int length) {
return new MeasurementRange[length];
}
@@ -364,7 +364,7 @@ public class MeasurementRange<T extends
* {@code MeasurementRange} using incommensurable units of measurement.
*/
@Override
- public boolean contains(final Range<? extends T> range) throws IllegalArgumentException {
+ public boolean contains(final Range<? extends E> range) throws IllegalArgumentException {
return super.contains(convert(range));
}
@@ -378,7 +378,7 @@ public class MeasurementRange<T extends
* {@code MeasurementRange} using incommensurable units of measurement.
*/
@Override
- public boolean intersects(final Range<? extends T> range) throws IllegalArgumentException {
+ public boolean intersects(final Range<? extends E> range) throws IllegalArgumentException {
return super.intersects(convert(range));
}
@@ -392,7 +392,7 @@ public class MeasurementRange<T extends
* {@code MeasurementRange} using incommensurable units of measurement.
*/
@Override
- public Range<T> intersect(final Range<T> range) throws IllegalArgumentException {
+ public Range<E> intersect(final Range<E> range) throws IllegalArgumentException {
return super.intersect(convert(range));
}
@@ -406,7 +406,7 @@ public class MeasurementRange<T extends
* {@code MeasurementRange} using incommensurable units of measurement.
*/
@Override
- public Range<T> union(final Range<T> range) throws IllegalArgumentException {
+ public Range<E> union(final Range<E> range) throws IllegalArgumentException {
return super.union(convert(range));
}
@@ -420,7 +420,7 @@ public class MeasurementRange<T extends
* {@code MeasurementRange} using incommensurable units of measurement.
*/
@Override
- public Range<T>[] subtract(final Range<T> range) throws IllegalArgumentException {
+ public Range<E>[] subtract(final Range<E> range) throws IllegalArgumentException {
return super.subtract(convert(range));
}
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java?rev=1446197&r1=1446196&r2=1446197&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java Thu Feb 14 14:18:06 2013
@@ -32,13 +32,13 @@ import org.apache.sis.util.resources.Err
* ({@link #contains(Range) contains}, {@link #intersect(Range) intersect},
* {@link #intersects(Range) intersects}, {@link #union(Range) union} and
* {@link #subtract(Range) subtract}) requires argument or range elements
- * of type {@code <T>}. No type conversion is performed.</li>
+ * of type {@code <E>}. No type conversion is performed.</li>
*
* <li>Methods defined in this class with the {@code Any} suffix
* ({@link #containsAny(NumberRange) containsAny}, {@link #intersectAny(NumberRange) intersectAny},
* {@link #intersectsAny(NumberRange) intersectsAny}, {@link #unionAny(NumberRange) unionAny} and
* {@link #subtractAny(NumberRange) subtractAny}) are more lenient on the argument or range element
- * type {@code <T>}. Widening conversions are performed as needed.</li>
+ * type {@code <E>}. Widening conversions are performed as needed.</li>
* </ul>
*
* The methods from the parent class are preferable when the ranges are known to contain elements
@@ -51,7 +51,7 @@ import org.apache.sis.util.resources.Err
* <li>{@link #castTo(Class)} for casting the range values to an other type.</li>
* </ul>
*
- * @param <T> The type of range elements as a subclass of {@link Number}.
+ * @param <E> The type of range elements as a subclass of {@link Number}.
*
* @author Martin Desruisseaux (IRD)
* @author Jody Garnett (for parameterized type inspiration)
@@ -62,7 +62,7 @@ import org.apache.sis.util.resources.Err
* @see RangeFormat
*/
@Immutable
-public class NumberRange<T extends Number & Comparable<? super T>> extends Range<T> {
+public class NumberRange<E extends Number & Comparable<? super E>> extends Range<E> {
/**
* Serial number for inter-operability with different versions.
*/
@@ -325,7 +325,7 @@ public class NumberRange<T extends Numbe
*
* @param range The range to copy. The elements must be {@link Number} instances.
*/
- public NumberRange(final Range<T> range) {
+ public NumberRange(final Range<E> range) {
super(range);
}
@@ -337,7 +337,7 @@ public class NumberRange<T extends Numbe
* @param minValue The minimum value, inclusive, or {@code null} if none.
* @param maxValue The maximum value, <strong>inclusive</strong>, or {@code null} if none.
*/
- public NumberRange(final Class<T> type, final T minValue, final T maxValue) {
+ public NumberRange(final Class<E> type, final E minValue, final E maxValue) {
super(type, minValue, maxValue);
}
@@ -351,9 +351,9 @@ public class NumberRange<T extends Numbe
* @param maxValue The maximal value, or {@code null} if none.
* @param isMaxIncluded {@code true} if the maximal value is inclusive, or {@code false} if exclusive.
*/
- public NumberRange(final Class<T> type,
- final T minValue, final boolean isMinIncluded,
- final T maxValue, final boolean isMaxIncluded)
+ public NumberRange(final Class<E> type,
+ final E minValue, final boolean isMinIncluded,
+ final E maxValue, final boolean isMaxIncluded)
{
super(type, minValue, isMinIncluded, maxValue, isMaxIncluded);
}
@@ -368,7 +368,7 @@ public class NumberRange<T extends Numbe
* @throws IllegalArgumentException If the given type is not one of the primitive
* wrappers for numeric types.
*/
- NumberRange(final Class<T> type, final Range<? extends Number> range)
+ NumberRange(final Class<E> type, final Range<? extends Number> range)
throws IllegalArgumentException
{
super(type, Numbers.cast(range.minValue, type), range.isMinIncluded,
@@ -380,8 +380,8 @@ public class NumberRange<T extends Numbe
* be overridden by subclasses in order to create a range of a more specific type.
*/
@Override
- Range<T> create(final T minValue, final boolean isMinIncluded,
- final T maxValue, final boolean isMaxIncluded)
+ Range<E> create(final E minValue, final boolean isMinIncluded,
+ final E maxValue, final boolean isMaxIncluded)
{
return new NumberRange<>(elementType, minValue, isMinIncluded, maxValue, isMaxIncluded);
}
@@ -436,7 +436,7 @@ public class NumberRange<T extends Numbe
*/
@Override
@SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
- Range<T>[] newArray(final int length) {
+ Range<E>[] newArray(final int length) {
return new NumberRange[length];
}
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java?rev=1446197&r1=1446196&r2=1446197&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Range.java Thu Feb 14 14:18:06 2013
@@ -38,9 +38,9 @@ import java.util.Objects;
* since iterations over the values will never reach the infinite bound.
*
* {@section Type and value of range elements}
- * To be a member of a {@code Range}, the {@code <T>} type defining the range must implement the
+ * To be a member of a {@code Range}, the {@code <E>} type defining the range must implement the
* {@link Comparable} interface. All argument values given to the methods of this class shall be
- * or contain instances of the same {@code <T>} type. The type is enforced by parameterized type,
+ * or contain instances of the same {@code <E>} type. The type is enforced by parameterized type,
* but some subclasses may put additional constraints. For example {@link MeasurementRange} will
* additionally checks the units of measurement. Every methods defined in this class may throw
* an {@link IllegalArgumentException} if a given argument does not meet a constraint other than
@@ -51,7 +51,7 @@ import java.util.Objects;
* in a locale-insensitive way. In order to format a range using a different locale,
* or for parsing a range, use {@link RangeFormat}.
*
- * @param <T> The type of range elements, typically a {@link Number} subclass or {@link java.util.Date}.
+ * @param <E> The type of range elements, typically a {@link Number} subclass or {@link java.util.Date}.
*
* @author Joe White
* @author Martin Desruisseaux (Geomatys)
@@ -63,7 +63,7 @@ import java.util.Objects;
* @see RangeFormat
*/
@Immutable
-public class Range<T extends Comparable<? super T>> implements CheckedContainer<T>, Serializable {
+public class Range<E extends Comparable<? super E>> implements CheckedContainer<E>, Serializable {
/**
* For cross-version compatibility.
*/
@@ -74,12 +74,12 @@ public class Range<T extends Comparable<
*
* @see #getElementType()
*/
- final Class<T> elementType;
+ final Class<E> elementType;
/**
* The minimal and maximal values.
*/
- final T minValue, maxValue;
+ final E minValue, maxValue;
/**
* Whether the minimal or maximum value is included.
@@ -92,7 +92,7 @@ public class Range<T extends Comparable<
*
* @param range The range to copy.
*/
- public Range(final Range<T> range) {
+ public Range(final Range<E> range) {
elementType = range.elementType;
minValue = range.minValue;
isMinIncluded = range.isMinIncluded;
@@ -108,7 +108,7 @@ public class Range<T extends Comparable<
* @param minValue The minimal value (inclusive), or {@code null} if none.
* @param maxValue The maximal value (inclusive), or {@code null} if none.
*/
- public Range(final Class<T> elementType, final T minValue, final T maxValue) {
+ public Range(final Class<E> elementType, final E minValue, final E maxValue) {
ArgumentChecks.ensureNonNull("elementType", elementType);
this.elementType = elementType;
this.minValue = minValue;
@@ -127,9 +127,9 @@ public class Range<T extends Comparable<
* @param maxValue The maximal value, or {@code null} if none.
* @param isMaxIncluded {@code true} if the maximal value is inclusive, or {@code false} if exclusive.
*/
- public Range(final Class<T> elementType,
- final T minValue, final boolean isMinIncluded,
- final T maxValue, final boolean isMaxIncluded)
+ public Range(final Class<E> elementType,
+ final E minValue, final boolean isMinIncluded,
+ final E maxValue, final boolean isMaxIncluded)
{
ArgumentChecks.ensureNonNull("elementType", elementType);
/*
@@ -154,8 +154,8 @@ public class Range<T extends Comparable<
* covariant return type) because those operations may return the given argument directly,
* and we have no guarantees on the type of those arguments.}
*/
- Range<T> create(final T minValue, final boolean isMinIncluded,
- final T maxValue, final boolean isMaxIncluded)
+ Range<E> create(final E minValue, final boolean isMinIncluded,
+ final E maxValue, final boolean isMaxIncluded)
{
return new Range<>(elementType, minValue, isMinIncluded, maxValue, isMaxIncluded);
}
@@ -169,7 +169,7 @@ public class Range<T extends Comparable<
* get an {@link ArrayStoreException}.
*/
@SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
- Range<T>[] newArray(final int length) {
+ Range<E>[] newArray(final int length) {
return new Range[length];
}
@@ -196,7 +196,7 @@ public class Range<T extends Comparable<
* This is the type specified at construction time.
*/
@Override
- public Class<T> getElementType() {
+ public Class<E> getElementType() {
return elementType;
}
@@ -207,7 +207,7 @@ public class Range<T extends Comparable<
*
* @return The minimal value, or {@code null} if this range is unbounded on the lower side.
*/
- public T getMinValue() {
+ public E getMinValue() {
return minValue;
}
@@ -229,7 +229,7 @@ public class Range<T extends Comparable<
*
* @return The maximal value, or {@code null} if this range is unbounded on the upper side.
*/
- public T getMaxValue() {
+ public E getMaxValue() {
return maxValue;
}
@@ -276,7 +276,7 @@ public class Range<T extends Comparable<
* @param value The value to check for inclusion in this range.
* @return {@code true} if the given value is included in this range.
*/
- public boolean contains(final T value) {
+ public boolean contains(final E value) {
if (value == null) {
return false;
}
@@ -316,7 +316,7 @@ public class Range<T extends Comparable<
* @throws IllegalArgumentException is the given range is incompatible,
* for example because of incommensurable units of measurement.
*/
- public boolean contains(final Range<? extends T> range) {
+ public boolean contains(final Range<? extends E> range) {
/*
* We could implement this method as below:
*
@@ -350,7 +350,7 @@ public class Range<T extends Comparable<
* @throws IllegalArgumentException is the given range is incompatible,
* for example because of incommensurable units of measurement.
*/
- public boolean intersects(final Range<? extends T> range) {
+ public boolean intersects(final Range<? extends E> range) {
return (compareMinTo(range.maxValue, range.isMaxIncluded ? 0 : +1) <= 0) &&
(compareMaxTo(range.minValue, range.isMinIncluded ? 0 : -1) >= 0);
}
@@ -363,7 +363,7 @@ public class Range<T extends Comparable<
* @throws IllegalArgumentException is the given range is incompatible,
* for example because of incommensurable units of measurement.
*/
- public Range<T> intersect(final Range<T> range) {
+ public Range<E> intersect(final Range<E> range) {
/*
* For two ranges [Lâ ⦠Hâ] and [Lâ ⦠Hâ], the intersection is given by
* ([max(Lâ, Lâ) ⦠min(Hâ, Hâ)]). Only two comparisons is needed.
@@ -375,7 +375,7 @@ public class Range<T extends Comparable<
* be either 'this' or 'range), return that range. Otherwise we need to create a
* new one.
*/
- final Range<T> intersect, min, max;
+ final Range<E> intersect, min, max;
min = compareMinTo(range.minValue, range.isMinIncluded ? 0 : -1) < 0 ? range : this;
max = compareMaxTo(range.maxValue, range.isMaxIncluded ? 0 : +1) > 0 ? range : this;
if (min == max) {
@@ -395,8 +395,8 @@ public class Range<T extends Comparable<
* @throws IllegalArgumentException is the given range is incompatible,
* for example because of incommensurable units of measurement.
*/
- public Range<T> union(final Range<T> range) {
- final Range<T> union, min, max;
+ public Range<E> union(final Range<E> range) {
+ final Range<E> union, min, max;
min = compareMinTo(range.minValue, range.isMinIncluded ? 0 : -1) > 0 ? range : this;
max = compareMaxTo(range.maxValue, range.isMaxIncluded ? 0 : +1) < 0 ? range : this;
if (min == max) {
@@ -425,12 +425,12 @@ public class Range<T extends Comparable<
* @throws IllegalArgumentException is the given range is incompatible,
* for example because of incommensurable units of measurement.
*/
- public Range<T>[] subtract(final Range<T> range) {
+ public Range<E>[] subtract(final Range<E> range) {
/*
* Implementation note: never store the 'range' argument value in the array
* returned by 'newArray(int)', otherwise we may get an ArrayStoreException.
*/
- final Range<T> subtract;
+ final Range<E> subtract;
if (!intersects(range)) {
subtract = this;
} else {
@@ -445,7 +445,7 @@ public class Range<T extends Comparable<
subtract = create(range.maxValue, !range.isMaxIncluded, maxValue, isMaxIncluded);
} else {
if (!clipMax) {
- final Range<T>[] array = newArray(2);
+ final Range<E>[] array = newArray(2);
array[0] = create(minValue, isMinIncluded, range.minValue, !range.isMinIncluded);
array[1] = create(range.maxValue, !range.isMaxIncluded, maxValue, isMaxIncluded);
return array;
@@ -455,7 +455,7 @@ public class Range<T extends Comparable<
}
assert contains(subtract) : subtract;
assert !subtract.intersects(range) : subtract;
- final Range<T>[] array = newArray(1);
+ final Range<E>[] array = newArray(1);
array[0] = subtract;
return array;
}
@@ -479,7 +479,7 @@ public class Range<T extends Comparable<
*
* @see #containsNC(Range)
*/
- private int compareMinTo(final T value, int position) {
+ private int compareMinTo(final E value, int position) {
/*
* Check for infinite values. If the given value is infinite, it can be either positive or
* negative infinity, which we can infer from the 'position' argument. Note that 'position'
@@ -522,7 +522,7 @@ public class Range<T extends Comparable<
* Compares the {@linkplain #getMaxValue() maximum value} of this range with the given bound of
* another range. See the comment in {@link #compareMinTo(Comparable, int)} for more details.
*/
- private int compareMaxTo(final T value, int position) {
+ private int compareMaxTo(final E value, int position) {
if (maxValue == null) {
return (value == null) ? 0 : +1;
}