This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new aab8281 Add NamedIdentifier.castOrCopy(...) methods.
aab8281 is described below
commit aab8281634883051722d68974758cfb5de00f31b
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Thu Jun 21 16:51:10 2018 +0200
Add NamedIdentifier.castOrCopy(...) methods.
---
.../org/apache/sis/feature/CustomAttribute.java | 2 +-
.../sis/internal/jaxb/metadata/RS_Identifier.java | 11 +---
.../sis/metadata/iso/ImmutableIdentifier.java | 2 +
.../referencing/CC_GeneralOperationParameter.java | 2 +-
.../apache/sis/referencing/NamedIdentifier.java | 60 +++++++++++++++++++++-
5 files changed, 65 insertions(+), 12 deletions(-)
diff --git
a/core/sis-feature/src/test/java/org/apache/sis/feature/CustomAttribute.java
b/core/sis-feature/src/test/java/org/apache/sis/feature/CustomAttribute.java
index 4c399de..1e9183f 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/feature/CustomAttribute.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/feature/CustomAttribute.java
@@ -83,7 +83,7 @@ final strictfp class CustomAttribute<V> extends
AbstractAttribute<V> {
final DefaultDomainConsistency report = new
DefaultDomainConsistency();
final DefaultQuantitativeResult result = new
DefaultQuantitativeResult();
result.setErrorStatistic(new
SimpleInternationalString(ADDITIONAL_QUALITY_INFO));
- report.setMeasureIdentification(new NamedIdentifier(getName()));
+ report.setMeasureIdentification(NamedIdentifier.castOrCopy(getName()));
report .setResults(singleton(result));
quality.setReports(singleton(report));
return quality;
diff --git
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/RS_Identifier.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/RS_Identifier.java
index 152fefe..ed5f672 100644
---
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/RS_Identifier.java
+++
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/RS_Identifier.java
@@ -33,7 +33,7 @@ import org.apache.sis.internal.jaxb.gco.PropertyType;
* instead.
*
* @author Guilhem Legal (Geomatys)
- * @version 0.3
+ * @version 1.0
* @since 0.3
* @module
*/
@@ -84,14 +84,7 @@ public final class RS_Identifier extends
PropertyType<RS_Identifier, Identifier>
*/
@XmlElementRef
public ImmutableIdentifier getElement() {
- final Identifier metadata = this.metadata;
- if (metadata == null) {
- return null;
- } else if (metadata instanceof ImmutableIdentifier) {
- return (ImmutableIdentifier) metadata;
- } else {
- return new ImmutableIdentifier(metadata);
- }
+ return ImmutableIdentifier.castOrCopy(metadata);
}
/**
diff --git
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
index f372aaa..bb29cf4 100644
---
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
+++
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
@@ -188,6 +188,8 @@ public class ImmutableIdentifier extends FormattableObject
implements Identifier
* get the code, codespace, authority and version from the given
identifier.
*
* @param identifier the identifier to copy.
+ *
+ * @see #castOrCopy(Identifier)
*/
public ImmutableIdentifier(final Identifier identifier) {
ensureNonNull("identifier", identifier);
diff --git
a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
index 5c97eef..3085136 100644
---
a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
+++
b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
@@ -446,7 +446,7 @@ public final class CC_GeneralOperationParameter extends
PropertyType<CC_GeneralO
/**
* Given an {@link Identifier} or {@link GenericName} instance, returns
that instance as a {@link NamedIdentifier}
* implementation. The intent is to allow {@code Object.equals(Object)}
and hash code to correctly recognize two
- * name or identifier as equal even if they are of different
implementations.
+ * names or identifiers as equal even if they are of different
implementations.
*
* <p>Note that {@link NamedIdentifier} is the type of unmarshalled names,
aliases and identifiers.
* So this method should not create any new object in a majority of
cases.</p>
diff --git
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
index d2d2e16..2b07667 100644
---
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
+++
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
@@ -85,7 +85,7 @@ import org.apache.sis.util.ArgumentChecks;
* any public {@code NamedIdentifier} state.
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 0.7
+ * @version 1.0
*
* @see org.apache.sis.metadata.iso.DefaultIdentifier
* @see org.apache.sis.util.iso.AbstractName
@@ -121,6 +121,8 @@ public class NamedIdentifier extends ImmutableIdentifier
implements GenericName
* to that name.</p>
*
* @param identifier the identifier to copy.
+ *
+ * @see #castOrCopy(Identifier)
*/
public NamedIdentifier(final Identifier identifier) {
super(identifier);
@@ -136,6 +138,8 @@ public class NamedIdentifier extends ImmutableIdentifier
implements GenericName
* {@link #head()} and {@link #scope()} will delegate to the given name.
*
* @param name the name to wrap.
+ *
+ * @see #castOrCopy(GenericName)
*/
public NamedIdentifier(final GenericName name) {
super(name instanceof Identifier ? (Identifier) name : new
NameToIdentifier(name));
@@ -328,6 +332,60 @@ public class NamedIdentifier extends ImmutableIdentifier
implements GenericName
}
/**
+ * Returns a SIS identifier implementation with the values of the given
arbitrary implementation.
+ * This method performs the first applicable action in the following
choices:
+ *
+ * <ul>
+ * <li>If the given object is {@code null}, then this method returns
{@code null}.</li>
+ * <li>Otherwise if the given object is already an instance of
+ * {@code NamedIdentifier}, then it is returned unchanged.</li>
+ * <li>Otherwise a new {@code NamedIdentifier} instance is created using
the
+ * {@linkplain #NamedIdentifier(Identifier) copy constructor} and
returned.
+ * Note that this is a <cite>shallow</cite> copy operation, since
the other
+ * metadata contained in the given object are not recursively
copied.</li>
+ * </ul>
+ *
+ * @param object the object to get as a SIS implementation, or {@code
null} if none.
+ * @return a SIS implementation containing the values of the given object
(may be the
+ * given object itself), or {@code null} if the argument was null.
+ *
+ * @since 1.0
+ */
+ public static NamedIdentifier castOrCopy(final Identifier object) {
+ if (object == null || object instanceof NamedIdentifier) {
+ return (NamedIdentifier) object;
+ }
+ return new NamedIdentifier(object);
+ }
+
+ /**
+ * Returns a SIS name implementation with the values of the given
arbitrary implementation.
+ * This method performs the first applicable action in the following
choices:
+ *
+ * <ul>
+ * <li>If the given object is {@code null}, then this method returns
{@code null}.</li>
+ * <li>Otherwise if the given object is already an instance of
+ * {@code NamedIdentifier}, then it is returned unchanged.</li>
+ * <li>Otherwise a new {@code NamedIdentifier} instance is created using
the
+ * {@linkplain #NamedIdentifier(GenericName) copy constructor} and
returned.
+ * Note that this is a <cite>shallow</cite> copy operation, since
the other
+ * metadata contained in the given object are not recursively
copied.</li>
+ * </ul>
+ *
+ * @param object the object to get as a SIS implementation, or {@code
null} if none.
+ * @return a SIS implementation containing the values of the given object
(may be the
+ * given object itself), or {@code null} if the argument was null.
+ *
+ * @since 1.0
+ */
+ public static NamedIdentifier castOrCopy(final GenericName object) {
+ if (object == null || object instanceof NamedIdentifier) {
+ return (NamedIdentifier) object;
+ }
+ return new NamedIdentifier(object);
+ }
+
+ /**
* The last element in the sequence of {@linkplain #getParsedNames()
parsed names}.
* By default, this is the same value than the {@linkplain #getCode()
code} provided as a local name.
*