Author: desruisseaux
Date: Wed Feb 27 15:56:37 2013
New Revision: 1450819
URL: http://svn.apache.org/r1450819
Log:
Moved ValueRange in public API, in order to allow the addition of convenience
NumberRange constructor.
This is needed by metadata implementation backed by Java reflection.
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/ValueRange.java
- copied, changed from r1450757,
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ValueRange.java
Removed:
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ValueRange.java
Modified:
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/package-info.java
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=1450819&r1=1450818&r2=1450819&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/NumberRange.java
[UTF-8] Wed Feb 27 15:56:37 2013
@@ -270,6 +270,18 @@ public class NumberRange<E extends Numbe
}
/**
+ * Constructs a range of the given type with values from the given
annotation.
+ *
+ * @param type The element type, usually one of {@link Byte}, {@link
Short},
+ * {@link Integer}, {@link Long}, {@link Float} or {@link
Double}.
+ * @param range The range of values.
+ */
+ public NumberRange(final Class<E> type, final ValueRange range) {
+ super(type, Numbers.cast(valueOf("minimum", range.minimum(),
Double.NEGATIVE_INFINITY), type), range.isMinIncluded(),
+ Numbers.cast(valueOf("maximum", range.maximum(),
Double.POSITIVE_INFINITY), type), range.isMaxIncluded());
+ }
+
+ /**
* Constructs a range of {@link Number} objects.
*
* @param type The element type, usually one of {@link Byte},
{@link Short},
Copied:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/ValueRange.java
(from r1450757,
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ValueRange.java)
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/ValueRange.java?p2=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/ValueRange.java&p1=sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ValueRange.java&r1=1450757&r2=1450819&rev=1450819&view=diff
==============================================================================
---
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ValueRange.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/ValueRange.java
[UTF-8] Wed Feb 27 15:56:37 2013
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.internal.metadata;
+package org.apache.sis.measure;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
@@ -23,18 +23,57 @@ import java.lang.annotation.RetentionPol
/**
- * The range of values that a method can return.
- * This is used mostly for metadata objects performing runtime checks.
+ * The range of values assignable to a field, or to a JavaBean property.
+ * When used with JavaBeans, this annotation shall be applied on the getter
method
+ * as in the following example:
*
- * <p>We do not put (yet) this annotation in public API because it may be
- * replaced by some <cite>checker framework</cite> in a future JDK version.</p>
+ * {@preformat java
+ * @ValueRange(minimum=0, maximum=100)
+ * public double getCloudCoverPercentage() {
+ * // Method implementation here...
+ * }
+ * }
+ *
+ * By default, both endpoints are inclusive. To make an endpoint exclusive,
+ * a {@code isFooInclusive} argument needs to be explicitely provided. This
+ * is useful mostly for floating point numbers. In the following example,
+ * values can be very close to zero but not equals, since a value of exactly
+ * zero makes no sense. Note also that the {@code maximum} value is not
explicitely
+ * provided, in which case it defaults to infinity.
+ *
+ * {@preformat java
+ * @@ValueRange(minimum=0, isMinIncluded=false)
+ * public double getSpatialResolution() {
+ * // Method implementation here...
+ * }
+ * }
+ *
+ * It is sometime convenient to convert {@code ValueRange} to {@link
NumberRange} instances
+ * in order to leverage the various {@code NumberRange} operations. The
following example
+ * uses a convenience constructor for this purpose. Note that the {@code
Double} type could
+ * by inferred from {@link java.lang.reflect.Method#getReturnType()}.
+ *
+ * {@preformat java
+ * Method myMethod = ...;
+ * ValueRange annotation = myMethod.getAnnotation(ValueRange.class);
+ * if (annotation != null) {
+ * NumberRange<Double> range = new NumberRange(Double.class,
annotation);
+ * // Use the range here.
+ * }
+ * }
+ *
+ * The {@link org.apache.sis.metadata.AbstractMetadata} class uses this
annotation for inferring
+ * {@link org.opengis.parameter.ParameterDescriptor} from metadata interfaces
and implementation
+ * classes.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.04)
* @version 0.3
* @module
+ *
+ * @see NumberRange#NumberRange(Class, ValueRange)
*/
-@Target(ElementType.METHOD)
+@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ValueRange {
/**
@@ -47,6 +86,14 @@ public @interface ValueRange {
double minimum() default Double.NEGATIVE_INFINITY;
/**
+ * {@code true} if the {@linkplain #minimum() minimal} value is inclusive,
or {@code false}
+ * if it is exclusive. By default the minimum value is inclusive.
+ *
+ * @return {@code true} if the minimum value is inclusive.
+ */
+ boolean isMinIncluded() default true;
+
+ /**
* Returns the maximal value that a method can return. The default value is
* {@linkplain Double#POSITIVE_INFINITY positive infinity}, which means
that
* there is no maximal value.
@@ -56,14 +103,6 @@ public @interface ValueRange {
double maximum() default Double.POSITIVE_INFINITY;
/**
- * {@code true} if the {@linkplain #minimum() minimal} value is inclusive,
or {@code false}
- * if it is exclusive. By default the minimum value is inclusive.
- *
- * @return {@code true} if the minimum value is inclusive.
- */
- boolean isMinIncluded() default true;
-
- /**
* {@code true} if the {@linkplain #maximum() maximal} value is inclusive,
or {@code false}
* if it is exclusive. By default the maximum value is
<strong>inclusive</strong>.
*
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/package-info.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/package-info.java?rev=1450819&r1=1450818&r2=1450819&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/package-info.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/package-info.java
[UTF-8] Wed Feb 27 15:56:37 2013
@@ -26,7 +26,8 @@
* {@link org.apache.sis.measure.Latitude})</li>
* <li>{@link org.apache.sis.measure.Range} and its subclasses
* ({@link org.apache.sis.measure.NumberRange},
- * {@link org.apache.sis.measure.MeasurementRange})</li>
+ * {@link org.apache.sis.measure.MeasurementRange}) or annotation
+ * ({@link org.apache.sis.measure.ValueRange}</li>
* <li>Formatters
* ({@link org.apache.sis.measure.AngleFormat},
* {@link org.apache.sis.measure.CoordinateFormat},