Class Attribute<V>

java.lang.Object
no.digipost.util.Attribute<V>
Type Parameters:
V - The type of the object this attribute is mapping.
All Implemented Interfaces:
Serializable, GetsNamedValue<V>, SetsNamedValue<V>

public final class Attribute<V> extends Object implements GetsNamedValue<V>, SetsNamedValue<V>, Serializable
An Attribute defines a String-based name (or key) and the type of a value which the name maps to. This construct offers pseudo-typesafe handling where objects of arbitrary types are retrieved by name and must be manually casted.
See Also:
  • Field Details

    • name

      public final String name
      The name of this attribute.
  • Constructor Details

    • Attribute

      public Attribute(String name)
  • Method Details

    • withName

      public Attribute<V> withName(String anotherName)
      Create a new attribute of the same type with another name.
      Parameters:
      anotherName - the name for the new attribute
      Returns:
      the new attribute instance. If the given name is equal to this attribute's name, the same instance is returned.
      See Also:
    • withValue

      public Tuple<Attribute<V>,V> withValue(V value)
      Bundle an attribute with an associated value in a Tuple.
      Parameters:
      value - the value to associate with the attribute
      Returns:
      a tuple containing the attribute and the value.
    • setOn

      public void setOn(BiConsumer<String,? super V> setter, V value)
      Specified by:
      setOn in interface SetsNamedValue<V>
    • getFrom

      public Optional<V> getFrom(Function<String,?> getter)
      Specified by:
      getFrom in interface GetsNamedValue<V>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object