Package no.digipost.util
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
AnAttribute
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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface no.digipost.util.GetsNamedValue
GetsNamedValue.NotFound
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Optional<V>
getFrom(Function<String,?> getter)
int
hashCode()
void
setOn(BiConsumer<String,? super V> setter, V value)
String
toString()
Attribute<V>
withName(String anotherName)
Create a new attribute of the same type with another name.Tuple<Attribute<V>,V>
withValue(V value)
Bundle an attribute with an associated value in aTuple
.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface no.digipost.util.GetsNamedValue
getFrom, requireFrom, requireFrom
-
Methods inherited from interface no.digipost.util.SetsNamedValue
setOn
-
-
-
-
Field Detail
-
name
public final String name
The name of this attribute.
-
-
Constructor Detail
-
Attribute
public Attribute(String name)
-
-
Method Detail
-
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:
name
-
withValue
public Tuple<Attribute<V>,V> withValue(V value)
Bundle an attribute with an associated value in aTuple
.- 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 interfaceSetsNamedValue<V>
-
getFrom
public Optional<V> getFrom(Function<String,?> getter)
- Specified by:
getFrom
in interfaceGetsNamedValue<V>
-
-