# Class Features

Object
Features

public final class Features extends Object
Static methods working on features or attributes.

Since:
  0.5

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <V> AbstractAttribute<V>`
  `cast(AbstractAttribute<?> attribute, Class<V> valueClass)`
  Casts the given attribute instance to the given parameterized type.
  `static <V> DefaultAttributeType<V>`
  `cast(DefaultAttributeType<?> type, Class<V> valueClass)`
  Casts the given attribute type to the given parameterized type.
  `static DefaultFeatureType`
  `findCommonParent(Iterable<? extends DefaultFeatureType> types)`
  Finds a feature type common to all given types, or returns `null` if none is found.
  `static Optional<String>`
  `getLinkTarget(AbstractIdentifiedType property)`
  If the given property is a link, returns the name of the referenced property.
  `static List<String>`
  `getLinkTargets(AbstractIdentifiedType property)`
  If the given property is a link or a compound key, returns the name of the referenced properties.
  `static List<String>`
  `getPropertyNames(DefaultFeatureType feature)`
  Returns the name of all properties (including inherited properties) of the given feature type.
  `static GenericName`
  `getValueTypeName(AbstractIdentifiedType property)`
  Returns the name of the type of values that the given property can take.
  `static Optional<DefaultAssociationRole>`
  `toAssociation(AbstractIdentifiedType type)`
  Returns the given type as a `FeatureAssociationRole` by casting if possible, or by getting the result type of an operation.
  `static Optional<DefaultAttributeType<?>>`
  `toAttribute(AbstractIdentifiedType type)`
  Returns the given type as an `AttributeType` by casting if possible, or by getting the result type of an operation.
  `static void`
  `validate(AbstractFeature feature)`
  Ensures that all characteristics and property values in the given feature are valid.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### cast

    public static <V> DefaultAttributeType<V> cast(DefaultAttributeType<?> type, Class<V> valueClass) throws ClassCastException
    Casts the given attribute type to the given parameterized type. An exception is thrown immediately if the given type does not have the expected value class.
    Type Parameters:
      `V` - the expected value class.
    Parameters:
      `type` - the attribute type to cast, or `null`.
      `valueClass` - the expected value class.
    Returns:
      the attribute type cast to the given value class, or `null` if the given type was null.
    Throws:
      `ClassCastException` - if the given attribute type does not have the expected value class.

  - ### cast

    public static <V> AbstractAttribute<V> cast(AbstractAttribute<?> attribute, Class<V> valueClass) throws ClassCastException
    Casts the given attribute instance to the given parameterized type. An exception is thrown immediately if the given instance does not have the expected value class.
    Type Parameters:
      `V` - the expected value class.
    Parameters:
      `attribute` - the attribute instance to cast, or `null`.
      `valueClass` - the expected value class.
    Returns:
      the attribute instance cast to the given value class, or `null` if the given instance was null.
    Throws:
      `ClassCastException` - if the given attribute instance does not have the expected value class.

  - ### toAttribute

    public static Optional<DefaultAttributeType<?>> toAttribute(AbstractIdentifiedType type)
    Returns the given type as an `AttributeType` by casting if possible, or by getting the result type of an operation. More specifically this method returns the first of the following types which apply:
    - If the given type is an instance of `AttributeType`, then it is returned as-is.
    - If the given type is an instance of `Operation` and the `Operation​.getResult() result type` is an `AttributeType`, then that result type is returned.
    - If the given type is an instance of `Operation` and the `Operation​.getResult() result type` is another operation, then the above check is performed recursively.
    Parameters:
      `type` - the data type to express as an attribute type, or `null`.
    Returns:
      the attribute type, or empty if this method cannot find any.
    Since:
      1.1

  - ### toAssociation

    public static Optional<DefaultAssociationRole> toAssociation(AbstractIdentifiedType type)
    Returns the given type as a `FeatureAssociationRole` by casting if possible, or by getting the result type of an operation. More specifically this method returns the first of the following types which apply:
    - If the given type is an instance of `FeatureAssociationRole`, then it is returned as-is.
    - If the given type is an instance of `Operation` and the `Operation​.getResult() result type` is an `FeatureAssociationRole`, then that result type is returned.
    - If the given type is an instance of `Operation` and the `Operation​.getResult() result type` is another operation, then the above check is performed recursively.
    Parameters:
      `type` - the data type to express as an attribute type, or `null`.
    Returns:
      the association role, or empty if this method cannot find any.
    Since:
      1.4

  - ### findCommonParent

    @OptionalCandidate public static DefaultFeatureType findCommonParent(Iterable<? extends DefaultFeatureType> types)
    Finds a feature type common to all given types, or returns `null` if none is found. The return value is either one of the given types, or a parent common to all types. A feature F is considered a common parent if `F.`isAssignableFrom`(type)` returns `true` for all elements type in the given array.
    Parameters:
      `types` - types for which to find a common type, or `null`.
    Returns:
      a feature type which is assignable from all given types, or `null` if none.
    Since:
      1.0
    See Also:
      - `DefaultFeatureType​.isAssignableFrom(DefaultFeatureType)`

  - ### getPropertyNames

    public static List<String> getPropertyNames(DefaultFeatureType feature)
    Returns the name of all properties (including inherited properties) of the given feature type.
    Parameters:
      `feature` - the feature type from which to get the name of all properties.
    Returns:
      name of all properties of the specified feature type.
    Since:
      1.6

  - ### getValueTypeName

    @OptionalCandidate public static GenericName getValueTypeName(AbstractIdentifiedType property)
    Returns the name of the type of values that the given property can take. The type of value can be a `Class`, a `FeatureType` or another `PropertyType` depending on given argument:
    - If `property` is an `AttributeType`, then this method gets the value class and maps that class to a name.
    - If `property` is a `FeatureAssociationRole`, then this method gets the name of the value type. This methods can work even if the associated `FeatureType` is not yet resolved.
    - If `property` is an `Operation`, then this method returns the name of the result type.
    Parameters:
      `property` - the property for which to get the name of value type.
    Returns:
      the name of value type, or `null` if none.
    Since:
      0.8

  - ### getLinkTarget

    public static Optional<String> getLinkTarget(AbstractIdentifiedType property)
    If the given property is a link, returns the name of the referenced property. A link is an operation created by a call to `FeatureOperations​.link(Map, PropertyType)`, in which case the value returned by this method is the name of the `PropertyType` argument which has been given to that `link(…)` method.
    Parameters:
      `property` - the property to test, or `null` if none.
    Returns:
      the referenced property name if `property` is a link, or an empty value otherwise.
    Since:
      1.1
    See Also:
      - `FeatureOperations​.link(Map, PropertyType)`

  - ### getLinkTargets

    public static List<String> getLinkTargets(AbstractIdentifiedType property)
    If the given property is a link or a compound key, returns the name of the referenced properties. This method is similar to `getLinkTarget(AbstractIdentifiedType)`, except that it recognizes also the operations created by `FeatureOperations​.compound(…)`.
    Parameters:
      `property` - the property to test, or `null` if none.
    Returns:
      the referenced property names if `property` is a link or a compound key, or an empty list otherwise.
    Since:
      1.5
    See Also:
      - `FeatureOperations​.compound(Map, String, String, String, AbstractIdentifiedType...)`

  - ### validate

    public static void validate(AbstractFeature feature) throws IllegalArgumentException
    Ensures that all characteristics and property values in the given feature are valid. An attribute is valid if it contains a number of values between the minimum and maximum number of occurrences (inclusive), all values are instances of the expected value class, and the attribute is compliant with any other restriction that the implementation may add.

    This method gets a quality report as documented in the `AbstractFeature​.quality()` method and verifies that all conformance tests pass. If at least one `ConformanceResult​.pass` attribute is false, then an `InvalidPropertyValueException` is thrown. Otherwise this method returns doing nothing.

    Parameters:
      `feature` - the feature to validate, or `null`.
    Throws:
      `IllegalArgumentException` - if the given feature is non-null and does not pass validation.
    Since:
      0.7