Author: desruisseaux
Date: Fri Dec 13 04:28:09 2013
New Revision: 1550634
URL: http://svn.apache.org/r1550634
Log:
Allow ReferenceResolver to check for empty metadata.
Added:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Emptiable.java
(with props)
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ExcludedSet.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Localized.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ObjectConverters.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ReferenceResolver.java
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ExcludedSet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ExcludedSet.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ExcludedSet.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ExcludedSet.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -61,6 +61,8 @@ public final class ExcludedSet<E> extend
/**
* Returns {@code true} since this set is always empty.
+ *
+ * @return {@code true}
*/
@Override
public boolean isEmpty() {
@@ -69,6 +71,8 @@ public final class ExcludedSet<E> extend
/**
* Returns {@code 0} since this set is always empty.
+ *
+ * @return 0
*/
@Override
public int size() {
@@ -77,6 +81,8 @@ public final class ExcludedSet<E> extend
/**
* Returns the empty iterator.
+ *
+ * @return Empty iterator.
*/
@Override
public Iterator<E> iterator() {
@@ -86,6 +92,9 @@ public final class ExcludedSet<E> extend
/**
* Unconditionally throws a {@link UnsupportedOperationException} with a message
* saying which properties are mutually exclusive.
+ *
+ * @param e Ignored.
+ * @return Never return.
*/
@Override
public boolean add(final E e) {
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -19,6 +19,7 @@ package org.apache.sis.metadata;
import java.util.Map;
import java.util.logging.Logger;
import javax.xml.bind.annotation.XmlTransient;
+import org.apache.sis.util.Emptiable;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.LenientComparable;
import org.apache.sis.util.collection.TreeTable;
@@ -75,7 +76,7 @@ import org.apache.sis.util.logging.Loggi
* @see MetadataStandard
*/
@XmlTransient
-public abstract class AbstractMetadata implements LenientComparable {
+public abstract class AbstractMetadata implements LenientComparable, Emptiable {
/**
* The logger for messages related to metadata implementations.
*/
@@ -125,8 +126,7 @@ public abstract class AbstractMetadata i
* <li>An other metadata object containing only {@code null}, nil or empty properties.</li>
* </ul>
*
- * Note that empty properties can be removed by calling the {@link ModifiableMetadata#prune()}
- * method.
+ * Note that empty properties can be removed by calling the {@link ModifiableMetadata#prune()}
method.
*
* {@section Note for implementors}
* The default implementation uses Java reflection indirectly, by iterating over all
entries
@@ -139,6 +139,7 @@ public abstract class AbstractMetadata i
*
* @see org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox#isEmpty()
*/
+ @Override
public boolean isEmpty() {
return Pruner.isEmpty(this, false);
}
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/Pruner.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -20,6 +20,7 @@ import java.util.Map;
import java.util.Iterator;
import java.util.Collection;
import org.opengis.util.CodeList;
+import org.apache.sis.util.Emptiable;
import org.apache.sis.internal.util.CollectionsExt;
import static org.apache.sis.metadata.ValueExistencePolicy.*;
@@ -132,47 +133,58 @@ final class Pruner {
tested.put(value, Boolean.TRUE);
} else {
isEmpty = false;
+ if (!prune) break; // No need to continue if we are not pruning the metadata.
}
} else {
- boolean allEmpty = true;
+ /*
+ * At this point, 'value' is a new instance not yet processed by Pruner.
The value may
+ * be a data object or a collection. For convenience we will proceed as if
we had only
+ * collections, wrapping data object in a singleton collection if necessary.
+ */
+ boolean allElementsAreEmpty = true;
final Collection<?> values = CollectionsExt.toCollection(value);
for (final Iterator<?> it = values.iterator(); it.hasNext();) {
final Object element = it.next();
if (!isNullOrEmpty(element)) {
/*
- * If the value is not an empty "simple" property (null value, or
empty
- * string, or an empty collection or array), check if it is an other
- * metadata element. If so, invoke the isEmpty() method recursively.
+ * At this point, 'element' is not an empty CharSequence, Collection
or array.
+ * It may be an other metadata, a Java primitive type or user-defined
object.
+ *
+ * - For AbstractMetadata, delegate to the public API in case it
has been overriden.
+ * - For user-defined Emptiable, delegate to the user's isEmpty()
method. Note that
+ * we test at different times depending if 'prune' is true of
false.
*/
- final boolean e;
- if (element instanceof Enum<?> || element instanceof CodeList<?>)
{
- e = false;
- } else if (element instanceof AbstractMetadata) {
+ boolean isEmptyElement = false;
+ if (element instanceof AbstractMetadata) {
final AbstractMetadata md = (AbstractMetadata) element;
if (prune) md.prune();
- e = md.isEmpty();
- } else {
+ isEmptyElement = md.isEmpty();
+ } else if (!prune && element instanceof Emptiable) {
+ isEmptyElement = ((Emptiable) element).isEmpty();
+ // If 'prune' is true, we will rather test for Emptiable after
our pruning attempt.
+ } else if (!(element instanceof Enum<?>) && !(element
instanceof CodeList<?>)) {
final MetadataStandard standard = MetadataStandard.forClass(element.getClass());
if (standard != null) {
- e = isEmpty(asMap(standard, element, prune), tested, prune);
+ isEmptyElement = isEmpty(asMap(standard, element, prune),
tested, prune);
+ if (!isEmptyElement && element instanceof Emptiable)
{
+ isEmptyElement = ((Emptiable) element).isEmpty();
+ }
} else if (isPrimitive(entry)) {
if (value instanceof Number) {
- e = Double.isNaN(((Number) value).doubleValue());
+ isEmptyElement = Double.isNaN(((Number) value).doubleValue());
} else {
// Typically methods of the kind 'isFooAvailable()'.
- e = Boolean.FALSE.equals(value);
+ isEmptyElement = Boolean.FALSE.equals(value);
}
- } else {
- e = false; // Element is a String, Number (not primitive),
etc.
}
}
- if (!e) {
+ if (!isEmptyElement) {
// At this point, we have determined that the property is not
empty.
// If we are not removing empty nodes, there is no need to continue.
if (!prune) {
return false;
}
- allEmpty = false;
+ allElementsAreEmpty = false;
continue;
}
}
@@ -183,15 +195,14 @@ final class Pruner {
}
}
// If all elements were empty, set the whole property to 'null'.
- if (allEmpty) {
+ isEmpty &= allElementsAreEmpty;
+ if (allElementsAreEmpty) {
tested.put(value, Boolean.TRUE);
if (prune) try {
entry.setValue(null);
} catch (UnsupportedOperationException e) {
// Entry is read only - ignore.
}
- } else {
- isEmpty = false;
}
}
}
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -150,6 +150,11 @@ public enum ValueExistencePolicy {
* <p>This method intentionally does not inspect array or collection elements,
since this method
* is invoked from methods doing shallow copy or comparison. If we were inspecting elements,
* we would need to add a check against infinite recursivity.</p>
+ *
+ * <p>This method does not check for the {@link org.apache.sis.util.Emptiable}
interface because
+ * the {@code isEmpty()} method may be costly (for example {@link AbstractMetadata#isEmpty()}
+ * iterates over all the metadata tree). Instead, the check for {@code Emptiable} will
be done
+ * explicitely by the caller when appropriate.</p>
*/
static boolean isNullOrEmpty(final Object value) {
if (value == null) return true;
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -33,6 +33,7 @@ import org.opengis.referencing.crs.Coord
import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.RangeMeaning;
+import org.apache.sis.util.Emptiable;
import org.apache.sis.util.Utilities;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.resources.Errors;
@@ -111,7 +112,7 @@ import java.util.Objects;
* @version 0.3
* @module
*/
-public abstract class AbstractEnvelope implements Envelope {
+public abstract class AbstractEnvelope implements Envelope, Emptiable {
/**
* An empty array of envelopes, to be returned by {@link #toSimpleEnvelopes()}
* when en envelope is empty.
@@ -624,6 +625,7 @@ public abstract class AbstractEnvelope i
* @see org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox#isEmpty()
* @see java.awt.geom.Rectangle2D#isEmpty()
*/
+ @Override
public boolean isEmpty() {
final int dimension = getDimension();
if (dimension == 0) {
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -27,6 +27,7 @@ import org.opengis.referencing.cs.Coordi
import org.opengis.referencing.cs.AxisDirection;
import org.opengis.util.FactoryException;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.Emptiable;
import org.apache.sis.referencing.CRS;
import static java.lang.Double.NaN;
@@ -106,7 +107,7 @@ import java.util.Objects;
* @see GeneralEnvelope
* @see org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox
*/
-public class Envelope2D extends Rectangle2D.Double implements Envelope, Cloneable {
+public class Envelope2D extends Rectangle2D.Double implements Envelope, Emptiable, Cloneable
{
/**
* Serial number for inter-operability with different versions.
*/
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java [UTF-8]
Fri Dec 13 04:28:09 2013
@@ -24,6 +24,7 @@ import javax.measure.unit.Unit;
import org.apache.sis.internal.util.Utilities;
import org.apache.sis.util.collection.CheckedContainer;
import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.Emptiable;
import org.apache.sis.util.Immutable;
import org.apache.sis.util.Numbers;
@@ -87,7 +88,7 @@ import java.util.Objects;
* @see org.apache.sis.util.collection.RangeSet
*/
@Immutable
-public class Range<E extends Comparable<? super E>> implements CheckedContainer<E>,
Formattable, Serializable {
+public class Range<E extends Comparable<? super E>> implements CheckedContainer<E>,
Formattable, Emptiable, Serializable {
/**
* For cross-version compatibility.
*/
@@ -262,6 +263,7 @@ public class Range<E extends Comparable<
*
* @return {@code true} if this range is empty.
*/
+ @Override
public final boolean isEmpty() {
if (minValue == null || maxValue == null) {
return false; // Unbounded: can't be empty.
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -78,7 +78,7 @@ import org.apache.sis.util.resources.Err
* being checked. This programmatic name is used for building an error message localized
* in the {@linkplain java.util.Locale#getDefault() default locale} if the check failed.
*
- * @author Martin Desruisseaux (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.17)
* @version 0.4
* @module
Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Emptiable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Emptiable.java?rev=1550634&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Emptiable.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Emptiable.java [UTF-8]
Fri Dec 13 04:28:09 2013
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.util;
+
+
+/**
+ * Interface of classes for which empty instances may exist.
+ * This interface is typically used for filtering empty elements from a collection or a tree
of objects.
+ * Some examples of emptiable classes are:
+ *
+ * <ul>
+ * <li>{@link org.apache.sis.measure.Range} when the lower bounds is equals to the
upper bounds and at least
+ * one bound is exclusive.</li>
+ * <li>{@link org.apache.sis.metadata.AbstractMetadata} when no property value has
been given to the metadata,
+ * or all properties are themselves empty.</li>
+ * <li>{@link org.apache.sis.geometry.AbstractEnvelope} when the span, surface or
volume inside the envelope
+ * is zero.</li>
+ * </ul>
+ *
+ * SIS collections do <strong>not</strong> implement this interface even if they
provide a {@code isEmpty()} method,
+ * for consistency with collections in {@code java.util} and other libraries. This policy
avoid duplicated calls to
+ * {@code isEmpty()} methods when the caller need to check for both {@code Collection} and
{@code Emptiable} interfaces.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+public interface Emptiable {
+ /**
+ * Returns {@code true} if this instance is empty. The definition of "emptiness" may
vary between implementations.
+ * For example {@link org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox#isEmpty()}
returns {@code true}
+ * if all values are {@code NaN} (i.e. uninitialized) while {@link org.apache.sis.geometry.AbstractEnvelope#isEmpty()}
+ * returns {@code true} if the geometric surface is zero.
+ *
+ * @return {@code true} if this instance is empty, or {@code false} otherwise.
+ */
+ boolean isEmpty();
+}
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Emptiable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Emptiable.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -18,7 +18,7 @@ package org.apache.sis.util;
/**
- * Indicates that this object can be compared for equality using different levels of strictness.
+ * Interfaces of classes for which instances can be compared for equality using different
levels of strictness.
* For example {@link org.opengis.referencing.operation.MathTransform} implementations can
be
* compared ignoring some properties (remarks, <i>etc.</i>) that are not relevant
to the
* coordinates calculation.
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Localized.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Localized.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Localized.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Localized.java [UTF-8]
Fri Dec 13 04:28:09 2013
@@ -20,7 +20,8 @@ import java.util.Locale;
/**
- * Interface of localized services (parser, formatter, codes, …).
+ * Interface of classes for which each instance is configured for a particular locale.
+ * Those classes are often parsers or formatters.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.05)
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ObjectConverters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ObjectConverters.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ObjectConverters.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/ObjectConverters.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -24,7 +24,7 @@ import org.apache.sis.internal.converter
/**
- * Creates {@link ObjectConverter} instances, or uses them for creating collection views.
+ * Static methods for creating {@link ObjectConverter} instances or collection views based
on converters.
* Converters are created by the following methods:
*
* <ul>
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -255,6 +255,9 @@ public class Cache<K,V> extends Abstract
/**
* Returns {@code true} if this map contains the specified key.
+ *
+ * @param key The key to check for existence.
+ * @return {@code true} if the given key still exist in this cache.
*/
@Override
public boolean containsKey(final Object key) {
@@ -846,6 +849,8 @@ public class Cache<K,V> extends Abstract
/**
* Returns the set of keys in this cache. The returned set is subjects to the same caution
* than the ones documented in the {@link ConcurrentHashMap#keySet()} method.
+ *
+ * @return The set of keys in this cache.
*/
@Override
public Set<K> keySet() {
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ReferenceResolver.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ReferenceResolver.java?rev=1550634&r1=1550633&r2=1550634&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ReferenceResolver.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ReferenceResolver.java
[UTF-8] Fri Dec 13 04:28:09 2013
@@ -19,6 +19,7 @@ package org.apache.sis.xml;
import java.util.UUID;
import java.lang.reflect.Proxy;
import org.opengis.metadata.Identifier;
+import org.apache.sis.util.Emptiable;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.LenientComparable;
import org.apache.sis.internal.jaxb.gmx.Anchor;
@@ -38,7 +39,7 @@ import static org.apache.sis.util.Argume
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.18)
- * @version 0.3
+ * @version 0.4
* @module
*/
public class ReferenceResolver {
@@ -130,9 +131,13 @@ public class ReferenceResolver {
* SIS can not know if the metadata shall be fully marshalled or not.
* Such information needs to be provided by the application.
*
- * <p>The default implementation conservatively returns {@code false} in every
cases except for instances of
- * {@link NilObject}, since the later exist only for carrying the {@code gco} and {@code
xlink} attributes.
- * Subclasses can override this method if they know whether the receiver will be able
to resolve the reference.</p>
+ * <p>The default implementation returns {@code true} in the following cases:</p>
+ * <ul>
+ * <li>If {@code object} implements {@link NilObject}.</li>
+ * <li>If {@code object} implements {@link Emptiable} and its {@code isEmpty()}
method returns {@code true}.</li>
+ * </ul>
+ *
+ * Subclasses can override this method if they know whether the receiver will be able
to resolve the reference.
*
* @param <T> The compile-time type of the {@code type} argument.
* @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling
process.
@@ -144,7 +149,7 @@ public class ReferenceResolver {
* instead than marshalling the given metadata.
*/
public <T> boolean canSubstituteByReference(final MarshalContext context, final
Class<T> type, final T object, final UUID uuid) {
- return (object instanceof NilObject);
+ return (object instanceof NilObject) || (object instanceof Emptiable && ((Emptiable)
object).isEmpty());
}
/**
@@ -154,9 +159,13 @@ public class ReferenceResolver {
* SIS can not know if the metadata shall be fully marshalled or not.
* Such information needs to be provided by the application.
*
- * <p>The default implementation conservatively returns {@code false} in every
cases except for instances of
- * {@link NilObject}, since the later exist only for carrying the {@code gco} and {@code
xlink} attributes.
- * Subclasses can override this method if they know whether the receiver will be able
to resolve the reference.</p>
+ * <p>The default implementation returns {@code true} in the following cases:</p>
+ * <ul>
+ * <li>If {@code object} implements {@link NilObject}.</li>
+ * <li>If {@code object} implements {@link Emptiable} and its {@code isEmpty()}
method returns {@code true}.</li>
+ * </ul>
+ *
+ * Subclasses can override this method if they know whether the receiver will be able
to resolve the reference.
*
* @param <T> The compile-time type of the {@code type} argument.
* @param context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling
process.
@@ -168,7 +177,7 @@ public class ReferenceResolver {
* instead than marshalling the given metadata.
*/
public <T> boolean canSubstituteByReference(final MarshalContext context, final
Class<T> type, final T object, final XLink link) {
- return (object instanceof NilObject);
+ return (object instanceof NilObject) || (object instanceof Emptiable && ((Emptiable)
object).isEmpty());
}
/**
|