Author: desruisseaux
Date: Wed Mar 5 21:21:46 2014
New Revision: 1574667
URL: http://svn.apache.org/r1574667
Log:
Continue Feature work: complete DefaultFeatureType based on the
DefaultParameterDescriptor experience.
Despite the API being intentionally similar, there is no relationship between
those two classes because
they are different concepts.
Modified:
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
Modified:
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java?rev=1574667&r1=1574666&r2=1574667&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
[UTF-8] Wed Mar 5 21:21:46 2014
@@ -86,14 +86,13 @@ public class AbstractIdentifiedType impl
/**
* Compares this type with the given object for equality.
*
- * @param obj The object to compare with this class.
- * @return {@code true} if the given object is equals to this map.
+ * @param obj The object to compare with this type.
+ * @return {@code true} if the given object is equals to this type.
*/
@Override
public boolean equals(final Object obj) {
if (obj != null && getClass() != obj.getClass()) {
- final AbstractIdentifiedType that = (AbstractIdentifiedType) obj;
- return Objects.equals(this.name, that.name);
+ return Objects.equals(name, ((AbstractIdentifiedType) obj).name);
}
return false;
}
Modified:
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java?rev=1574667&r1=1574666&r2=1574667&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
[UTF-8] Wed Mar 5 21:21:46 2014
@@ -17,17 +17,24 @@
package org.apache.sis.feature;
import org.opengis.util.GenericName;
+import org.apache.sis.measure.Range;
+import org.apache.sis.util.Classes;
+import org.apache.sis.util.Numbers;
+import org.apache.sis.util.resources.Errors;
import org.apache.sis.internal.util.Numerics;
import static org.apache.sis.util.ArgumentChecks.*;
+// Related to JDK7
+import java.util.Objects;
+
/**
* Definition of an attribute in a feature type.
*
* <div class="note"><b>Note:</b>
- * Compared to the Java language, {@code FeatureType} is equivalent to {@link
Class} and
- * {@code AttributeType} is equivalent to {@link
java.lang.reflect.Field}.</div>
+ * Compared to the Java language, {@code AttributeType} is equivalent to
{@link java.lang.reflect.Field}
+ * while {@code FeatureType} is equivalent to {@link Class}.</div>
*
* <div class="warning"><b>Warning:</b>
* This class is expected to implement a GeoAPI {@code AttributeType}
interface in a future version.
@@ -41,6 +48,11 @@ import static org.apache.sis.util.Argume
*/
public class DefaultAttributeType<T> extends AbstractIdentifiedType {
/**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = 8215784957556648553L;
+
+ /**
* The class that describe the type of attribute values.
*
* @see #getValueClass()
@@ -48,56 +60,178 @@ public class DefaultAttributeType<T> ext
private final Class<T> valueClass;
/**
- * The default value for the attribute, or {@code null}.
+ * The minimum and maximum attribute value with their unit of measurement,
or {@code null} if none.
+ * If this field is non-null, then <code>valueDomain.{@linkplain
Range#getElementType() getElementType()}</code>
+ * shall be one of the following:
+ *
+ * <ul>
+ * <li>If {@link #valueClass} is not an array, then the range element
type shall be the same class.</li>
+ * <li>If {@code valueClass} is an array, then the range element type
shall be the wrapper of
+ * <code>valueClass.{@linkplain Class#getComponentType()
getComponentType()}</code>.</li>
+ * </ul>
+ *
+ * @see #getValueDomain()
+ */
+ private final Range<?> valueDomain;
+
+ /**
+ * The default value for the attribute, or {@code null} if none.
*
* @see #getDefaultValue()
*/
private final T defaultValue;
/**
+ * The minimum/maximum number of occurrences of the property within its
containing entity.
+ *
+ * @see #getMinimumOccurs()
+ * @see #getMaximumOccurs()
+ */
+ private final int minimumOccurs, maximumOccurs;
+
+ /**
* Creates an attribute type of the given name.
*
+ * {@section Domain of attribute values}
+ * If {@code valueDomain} argument is non-null, then it shall comply to
the following conditions:
+ *
+ * <ul>
+ * <li>The range shall be non-{@linkplain Range#isEmpty() empty}.</li>
+ * <li><code>valueDomain.{@linkplain Range#getElementType()
getElementType()}</code> shall be equals
+ * to one of the following:
+ * <ul>
+ * <li>to {@code valueClass} if the later is not an array,</li>
+ * <li>or to <code>{@linkplain Numbers#primitiveToWrapper(Class)
+ * primitiveToWrapper}(valueClass.{@linkplain
Class#getComponentType() getComponentType()})</code>
+ * if {@code valueClass} is an array.</li>
+ * </ul>
+ * </li>
+ * </ul>
+ *
* @param name The name of this attribute type.
* @param valueClass The type of attribute values.
- * @param defaultValue The default value, or {@code null} if none.
- */
- public DefaultAttributeType(final GenericName name, final Class<T>
valueClass, final T defaultValue) {
+ * @param valueDomain The minimum value, maximum value and unit of
measurement, or {@code null} if none.
+ * @param defaultValue The default value for the attribute, or {@code
null} if none.
+ * @param minimumOccurs The minimum number of occurrences of the property
within its containing entity.
+ * @param maximumOccurs The maximum number of occurrences of the property
within its containing entity,
+ * or {@link Integer#MAX_VALUE} if none.
+ */
+ public DefaultAttributeType(final GenericName name, final Class<T>
valueClass, final Range<?> valueDomain,
+ final T defaultValue, final int minimumOccurs, final int
maximumOccurs)
+ {
super(name);
ensureNonNull("valueClass", valueClass);
ensureCanCast("defaultValue", valueClass, defaultValue);
- this.valueClass = valueClass;
- this.defaultValue = Numerics.cached(defaultValue);
+ if (minimumOccurs < 0 || minimumOccurs > maximumOccurs) {
+ throw new
IllegalArgumentException(Errors.format(Errors.Keys.IllegalRange_2,
minimumOccurs, maximumOccurs));
+ }
+ if (valueDomain != null) {
+ Class<?> componentType = valueClass.getComponentType();
+ if (componentType != null) {
+ componentType = Numbers.primitiveToWrapper(componentType);
+ } else {
+ componentType = valueClass;
+ }
+ final Class<?> elementType = valueDomain.getElementType();
+ if (elementType != componentType) {
+ throw new
IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentClass_2,
+ "valueDomain", "Range<" +
Classes.getShortName(elementType) + '>'));
+ }
+ if (valueDomain.isEmpty()) {
+ throw new
IllegalArgumentException(Errors.format(Errors.Keys.IllegalRange_2,
+ valueDomain.getMinValue(), valueDomain.getMaxValue()));
+ }
+ }
+ this.valueClass = valueClass;
+ this.valueDomain = valueDomain;
+ this.defaultValue = Numerics.cached(defaultValue);
+ this.minimumOccurs = minimumOccurs;
+ this.maximumOccurs = maximumOccurs;
}
/**
- * The type of attribute values.
+ * Returns the type of attribute values.
+ *
+ * @return The type of attribute values.
*/
- public Class<T> getValueClass() {
+ public final Class<T> getValueClass() {
return valueClass;
}
/**
- * The minimum number of occurrences of the property within its containing
entity.
+ * Returns the domain of values with their unit of measurement (if any),
or {@code null} if none.
+ *
+ * <div class="note"><b>API note:</b> If this method returns a non-null
value, then its type is either exactly
+ * {@code Range<T>}, or {@code Range<E>} where {@code <E>} is the
{@linkplain Class#getComponentType() component
+ * type} of {@code <T>} (using wrapper classes for primitive types).</div>
+ *
+ * @return The domain of values, or {@code null}.
+ */
+ /* Implementation note: this method is final because the constructor
performs various checks on range validity,
+ * and we can not express those rules in the method signature. If the user
was allowed to override this method,
+ * there is no way we can ensure that the range element type still valid.
+ */
+ public final Range<?> getValueDomain() {
+ return valueDomain;
+ }
+
+ /**
+ * Returns the default value for the attribute.
+ * This value is used when an attribute is created and no value for it is
specified.
+ *
+ * @return The default value for the attribute, or {@code null} if none.
+ */
+ public T getDefaultValue() {
+ return defaultValue;
+ }
+
+ /**
+ * Returns the minimum number of occurrences of the property within its
containing entity.
* This value is always an integer greater than or equal to zero.
+ *
+ * @return The minimum number of occurrences of the property within its
containing entity.
*/
public int getMinimumOccurs() {
- return 0;
+ return minimumOccurs;
}
/**
* The maximum number of occurrences of the property within its containing
entity.
- * This value is a positive integer. A value of {@link Integer#MAX_VALUE}
means that
- * the maximum number of occurrences is unbounded.
+ * A value of {@link Integer#MAX_VALUE} means that the maximum number of
occurrences is unbounded.
+ *
+ * @return The maximum number of occurrences of the property within its
containing entity,
+ * or {@link Integer#MAX_VALUE} if none.
*/
public int getMaximumOccurs() {
- return 1;
+ return maximumOccurs;
}
/**
- * The default value for the attribute.
- * This value is used when an attribute is created and no value for it is
specified.
+ * Returns a hash code value for this attribute type.
+ *
+ * @return {@inheritDoc}
*/
- public T getDefaultValue() {
- return defaultValue;
+ @Override
+ public int hashCode() {
+ return super.hashCode() + valueClass.hashCode() +
Objects.hashCode(valueDomain) +
+ 31*(Objects.hashCode(defaultValue) + 31*(minimumOccurs +
31*maximumOccurs));
+ }
+
+ /**
+ * Compares this attribute type with the given object for equality.
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (super.equals(obj)) {
+ final DefaultAttributeType<?> that = (DefaultAttributeType<?>) obj;
+ return valueClass == that.valueClass &&
+ minimumOccurs == that.minimumOccurs &&
+ maximumOccurs == that.maximumOccurs &&
+ Objects.equals(valueDomain, that.valueDomain) &&
+ Objects.equals(defaultValue, that.defaultValue);
+ }
+ return false;
}
}
Modified:
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java?rev=1574667&r1=1574666&r2=1574667&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] Wed Mar 5 21:21:46 2014
@@ -24,7 +24,7 @@ import org.opengis.util.GenericName;
* {@link DefaultFeature} instances of that type.
*
* <div class="note"><b>Note:</b>
- * Compared to the Java language, {@code FeatureType} is equivalent to {@link
Class} and
+ * Compared to the Java language, {@code FeatureType} is equivalent to {@link
Class} while
* {@code Feature} instances are equivalent to {@link Object} instances of
that class.</div>
*
* <div class="warning"><b>Warning:</b>
Modified:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java?rev=1574667&r1=1574666&r2=1574667&view=diff
==============================================================================
---
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
[UTF-8] (original)
+++
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelDataInput.java
[UTF-8] Wed Mar 5 21:21:46 2014
@@ -774,6 +774,8 @@ public class ChannelDataInput {
/**
* Returns a string representation of this object for debugging purpose.
+ *
+ * @return A string representation of this channel.
*/
@Debug
@Override