Class AttributeModel

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class AttributeModel
    extends java.lang.Object
    implements java.lang.Cloneable
    • Constructor Detail

      • AttributeModel

        public AttributeModel()
      • AttributeModel

        public AttributeModel​(java.util.Map<AttributeKey<?>,​java.lang.Object> attributes)
    • Method Detail

      • configure

        public static AttributeModel configure()
        Returns:
        factory method for builder template
      • configure

        public static AttributeModel configure​(AttributeModel template)
        Parameters:
        template - configure model by given filled model
        Returns:
        factory method for builder template
      • getAttribute

        public <T> T getAttribute​(AttributeKey<T> key)
        Returns an attribute of the plugin model
        Type Parameters:
        T - Type of the value
        Parameters:
        key - Key which identifies the attribute
        Returns:
        Attribute value or null if the attribute is not set
      • getRequiredAttribute

        public <T> T getRequiredAttribute​(AttributeKey<T> key)
        Returns an attribute value as required
        Type Parameters:
        T - Type of the value
        Parameters:
        key - Key which identifies the attribute
        Returns:
        Attribute value, null - throws IllegalArgumentException - required attributes
      • getAttribute

        public <T> T getAttribute​(AttributeKey<T> key,
                                  T defaultValue)
        Returns an attribute of the model
        Type Parameters:
        T - Type of the value
        Parameters:
        key - Key which identifies the attribute
        defaultValue - value is used, if the value doesn't exist
        Returns:
        Attribute value or default value if the attribute is not set
      • getAttributeAndSet

        public <T> T getAttributeAndSet​(AttributeKey<T> key,
                                        T defaultValue)
        Returns an attribute of the model, if it is not available - the default value is taken and automatically is set to the model!
        Type Parameters:
        T - Type of the value
        Parameters:
        key - Key which identifies the attribute
        defaultValue - value is used, if the value doesn't exist, and set to the instance model
        Returns:
        Attribute value or default value if the attribute is not set
      • getAttribute

        public <T,​E extends T> E getAttribute​(AttributeKey<T> key,
                                                    java.lang.Class<E> clazz)
        Returns an attribute of the plugin model
        Type Parameters:
        T - Type of the value
        E - retype to specific inherited class
        Parameters:
        key - Key which identifies the attribute
        clazz - specific class which will be used for casting
        Returns:
        Attribute value or default value if the attribute is not set
      • getAttribute

        public <T,​E extends T> E getAttribute​(AttributeKey<T> key,
                                                    java.lang.Class<E> clazz,
                                                    E defaultValue)
        Returns an attribute of the plugin model
        Type Parameters:
        T - Type of the value
        E - retype to specific inherited class
        Parameters:
        key - Key which identifies the attribute
        clazz - specific class which will be used for casting
        defaultValue - default value is used, if the value doesn't exist
        Returns:
        Attribute value or default value if the attribute is not set
      • setAttribute

        public <T> AttributeModel setAttribute​(AttributeKey<T> key,
                                               T value)
        Sets an attribute on the plugin model. The key must not be null. If a value is null, the attribute is removed, so containsAttribute method will return false after this operation.
        Type Parameters:
        T - Type of the value
        Parameters:
        key - Key which identifies the attribute
        value - Attribute value
        Returns:
        this instance, can be used for builder syntax
      • containsAttribute

        public boolean containsAttribute​(AttributeKey<?> key)
        Returns true if the plugin model contains an attribute specified by given key
        Parameters:
        key - Key which identifies the attribute
      • getAttributes

        public java.util.Set<AttributeKey<?>> getAttributes()
        Returns:
        provides all attribute keys in the model
      • merge

        public void merge​(AttributeModel model)
        Merge model to this actual model
        Parameters:
        model - AttributeModel
      • deepCopyAttributes

        public AttributeModel deepCopyAttributes()
        Returns:
        copy attributes model - deep copy of objects
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object