sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1751946 - in /sis/branches/JDK8/core/sis-feature/src: main/java/org/apache/sis/feature/ main/java/org/apache/sis/internal/feature/ test/java/org/apache/sis/internal/feature/
Date Fri, 08 Jul 2016 17:49:28 GMT
Author: desruisseaux
Date: Fri Jul  8 17:49:28 2016
New Revision: 1751946

URL: http://svn.apache.org/viewvc?rev=1751946&view=rev
Log:
Add getter methods for some of the builder properties.
Given the increase in amount of methods, make the Builder abstract class public (after renaming).

Added:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureElementBuilder.java
      - copied, changed from r1751945, sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Builder.java
Removed:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Builder.java
Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureTypeBuilder.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/FeatureTypeBuilderTest.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java?rev=1751946&r1=1751945&r2=1751946&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractIdentifiedType.java
[UTF-8] Fri Jul  8 17:49:28 2016
@@ -230,7 +230,7 @@ public class AbstractIdentifiedType impl
      * Returns a natural language designator for the element.
      * This can be used as an alternative to the {@linkplain #getName() name} in user interfaces.
      *
-     * @return Natural language designator for the element.
+     * @return Natural language designator for the element, or {@code null} if none.
      */
     @Override
     public InternationalString getDesignation() {

Copied: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureElementBuilder.java
(from r1751945, sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Builder.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureElementBuilder.java?p2=sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureElementBuilder.java&p1=sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Builder.java&r1=1751945&r2=1751946&rev=1751946&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Builder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureElementBuilder.java
[UTF-8] Fri Jul  8 17:49:28 2016
@@ -34,11 +34,7 @@ import org.opengis.feature.IdentifiedTyp
 
 
 /**
- * Base class of feature and attribute builders.
- * This base class provide the method needed for filling the {@code identification} map.
- *
- * @param <B> the builder subclass. It is subclass responsibility to ensure that {@code
this}
- *            is assignable to {@code <B>}; this {@code Builder} class can not verify
that.
+ * Base class of feature type, and attribute type, association role and characteristic builders.
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
@@ -46,7 +42,7 @@ import org.opengis.feature.IdentifiedTyp
  * @version 0.8
  * @module
  */
-abstract class Builder<B extends Builder<B>> implements Localized {
+public abstract class FeatureElementBuilder implements Localized {
     /**
      * The feature name, definition, designation and description.
      * The name is mandatory; all other information are optional.
@@ -56,7 +52,7 @@ abstract class Builder<B extends Builder
     /**
      * Creates a new builder initialized to the values of an existing type.
      */
-    Builder(final IdentifiedType template, final Locale locale) {
+    FeatureElementBuilder(final IdentifiedType template, final Locale locale) {
         putIfNonNull(Errors.LOCALE_KEY, locale);
         if (template != null) {
             putIfNonNull(AbstractIdentifiedType.NAME_KEY,        template.getName());
@@ -78,29 +74,6 @@ abstract class Builder<B extends Builder
     }
 
     /**
-     * If the object created by the last call to {@code build()} has been cached, clears
that cache.
-     */
-    abstract void clearCache();
-
-    /**
-     * Creates a generic name from the given scope and local part.
-     * An empty scope means no scope. A {@code null} scope means the
-     * {@linkplain FeatureTypeBuilder#setDefaultScope(String) default scope}.
-     *
-     * @param scope      the scope of the name to create, or {@code null} if the name is
local.
-     * @param localPart  the local part of the generic name (can not be {@code null}).
-     */
-    abstract GenericName name(String scope, String localPart);
-
-    /**
-     * Returns a default name to use if the user did not specified a name. The first letter
will be changed to
-     * lower case (unless the name looks like an acronym) for compliance with Java convention
on property names.
-     */
-    String getDefaultName() {
-        return null;
-    }
-
-    /**
      * Returns the map of properties to give to the {@code FeatureType} or {@code PropertyType}
constructor.
      * If the map does not contains a name, a default name may be generated.
      */
@@ -128,49 +101,51 @@ abstract class Builder<B extends Builder
     }
 
     /**
-     * Sets the name as a simple string with the default scope.
-     * The default scope is the value specified by the last call to
-     * {@link FeatureTypeBuilder#setDefaultScope(String)}.
+     * If the object created by the last call to {@code build()} has been cached, clears
that cache.
+     */
+    abstract void clearCache();
+
+    /**
+     * Creates a generic name from the given scope and local part.
+     * An empty scope means no scope. A {@code null} scope means the
+     * {@linkplain FeatureTypeBuilder#setDefaultScope(String) default scope}.
      *
-     * <p>The name will be an instance of {@link org.opengis.util.LocalName} if no
default scope
-     * has been specified, or an instance of {@link org.opengis.util.ScopedName} otherwise.</p>
+     * @param scope      the scope of the name to create, or {@code null} if the name is
local.
+     * @param localPart  the local part of the generic name (can not be {@code null}).
+     */
+    abstract GenericName name(String scope, String localPart);
+
+    /**
+     * Returns the name of the {@code IdentifiedType} to create, or {@code null} if undefined.
+     * This method returns the value built from the last call to a {@code setName(…)} method,
+     * or a default name or {@code null} if no name has been explicitely specified.
      *
-     * <p>This convenience method creates a {@link GenericName} instance,
-     * then delegates to {@link #setName(GenericName)}.</p>
+     * @return the name of the {@code IdentifiedType} to create (may be a default name or
{@code null}).
      *
-     * @param  localPart  the local part of the generic name (can not be {@code null}).
-     * @return {@code this} for allowing method calls chaining.
+     * @see AbstractIdentifiedType#getName()
      */
-    public B setName(final String localPart) {
-        ensureNonEmpty("localPart", localPart);
-        return setName(name(null, localPart));
+    public GenericName getName() {
+        return (GenericName) identification().get(AbstractIdentifiedType.NAME_KEY);
     }
 
     /**
-     * Sets the name as a string in the given scope.
-     * If a {@linkplain FeatureTypeBuilder#setDefaultScope(String) default scope} was specified,
-     * this method override it.
-     *
-     * <p>The name will be an instance of {@link org.opengis.util.LocalName} if the
given scope
-     * is {@code null} or empty, or an instance of {@link org.opengis.util.ScopedName} otherwise.</p>
-     *
-     * <p>This convenience method creates a {@link GenericName} instance,
-     * then delegates to {@link #setName(GenericName)}.</p>
-     *
-     * @param  scope      the scope of the name to create, or {@code null} if the name is
local.
-     * @param  localPart  the local part of the generic name (can not be {@code null}).
-     * @return {@code this} for allowing method calls chaining.
+     * Returns a default name to use if the user did not specified a name. The first letter
will be changed to
+     * lower case (unless the name looks like an acronym) for compliance with Java convention
on property names.
      */
-    public B setName(String scope, final String localPart) {
-        ensureNonEmpty("localPart", localPart);
-        if (scope == null) {
-            scope = "";                                 // For preventing the use of default
scope.
-        }
-        return setName(name(scope, localPart));
+    String getDefaultName() {
+        return null;
     }
 
     /**
-     * Sets the name as a generic name.
+     * Returns the name to use for displaying error messages.
+     */
+    final String getDisplayName() {
+        final GenericName name = getName();
+        return (name != null) ? name.toString() : Vocabulary.getResources(identification).getString(Vocabulary.Keys.Unnamed);
+    }
+
+    /**
+     * Sets the {@code IdentifiedType} name as a generic name.
      * If another name was defined before this method call, that previous value will be discarded.
      *
      * <div class="note"><b>Note for subclasses:</b>
@@ -180,34 +155,69 @@ abstract class Builder<B extends Builder
      * @param  name  the generic name (can not be {@code null}).
      * @return {@code this} for allowing method calls chaining.
      *
+     * @see #getName()
      * @see AbstractIdentifiedType#NAME_KEY
      */
-    @SuppressWarnings("unchecked")
-    public B setName(final GenericName name) {
+    public FeatureElementBuilder setName(final GenericName name) {
         ensureNonNull("name", name);
         if (!name.equals(identification.put(AbstractIdentifiedType.NAME_KEY, name))) {
             clearCache();
         }
-        return (B) this;
+        return this;
     }
 
     /**
-     * Returns the current name, or {@code null} if undefined.
-     * This method returns the value built from the last call to a {@code setName(…)} method,
-     * or a default name or {@code null} if no name has been explicitely specified.
+     * Sets the {@code IdentifiedType} name as a simple string with the default scope.
+     * The default scope is the value specified by the last call to {@link FeatureTypeBuilder#setDefaultScope(String)}.
+     * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local name}
if no default scope
+     * has been specified, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName scoped
name} otherwise.
+     *
+     * <p>This convenience method creates a {@link GenericName} instance,
+     * then delegates to {@link #setName(GenericName)}.</p>
+     *
+     * @param  localPart  the local part of the generic name (can not be {@code null}).
+     * @return {@code this} for allowing method calls chaining.
      *
-     * @return the current name (may be a default name or {@code null}).
+     * @see #getName()
      */
-    public GenericName getName() {
-        return (GenericName) identification().get(AbstractIdentifiedType.NAME_KEY);
+    public FeatureElementBuilder setName(final String localPart) {
+        ensureNonEmpty("localPart", localPart);
+        return setName(name(null, localPart));
     }
 
     /**
-     * Returns the name to use for displaying error messages.
+     * Sets the {@code IdentifiedType} name as a string in the given scope.
+     * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local name}
if the given scope is
+     * {@code null} or empty, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName
scoped name} otherwise.
+     * If a {@linkplain FeatureTypeBuilder#setDefaultScope(String) default scope} has been
specified, then the
+     * {@code scope} argument overrides it.
+     *
+     * <p>This convenience method creates a {@link GenericName} instance,
+     * then delegates to {@link #setName(GenericName)}.</p>
+     *
+     * @param  scope      the scope of the name to create, or {@code null} if the name is
local.
+     * @param  localPart  the local part of the generic name (can not be {@code null}).
+     * @return {@code this} for allowing method calls chaining.
+     *
+     * @see #getName()
      */
-    final String getDisplayName() {
-        final GenericName name = getName();
-        return (name != null) ? name.toString() : Vocabulary.getResources(identification).getString(Vocabulary.Keys.Unnamed);
+    public FeatureElementBuilder setName(String scope, final String localPart) {
+        ensureNonEmpty("localPart", localPart);
+        if (scope == null) {
+            scope = "";                                 // For preventing the use of default
scope.
+        }
+        return setName(name(scope, localPart));
+    }
+
+    /**
+     * Returns a concise definition of the element.
+     *
+     * @return concise definition of the element, or {@code null} if none.
+     *
+     * @see AbstractIdentifiedType#getDefinition()
+     */
+    public CharSequence getDefinition() {
+        return (CharSequence) identification.get(AbstractIdentifiedType.DEFINITION_KEY);
     }
 
     /**
@@ -216,14 +226,26 @@ abstract class Builder<B extends Builder
      * @param  definition a concise definition of the element, or {@code null} if none.
      * @return {@code this} for allowing method calls chaining.
      *
+     * @see #getDefinition()
      * @see AbstractIdentifiedType#DEFINITION_KEY
      */
-    @SuppressWarnings("unchecked")
-    public B setDefinition(final CharSequence definition) {
+    public FeatureElementBuilder setDefinition(final CharSequence definition) {
         if (!Objects.equals(definition, identification.put(AbstractIdentifiedType.DEFINITION_KEY,
definition))) {
             clearCache();
         }
-        return (B) this;
+        return this;
+    }
+
+    /**
+     * Returns a natural language designator for the element.
+     * This can be used as an alternative to the {@linkplain #getName() name} in user interfaces.
+     *
+     * @return natural language designator for the element, or {@code null} if none.
+     *
+     * @see AbstractIdentifiedType#getDesignation()
+     */
+    public CharSequence getDesignation() {
+        return (CharSequence) identification.get(AbstractIdentifiedType.DESIGNATION_KEY);
     }
 
     /**
@@ -233,14 +255,26 @@ abstract class Builder<B extends Builder
      * @param  designation a natural language designator for the element, or {@code null}
if none.
      * @return {@code this} for allowing method calls chaining.
      *
+     * @see #getDesignation()
      * @see AbstractIdentifiedType#DESIGNATION_KEY
      */
-    @SuppressWarnings("unchecked")
-    public B setDesignation(final CharSequence designation) {
+    public FeatureElementBuilder setDesignation(final CharSequence designation) {
         if (!Objects.equals(designation, identification.put(AbstractIdentifiedType.DESIGNATION_KEY,
designation))) {
             clearCache();
         }
-        return (B) this;
+        return this;
+    }
+
+    /**
+     * Returns optional information beyond that required for concise definition of the element.
+     * The description may assist in understanding the element scope and application.
+     *
+     * @return information beyond that required for concise definition of the element, or
{@code null} if none.
+     *
+     * @see AbstractIdentifiedType#getDescription()
+     */
+    public CharSequence getDescription() {
+        return (CharSequence) identification.get(AbstractIdentifiedType.DESCRIPTION_KEY);
     }
 
     /**
@@ -250,14 +284,14 @@ abstract class Builder<B extends Builder
      * @param  description  information beyond that required for concise definition of the
element, or {@code null} if none.
      * @return {@code this} for allowing method calls chaining.
      *
+     * @see #getDescription()
      * @see AbstractIdentifiedType#DESCRIPTION_KEY
      */
-    @SuppressWarnings("unchecked")
-    public B setDescription(final CharSequence description) {
+    public FeatureElementBuilder setDescription(final CharSequence description) {
         if (!Objects.equals(description, identification.put(AbstractIdentifiedType.DESCRIPTION_KEY,
description))) {
             clearCache();
         }
-        return (B) this;
+        return this;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureTypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureTypeBuilder.java?rev=1751946&r1=1751945&r2=1751946&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureTypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureTypeBuilder.java
[UTF-8] Fri Jul  8 17:49:28 2016
@@ -65,7 +65,7 @@ import org.opengis.feature.FeatureAssoci
  *
  * @see org.apache.sis.parameter.ParameterBuilder
  */
-public class FeatureTypeBuilder extends Builder<FeatureTypeBuilder> {
+public class FeatureTypeBuilder extends FeatureElementBuilder {
     /**
      * The factory to use for creating names.
      */
@@ -74,7 +74,7 @@ public class FeatureTypeBuilder extends
     /**
      * Builders for the properties (attributes, associations or operations) of this feature.
      */
-    private final List<Property<?>> properties;
+    private final List<Property> properties;
 
     /**
      * The parent of the feature to create. By default, new features have no parent.
@@ -83,12 +83,16 @@ public class FeatureTypeBuilder extends
 
     /**
      * Whether the feature type is abstract. The default value is {@code false}.
+     *
+     * @see #isAbstract()
+     * @see #setAbstract(boolean)
      */
     private boolean isAbstract;
 
     /**
      * The default scope to use when {@link #name(String, String)} is invoked with a null
scope.
      *
+     * @see #getDefaultScope()
      * @see #setDefaultScope(String)
      */
     private String defaultScope;
@@ -180,7 +184,7 @@ public class FeatureTypeBuilder extends
             isAbstract = template.isAbstract();
             superTypes.addAll(template.getSuperTypes());
             for (final PropertyType p : template.getProperties(false)) {
-                final Property<?> builder;
+                final Property builder;
                 if (p instanceof AttributeType<?>) {
                     builder = new Attribute<>(this, (AttributeType<?>) p);
                 } else if (p instanceof FeatureAssociationRole) {
@@ -194,7 +198,7 @@ public class FeatureTypeBuilder extends
     }
 
     /**
-     * If a {@code FeatureType} has been created by the last call to {@link #build()} has
been cached,
+     * If the {@code FeatureType} created by the last call to {@link #build()} has been cached,
      * clears that cache. This method must be invoked every time that a setter method is
invoked.
      */
     @Override
@@ -203,10 +207,22 @@ public class FeatureTypeBuilder extends
     }
 
     /**
-     * Sets whether the feature type is abstract.
+     * Returns {@code true} if the feature type to create will act as an abstract super-type.
+     * Abstract types can not be {@linkplain DefaultFeatureType#newInstance() instantiated}.
+     *
+     * @return {@code true} if the feature type to create will act as an abstract super-type.
+     *
+     * @see DefaultFeatureType#isAbstract()
+     */
+    public boolean isAbstract() {
+        return isAbstract;
+    }
+
+    /**
+     * Sets whether the feature type to create will be abstract.
      * If this method is not invoked, then the default value is {@code false}.
      *
-     * @param  isAbstract whether the feature type is abstract.
+     * @param  isAbstract whether the feature type will be abstract.
      * @return {@code this} for allowing method calls chaining.
      */
     public FeatureTypeBuilder setAbstract(final boolean isAbstract) {
@@ -218,6 +234,17 @@ public class FeatureTypeBuilder extends
     }
 
     /**
+     * Returns the direct parents of the feature type to create.
+     *
+     * @return the parents of the feature type to create, or an empty array if none.
+     *
+     * @see DefaultFeatureType#getSuperTypes()
+     */
+    public FeatureType[] getSuperTypes() {
+        return superTypes.toArray(new FeatureType[superTypes.size()]);
+    }
+
+    /**
      * Sets the parent types (or super-type) from which to inherit properties.
      * If this method is not invoked, then the default value is to have no parent.
      *
@@ -236,7 +263,82 @@ public class FeatureTypeBuilder extends
     }
 
     /**
-     * Sets the scope to use by default when {@link #setName(String)} is invoked.
+     * Sets the {@code FeatureType} name as a generic name.
+     * If another name was defined before this method call, that previous value will be discarded.
+     *
+     * <div class="note"><b>Note for subclasses:</b>
+     * all {@code setName(…)} convenience methods in this builder delegate to this method.
+     * Consequently this method can be used as a central place where to control the creation
of all names.</div>
+     *
+     * @return {@code this} for allowing method calls chaining.
+     */
+    @Override
+    public FeatureTypeBuilder setName(final GenericName name) {
+        super.setName(name);
+        return this;
+    }
+
+    /**
+     * Sets the {@code FeatureType} name as a simple string with the default scope.
+     * The default scope is the value specified by the last call to {@link #setDefaultScope(String)}.
+     * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local name}
if no default scope
+     * has been specified, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName scoped
name} otherwise.
+     *
+     * <p>This convenience method creates a {@link GenericName} instance,
+     * then delegates to {@link #setName(GenericName)}.</p>
+     *
+     * @return {@code this} for allowing method calls chaining.
+     */
+    @Override
+    public FeatureTypeBuilder setName(final String localPart) {
+        super.setName(localPart);
+        return this;
+    }
+
+    /**
+     * Sets the {@code FeatureType} name as a string in the given scope.
+     * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local name}
if the given scope is
+     * {@code null} or empty, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName
scoped name} otherwise.
+     * If a {@linkplain #setDefaultScope(String) default scope} has been specified, then
the
+     * {@code scope} argument overrides it.
+     *
+     * <p>This convenience method creates a {@link GenericName} instance,
+     * then delegates to {@link #setName(GenericName)}.</p>
+     *
+     * @return {@code this} for allowing method calls chaining.
+     */
+    @Override
+    public FeatureTypeBuilder setName(final String scope, final String localPart) {
+        super.setName(scope, localPart);
+        return this;
+    }
+
+    /**
+     * Invoked by {@link FeatureElementBuilder} for creating new {@code LocalName} or {@code
GenericName} instances.
+     */
+    @Override
+    final GenericName name(String scope, final String localPart) {
+        if (scope == null) {
+            scope = getDefaultScope();
+        }
+        if (scope == null || scope.isEmpty()) {
+            return nameFactory.createLocalName(null, localPart);
+        } else {
+            return nameFactory.createGenericName(null, scope, localPart);
+        }
+    }
+
+    /**
+     * Returns the scope of the names created by {@code setName(String)} method calls.
+     *
+     * @return the scope to use by default when {@link #setName(String)} is invoked.
+     */
+    public String getDefaultScope() {
+        return defaultScope;
+    }
+
+    /**
+     * Sets the scope of the names created by {@code setName(String)} method calls.
      *
      * @param  scope  the new default scope, or {@code null} if none.
      * @return {@code this} for allowing method calls chaining.
@@ -401,11 +503,8 @@ public class FeatureTypeBuilder extends
      *   <li>{@link FeatureTypeBuilder#addAssociation(FeatureType)}</li>
      *   <li>{@link FeatureTypeBuilder#addAssociation(GenericName)}</li>
      * </ul>
-     *
-     * @param <B> the property subclass. It is subclass responsibility to ensure that
{@code this}
-     *            is assignable to {@code <B>}; this {@code Property} class can not
verify that.
      */
-    static abstract class Property<B extends Property<B>> extends Builder<B>
{
+    public static abstract class Property extends FeatureElementBuilder {
         /**
          * The feature type builder instance that created this {@code Property} builder.
          *
@@ -463,7 +562,7 @@ public class FeatureTypeBuilder extends
          * @return {@code this} for allowing method calls chaining.
          */
         @SuppressWarnings("unchecked")
-        public B setCardinality(final int minimumOccurs, final int maximumOccurs) {
+        public Property setCardinality(final int minimumOccurs, final int maximumOccurs)
{
             if (this.minimumOccurs != minimumOccurs || this.maximumOccurs != maximumOccurs)
{
                 if (minimumOccurs < 0 || maximumOccurs < minimumOccurs) {
                     throw new IllegalArgumentException(errors().getString(Errors.Keys.IllegalRange_2,
minimumOccurs, maximumOccurs));
@@ -472,7 +571,7 @@ public class FeatureTypeBuilder extends
                 this.maximumOccurs = maximumOccurs;
                 clearCache();
             }
-            return (B) this;
+            return this;
         }
 
         /**
@@ -491,7 +590,7 @@ public class FeatureTypeBuilder extends
         }
 
         /**
-         * If a {@code PropertyType} has been created by the last call to {@link #build()}
has been cached,
+         * If the {@code PropertyType} created by the last call to {@link #build()} has been
cached,
          * clears that cache. This method must be invoked every time that a setter method
is invoked.
          */
         @Override
@@ -529,7 +628,7 @@ public class FeatureTypeBuilder extends
      * @see FeatureTypeBuilder#addAssociation(FeatureType)
      * @see FeatureTypeBuilder#addAssociation(GenericName)
      */
-    public static final class Association extends Property<Association> {
+    public static final class Association extends Property {
         /**
          * The target feature type, or {@code null} if unknown.
          */
@@ -566,6 +665,14 @@ public class FeatureTypeBuilder extends
         }
 
         /**
+         * Appends a text inside the value returned by {@link #toString()}, before the closing
bracket.
+         */
+        @Override
+        final void toStringInternal(final StringBuilder buffer) {
+            buffer.append(" → ").append(typeName);
+        }
+
+        /**
          * Returns a default name to use if the user did not specified a name. The first
letter will be changed to
          * lower case (unless the name looks like an acronym) for compliance with Java convention
on property names.
          */
@@ -575,11 +682,72 @@ public class FeatureTypeBuilder extends
         }
 
         /**
-         * Appends a text inside the value returned by {@link #toString()}, before the closing
bracket.
+         * Sets the {@code FeatureAssociationRole} name as a generic name.
+         * If another name was defined before this method call, that previous value will
be discarded.
+         *
+         * @return {@code this} for allowing method calls chaining.
          */
         @Override
-        final void toStringInternal(final StringBuilder buffer) {
-            buffer.append(" → ").append(typeName);
+        public Association setName(final GenericName name) {
+            super.setName(name);
+            return this;
+        }
+
+        /**
+         * Sets the {@code FeatureAssociationRole} name as a simple string with the default
scope.
+         * The default scope is the value specified by the last call to
+         * {@link FeatureTypeBuilder#setDefaultScope(String)}.
+         * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local
name} if no default scope
+         * has been specified, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName
scoped name} otherwise.
+         *
+         * @return {@code this} for allowing method calls chaining.
+         */
+        @Override
+        public Association setName(final String localPart) {
+            super.setName(localPart);
+            return this;
+        }
+
+        /**
+         * Sets the {@code FeatureAssociationRole} name as a string in the given scope.
+         * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local
name} if the given scope is
+         * {@code null} or empty, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName
scoped name} otherwise.
+         * If a {@linkplain FeatureTypeBuilder#setDefaultScope(String) default scope} has
been specified, then the
+         * {@code scope} argument overrides it.
+         *
+         * @return {@code this} for allowing method calls chaining.
+         */
+        @Override
+        public Association setName(final String scope, final String localPart) {
+            super.setName(scope, localPart);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Association setDefinition(final CharSequence definition) {
+            super.setDefinition(definition);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Association setDesignation(final CharSequence designation) {
+            super.setDesignation(designation);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Association setDescription(final CharSequence description) {
+            super.setDescription(description);
+            return this;
         }
 
         /**
@@ -607,7 +775,7 @@ public class FeatureTypeBuilder extends
      *
      * @see FeatureTypeBuilder#addAttribute(Class)
      */
-    public static final class Attribute<V> extends Property<Attribute<V>>
{
+    public static final class Attribute<V> extends Property {
         /**
          * The class of property values. Can not be changed after construction
          * because this value determines the parameterized type {@code <V>}.
@@ -671,6 +839,48 @@ public class FeatureTypeBuilder extends
         }
 
         /**
+         * Sets the {@code AttributeType} name as a generic name.
+         * If another name was defined before this method call, that previous value will
be discarded.
+         *
+         * @return {@code this} for allowing method calls chaining.
+         */
+        @Override
+        public Attribute<V> setName(final GenericName name) {
+            super.setName(name);
+            return this;
+        }
+
+        /**
+         * Sets the {@code AttributeType} name as a simple string with the default scope.
+         * The default scope is the value specified by the last call to
+         * {@link FeatureTypeBuilder#setDefaultScope(String)}.
+         * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local
name} if no default scope
+         * has been specified, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName
scoped name} otherwise.
+         *
+         * @return {@code this} for allowing method calls chaining.
+         */
+        @Override
+        public Attribute<V> setName(final String localPart) {
+            super.setName(localPart);
+            return this;
+        }
+
+        /**
+         * Sets the {@code AttributeType} name as a string in the given scope.
+         * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local
name} if the given scope is
+         * {@code null} or empty, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName
scoped name} otherwise.
+         * If a {@linkplain FeatureTypeBuilder#setDefaultScope(String) default scope} has
been specified, then the
+         * {@code scope} argument overrides it.
+         *
+         * @return {@code this} for allowing method calls chaining.
+         */
+        @Override
+        public Attribute<V> setName(final String scope, final String localPart) {
+            super.setName(scope, localPart);
+            return this;
+        }
+
+        /**
          * Sets the default value for the property.
          *
          * @param  value  default property value, or {@code null} if none.
@@ -883,6 +1093,33 @@ public class FeatureTypeBuilder extends
         }
 
         /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Attribute<V> setDefinition(final CharSequence definition) {
+            super.setDefinition(definition);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Attribute<V> setDesignation(final CharSequence designation) {
+            super.setDesignation(designation);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Attribute<V> setDescription(final CharSequence description) {
+            super.setDescription(description);
+            return this;
+        }
+
+        /**
          * Appends a text inside the value returned by {@link #toString()}, before the closing
bracket.
          */
         @Override
@@ -917,7 +1154,7 @@ public class FeatureTypeBuilder extends
      *
      * @param <V> the class of characteristic values.
      */
-    public static final class Characteristic<V> extends Builder<Characteristic<V>>
{
+    public static final class Characteristic<V> extends FeatureElementBuilder {
         /**
          * The attribute type builder instance that created this {@code Characteristic} builder.
          */
@@ -966,7 +1203,7 @@ public class FeatureTypeBuilder extends
         }
 
         /**
-         * If an {@code AttributeType<V>} has been created by the last call to {@link
#build()} has been cached,
+         * If the {@code AttributeType<V>} created by the last call to {@link #build()}
has been cached,
          * clears that cache. This method must be invoked every time that a setter method
is invoked.
          */
         @Override
@@ -985,6 +1222,48 @@ public class FeatureTypeBuilder extends
         }
 
         /**
+         * Sets the characteristic name as a generic name.
+         * If another name was defined before this method call, that previous value will
be discarded.
+         *
+         * @return {@code this} for allowing method calls chaining.
+         */
+        @Override
+        public Characteristic<V> setName(final GenericName name) {
+            super.setName(name);
+            return this;
+        }
+
+        /**
+         * Sets the characteristic name as a simple string with the default scope.
+         * The default scope is the value specified by the last call to
+         * {@link FeatureTypeBuilder#setDefaultScope(String)}.
+         * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local
name} if no default scope
+         * has been specified, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName
scoped name} otherwise.
+         *
+         * @return {@code this} for allowing method calls chaining.
+         */
+        @Override
+        public Characteristic<V> setName(final String localPart) {
+            super.setName(localPart);
+            return this;
+        }
+
+        /**
+         * Sets the characteristic name as a string in the given scope.
+         * The name will be a {@linkplain org.apache.sis.util.iso.DefaultLocalName local
name} if the given scope is
+         * {@code null} or empty, or a {@linkplain org.apache.sis.util.iso.DefaultScopedName
scoped name} otherwise.
+         * If a {@linkplain FeatureTypeBuilder#setDefaultScope(String) default scope} has
been specified, then the
+         * {@code scope} argument overrides it.
+         *
+         * @return {@code this} for allowing method calls chaining.
+         */
+        @Override
+        public Characteristic<V> setName(final String scope, final String localPart)
{
+            super.setName(scope, localPart);
+            return this;
+        }
+
+        /**
          * Delegates the creation of a new name to the enclosing builder.
          */
         @Override
@@ -1014,6 +1293,33 @@ public class FeatureTypeBuilder extends
         }
 
         /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Characteristic<V> setDefinition(final CharSequence definition) {
+            super.setDefinition(definition);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Characteristic<V> setDesignation(final CharSequence designation) {
+            super.setDesignation(designation);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Characteristic<V> setDescription(final CharSequence description) {
+            super.setDescription(description);
+            return this;
+        }
+
+        /**
          * Creates a new characteristic from the current setting.
          */
         final AttributeType<V> build() {
@@ -1028,6 +1334,33 @@ public class FeatureTypeBuilder extends
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public FeatureTypeBuilder setDefinition(final CharSequence definition) {
+        super.setDefinition(definition);
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public FeatureTypeBuilder setDesignation(final CharSequence designation) {
+        super.setDesignation(designation);
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public FeatureTypeBuilder setDescription(final CharSequence description) {
+        super.setDescription(description);
+        return this;
+    }
+
+    /**
      * Builds the feature type from the information and properties specified to this builder.
      * One of the {@code setName(…)} methods must have been invoked before this {@code
build()} method (mandatory).
      * All other methods are optional, but some calls to a {@code add} method are usually
needed.
@@ -1064,7 +1397,7 @@ public class FeatureTypeBuilder extends
             int propertyCursor = numSynthetic;
             int identifierCursor = 0;
             for (int i=0; i<numSpecified; i++) {
-                final Property<?>  builder = properties.get(i);
+                final Property     builder = properties.get(i);
                 final PropertyType instance = builder.build();
                 propertyTypes[propertyCursor] = instance;
                 /*
@@ -1124,7 +1457,7 @@ public class FeatureTypeBuilder extends
                             idDelimiter, idPrefix, idSuffix, identifierTypes);
                 }
             }
-            feature = new DefaultFeatureType(identification(), isAbstract,
+            feature = new DefaultFeatureType(identification(), isAbstract(),
                     superTypes.toArray(new FeatureType[superTypes.size()]),
                     ArraysExt.resize(propertyTypes, propertyCursor));
         }
@@ -1134,31 +1467,16 @@ public class FeatureTypeBuilder extends
     /**
      * Helper method for creating identification info of synthetic attributes.
      */
-    private static Map<String,?> name(final GenericName name) {
+    static Map<String,?> name(final GenericName name) {
         return Collections.singletonMap(AbstractOperation.NAME_KEY, name);
     }
 
     /**
-     * Invoked by {@link Builder} for creating new {@code LocalName} or {@code GenericName}
instances.
-     */
-    @Override
-    final GenericName name(String scope, final String localPart) {
-        if (scope == null) {
-            scope = defaultScope;
-        }
-        if (scope == null || scope.isEmpty()) {
-            return nameFactory.createLocalName(null, localPart);
-        } else {
-            return nameFactory.createGenericName(null, scope, localPart);
-        }
-    }
-
-    /**
      * Formats a string representation of this builder for debugging purpose.
      */
     @Override
     final void toStringInternal(final StringBuilder buffer) {
-        if (isAbstract) {
+        if (isAbstract()) {
             buffer.insert(buffer.indexOf("[") + 1, "abstract ");
         }
         String separator = " : ";
@@ -1168,7 +1486,7 @@ public class FeatureTypeBuilder extends
         }
         buffer.append(" {");
         separator = System.lineSeparator();
-        for (final Property<?> p : properties) {
+        for (final Property p : properties) {
             p.toString(buffer.append(separator).append("    ").append(p.getClass().getSimpleName()));
         }
         buffer.append(separator).append('}');

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/FeatureTypeBuilderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/FeatureTypeBuilderTest.java?rev=1751946&r1=1751945&r2=1751946&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/FeatureTypeBuilderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/FeatureTypeBuilderTest.java
[UTF-8] Fri Jul  8 17:49:28 2016
@@ -31,6 +31,7 @@ import org.opengis.feature.AttributeType
 import org.opengis.feature.FeatureType;
 import org.opengis.feature.PropertyType;
 import org.apache.sis.feature.DefaultFeatureTypeTest;
+import org.apache.sis.test.TestUtilities;
 
 
 /**
@@ -144,7 +145,7 @@ public final strictfp class FeatureTypeB
         builder.addAttribute(String .class).setName("name");
         builder.addAttribute(Integer.class).setName("age");
         builder.addAttribute(Point  .class).setName("location").setCRSCharacteristic(HardCodedCRS.WGS84);
-        builder.addAttribute(Double .class).setName("score").setCardinality(5, 50).setDefaultValue(10.0);
+        builder.addAttribute(Double .class).setName("score").setDefaultValue(10.0).setCardinality(5,
50);
 
         final FeatureType type = builder.build();
         assertEquals("name",        "myScope:myName",   type.getName().toString());
@@ -227,10 +228,13 @@ public final strictfp class FeatureTypeB
 
     /**
      * Tests creation of a builder from an existing feature type.
+     * This method also acts as a test of {@code FeatureTypeBuilder} getter methods.
      */
     @Test
     public void testCreateFromTemplate() {
         final FeatureTypeBuilder builder = new FeatureTypeBuilder(DefaultFeatureTypeTest.capital());
-        assertEquals("name", "Capital", builder.getName().toString());
+        assertEquals("name",       "Capital", builder.getName().toString());
+        assertEquals("superTypes", "City",    TestUtilities.getSingleton(builder.getSuperTypes()).getName().toString());
+        assertFalse ("isAbstract",            builder.isAbstract());
     }
 }




Mime
View raw message