Author: desruisseaux
Date: Mon Mar 4 14:02:50 2013
New Revision: 1452310
URL: http://svn.apache.org/r1452310
Log:
Slight simplification of 'equals' and 'shallowCopy', fixing the boolean
parameter to the value commonly used.
Modified:
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
Modified:
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java?rev=1452310&r1=1452309&r2=1452310&view=diff
==============================================================================
---
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] Mon Mar 4 14:02:50 2013
@@ -17,7 +17,6 @@
package org.apache.sis.metadata;
import java.util.logging.Logger;
-import java.lang.reflect.Modifier;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.LenientComparable;
import org.apache.sis.util.logging.Logging;
@@ -90,24 +89,6 @@ public abstract class AbstractMetadata i
}
/**
- * Returns the class of the given metadata, ignoring SIS private classes
- * like {@link org.apache.sis.metadata.iso.citation.CitationConstant}.
- * This method does <strong>not</strong> ignores user's private classes,
- * only the SIS ones.
- *
- * @see <a href="http://jira.geotoolkit.org/browse/GEOTK-48">GEOTK-48</a>
- */
- private static Class<?> getPublicClass(final Object metadata) {
- Class<?> type = metadata.getClass();
- while (!Modifier.isPublic(type.getModifiers()) &&
- type.getName().startsWith(MetadataStandard.SIS_PACKAGE))
- {
- type = type.getSuperclass();
- }
- return type;
- }
-
- /**
* Compares this metadata with the specified object for equality. The
default
* implementation uses Java reflection. Subclasses may override this method
* for better performances, or for comparing "hidden" attributes not
specified
@@ -126,7 +107,7 @@ public abstract class AbstractMetadata i
return false;
}
if (mode == ComparisonMode.STRICT) {
- if (getPublicClass(object) != getPublicClass(this)) {
+ if (object.getClass() != getClass()) {
return false;
}
}
Modified:
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java?rev=1452310&r1=1452309&r2=1452310&view=diff
==============================================================================
---
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] Mon Mar 4 14:02:50 2013
@@ -419,9 +419,11 @@ public class MetadataStandard {
* Copies all metadata from source to target.
* The source must implements the same metadata interface than the target.
*
+ * <p>If the source contains any null or empty properties, then those
properties will
+ * <strong>not</strong> overwrite the corresponding properties in the
destination metadata.</p>
+ *
* @param source The metadata to copy.
* @param target The target metadata.
- * @param skipNulls If {@code true}, only non-null values will be copied.
* @throws ClassCastException if the source or target object don't
* implements a metadata interface of the expected package.
* @throws UnmodifiableMetadataException if the target metadata is
unmodifiable,
@@ -429,7 +431,7 @@ public class MetadataStandard {
*
* @see ModifiableMetadata#clone()
*/
- public void shallowCopy(final Object source, final Object target, final
boolean skipNulls)
+ public void shallowCopy(final Object source, final Object target)
throws ClassCastException, UnmodifiableMetadataException
{
ensureNonNull("target", target);
@@ -439,7 +441,7 @@ public class MetadataStandard {
throw new
ClassCastException(Errors.format(Errors.Keys.IllegalArgumentClass_3,
"source", accessor.type, source.getClass()));
}
- if (!accessor.shallowCopy(source, target, skipNulls)) {
+ if (!accessor.shallowCopy(source, target)) {
throw new
UnmodifiableMetadataException(Errors.format(Errors.Keys.UnmodifiableMetadata));
}
}
@@ -480,7 +482,7 @@ public class MetadataStandard {
if (accessor.type != findInterface(metadata2.getClass())) {
return false;
}
- return accessor.equals(metadata1, metadata2, mode, false);
+ return accessor.equals(metadata1, metadata2, mode);
}
/**
Modified:
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1452310&r1=1452309&r2=1452310&view=diff
==============================================================================
---
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] Mon Mar 4 14:02:50 2013
@@ -63,7 +63,7 @@ import static org.apache.sis.internal.ut
* <li>The standard properties defined by the GeoAPI (or other standard)
interfaces.
* Those properties are the only one accessible by most methods in this
class,
* except {@link #equals(Object, Object, ComparisonMode, boolean)},
- * {@link #shallowCopy(Object, Object, boolean)} and {@link
#freeze(Object)}.</li>
+ * {@link #shallowCopy(Object, Object)} and {@link #freeze(Object)}.</li>
*
* <li>Extra properties defined by the {@link IdentifiedObject} interface.
Those properties
* invisible in the ISO 19115 model, but appears in ISO 19139 XML
marshalling. So we do
@@ -953,44 +953,34 @@ final class PropertyAccessor {
* method without explicit calls to this {@code accessor.equals(…)} method
for children.
* However the final result may still be a deep comparison.
*
- * <p>This method can optionally excludes null values from the comparison.
In metadata,
- * null value often means "don't know", so in some occasions we want to
consider two
- * metadata as different only if a property value is know for sure to be
different.</p>
- *
* @param metadata1 The first metadata object to compare. This object
determines the accessor.
* @param metadata2 The second metadata object to compare.
* @param mode The strictness level of the comparison.
- * @param skipNulls If {@code true}, only non-null values will be
compared.
* @throws BackingStoreException If the implementation threw a checked
exception.
*
- * @see MetadataStandard#equals(Object, Object, ComparisonMode, boolean)
- *
- * @todo The semantic of the <code>skipNulls</code> argument should be
revisited
- * in order to provide a behavior more like a
<code>contains(Object)</code> method.
+ * @see MetadataStandard#equals(Object, Object, ComparisonMode)
*/
- public boolean equals(final Object metadata1, final Object metadata2,
- final ComparisonMode mode, final boolean skipNulls) throws
BackingStoreException
+ public boolean equals(final Object metadata1, final Object metadata2,
final ComparisonMode mode)
+ throws BackingStoreException
{
assert type.isInstance(metadata1) : metadata1;
assert type.isInstance(metadata2) : metadata2;
final int count = (mode == ComparisonMode.STRICT &&
EXTRA_GETTER.getDeclaringClass().isInstance(metadata2)) ?
allCount : standardCount;
for (int i=0; i<count; i++) {
- final Method method = getters[i];
- final Object value1 = get(method, metadata1);
- final Object value2 = get(method, metadata2);
- final boolean empty1 = isNullOrEmpty(value1);
- final boolean empty2 = isNullOrEmpty(value2);
- if (empty1 && empty2) {
+ final Method method = getters[i];
+ final Object value1 = get(method, metadata1);
+ final Object value2 = get(method, metadata2);
+ if (isNullOrEmpty(value1) && isNullOrEmpty(value2)) {
+ // Consider empty collections/arrays as equal to null.
+ // Empty strings are also considered equal to null (this is
more questionable).
continue;
}
if (!Utilities.deepEquals(value1, value2, mode)) {
if (mode.ordinal() >= ComparisonMode.APPROXIMATIVE.ordinal()
&& floatEpsilonEqual(value1, value2)) {
continue; // Accept this slight difference.
}
- if (!skipNulls || (!empty1 && !empty2)) {
- return false;
- }
+ return false;
}
}
return true;
@@ -1000,19 +990,17 @@ final class PropertyAccessor {
* Copies all non-empty metadata from source to target. The source can be
any implementation
* of the metadata interface, but the target must be the implementation
expected by this class.
*
- * <p>If {@code skipNulls} is {@code true} and the source contains any
null or empty properties,
- * then those properties will <strong>not</strong> overwrite the
corresponding properties in the
- * destination metadata.</p>
+ * <p>If the source contains any null or empty properties, then those
properties will
+ * <strong>not</strong> overwrite the corresponding properties in the
destination metadata.</p>
*
* @param source The metadata to copy.
* @param target The target metadata.
- * @param skipNulls If {@code true}, only non-null values will be copied.
* @return {@code true} in case of success, or {@code false} if at least
* one setter method was not found.
* @throws UnmodifiableMetadataException if the target metadata is
unmodifiable.
* @throws BackingStoreException If the implementation threw a checked
exception.
*/
- public boolean shallowCopy(final Object source, final Object target, final
boolean skipNulls)
+ public boolean shallowCopy(final Object source, final Object target)
throws UnmodifiableMetadataException, BackingStoreException
{
// Because this PropertyAccesssor is designed for the target, we must
@@ -1024,7 +1012,7 @@ final class PropertyAccessor {
for (int i=0; i<standardCount; i++) {
final Method getter = getters[i];
arguments[0] = get(getter, source);
- if (!skipNulls || !isNullOrEmpty(arguments[0])) {
+ if (!isNullOrEmpty(arguments[0])) {
if (setters == null) {
return false;
}
@@ -1122,9 +1110,9 @@ final class PropertyAccessor {
*/
static boolean isNullOrEmpty(final Object value) {
return value == null
- || ((value instanceof CharSequence) &&
CharSequences.trimWhitespaces((CharSequence) value).length() == 0)
+ || ((value instanceof CharSequence) && ((CharSequence)
value).length() == 0)
|| ((value instanceof Collection<?>) && ((Collection<?>)
value).isEmpty())
- || ((value instanceof Map<?,?>) && ((Map<?,?>)
value).isEmpty())
- || (value.getClass().isArray() && Array.getLength(value) == 0);
+ || ((value instanceof Map<?,?>) && ((Map<?,?>)
value).isEmpty())
+ || (value.getClass().isArray() && Array.getLength(value)
== 0);
}
}