Class TypedFeature<T>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class TypedFeature<T>
    extends Feature<T>
    Class for holding values for typed features. These features are must be backed by a existing ClassAttributeAssignment. This way the feature type, its localization status and its number format is configured automatically.
    See Also:
    Serialized Form
    • Field Detail

      • CONVERT_TO_FEATUREUNIT

        public static final java.lang.String CONVERT_TO_FEATUREUNIT
        Session context option to switch off automatic number conversion when calling getValuesDirect(SessionContext).
         SessionContext ctx = jaloSession.createSessionContext();
         ctx.setAttribute(TypedFeature.CONVERT_TO_FEATUREUNIT, false);
        
         List<Number> numbersNotConverted = feat.getValuesDirect(ctx);
         
        See Also:
        Constant Field Values
    • Constructor Detail

      • TypedFeature

        protected TypedFeature​(FeatureContainer parent,
                               ClassAttributeAssignment assignment)
        Creates a new typed feature object.
        Parameters:
        parent - the container which this feature belongs to
        assignment - the assignment which backs this feature
      • TypedFeature

        protected TypedFeature​(TypedFeature<T> src)
                        throws java.lang.CloneNotSupportedException
        Clone constructor. Don't use directly!
        Parameters:
        src - the source feature
        Throws:
        java.lang.CloneNotSupportedException
    • Method Detail

      • clone

        public TypedFeature<T> clone()
                              throws java.lang.CloneNotSupportedException
        Specified by:
        clone in class Feature<T>
        Throws:
        java.lang.CloneNotSupportedException
      • getCode

        public java.lang.String getCode()
        Returns the classification attribute code of the associated ClassificationAttribute.
      • getClassAttributeAssignment

        public ClassAttributeAssignment getClassAttributeAssignment()
        Returns the assignment which backs this feature.
      • getClassificationAttribute

        public ClassificationAttribute getClassificationAttribute()
        Returns the classification attribute of the assignment which backs this feature.
      • getClassificationClass

        public ClassificationClass getClassificationClass()
        Returns the classification class of the assignment which backs this feature.
      • getUnit

        public ClassificationAttributeUnit getUnit()
        Returns the configured classification attribute unit of the assignment which backs this feature.
      • getSelectableValues

        public java.util.Collection<ClassificationAttributeValue> getSelectableValues()
        Returns all assignable values for this feature.
      • setSelectableValue

        public FeatureValue<T> setSelectableValue​(java.lang.String code)
        Convenience method for setting enumeration values without fetching them via getSelectableValue(String).
        Parameters:
        code - the code of the classification enumeration value to set as value
        Returns:
        the new or updated feature value instance
        Throws:
        JaloInvalidParameterException - if no such value exists for the underlying class attribute assignment
      • setSelectableValue

        public FeatureValue<T> setSelectableValue​(SessionContext ctx,
                                                  java.lang.String code)
        Convenience method for setting enumeration values without fetching them via getSelectableValue(String).
        Parameters:
        ctx - the session context to perform this operation within
        code - the code of the classification enumeration value to set as value
        Returns:
        the new or updated feature value instance
        Throws:
        JaloInvalidParameterException - if no such value exists for the underlying class attribute assignment
      • setSelectableValues

        public java.util.List<FeatureValue<T>> setSelectableValues​(java.lang.String... codes)
        Stores a list of classification enum values by specifying their code. This is a convenience method to avoid fetching all enum values via getSelectableValue(String) first.
        Parameters:
        codes - the list of enumeration value codes
        Returns:
        the newly created or update feature values
        Throws:
        JaloInvalidParameterException - if at least one value does not exists for the underlying class attribute assignment
      • setSelectableValues

        public java.util.List<FeatureValue<T>> setSelectableValues​(java.util.List<java.lang.String> codes)
        Stores a list of classification enum values by specifying their code. This is a convenience method to avoid fetching all enum values via getSelectableValue(String) first.
        Parameters:
        codes - the list of enumeration value codes
        Returns:
        the newly created or update feature values
        Throws:
        JaloInvalidParameterException - if at least one value does not exists for the underlying class attribute assignment
      • setSelectableValues

        public java.util.List<FeatureValue<T>> setSelectableValues​(SessionContext ctx,
                                                                   java.lang.String... codes)
        Stores a list of classification enum values by specifying their code. This is a convenience method to avoid fetching all enum values via getSelectableValue(String) first.
        Parameters:
        ctx - the session context to perform this operation within
        codes - the list of enumeration value codes
        Returns:
        the newly created or update feature values
        Throws:
        JaloInvalidParameterException - if at least one value does not exists for the underlying class attribute assignment
      • setSelectableValues

        public java.util.List<FeatureValue<T>> setSelectableValues​(SessionContext ctx,
                                                                   java.util.List<java.lang.String> codes)
        Stores a list of classification enum values by specifying their code. This is a convenience method to avoid fetching all enum values via getSelectableValue(String) first.
        Parameters:
        ctx - the session context to perform this operation within
        codes - the list of enumeration value codes
        Returns:
        the newly created or update feature values
        Throws:
        JaloInvalidParameterException - if at least one value does not exists for the underlying class attribute assignment
      • getUniqueKey

        protected java.lang.String getUniqueKey()
        Specified by:
        getUniqueKey in class Feature<T>
      • createValue

        public FeatureValue<T> createValue​(SessionContext ctx,
                                           int index,
                                           java.lang.Object value)
        Overridden to create a new value for this feature according to the configured value type.
        Specified by:
        createValue in class Feature<T>
        Parameters:
        ctx - the session context to define session language ( if feature is localized )
        index - the value index to insert new value at; -1 to append at the end
        value - the actual value to wrap inside the feature value object
        Returns:
        the new feature value object
      • createValue

        public FeatureValue<T> createValue​(SessionContext ctx,
                                           int index,
                                           java.lang.Object value,
                                           boolean typeSafe)
        Overridden to create a new value for this feature according to the configured value type.
        Parameters:
        ctx - the session context to define session language ( if feature is localized )
        index - the value index to insert new value at; -1 to append at the end
        value - the actual value to wrap inside the feature value object
        typeSafe - if true throws an error if given Object is not of correct type, else creates an feature value of type String
        Returns:
        the new feature value object
      • getValuesFormatted

        public java.lang.String getValuesFormatted​(SessionContext ctx)
        Overridden to format range features specially.
        Overrides:
        getValuesFormatted in class Feature<T>
        Parameters:
        ctx - the session context which defines the language to choose the value for
      • getValuesDirect

        public java.util.List<T> getValuesDirect​(SessionContext ctx)
        Overrides Feature.getValuesDirect(SessionContext) by converting all number values into the feature's ClassificationAttributeUnit.

        This can be controlled by using the CONVERT_TO_FEATUREUNIT session context attriute:

         SessionContext myCtx = jaloSession.createSessionContext();
         // to switch off automatic conversion:
         myCtx.setAttribute(TypedFeature.CONVERT_TO_FEATUREUNIT, Boolean.FALSE);
         List<Number> numbers = typedfeature.getValuesDirect(myCtx);
         
        Overrides:
        getValuesDirect in class Feature<T>
        Parameters:
        ctx - the session context defining the language to get values for