Class AttributeKey<T>

java.lang.Object
org.pepsoft.util.AttributeKey<T>
Type Parameters:
T - The value type of the attribute.
Direct Known Subclasses:
IntegerAttributeKey, LongAttributeKey, StringAttributeKey

public class AttributeKey<T> extends Object
A utility class for getting a typed attribute value with a default conveniently. This class is Serializable, but only if the concrete type of all the values is serializable!
  • Field Details

    • key

      public final String key
    • defaultValue

      public final T defaultValue
  • Constructor Details

    • AttributeKey

      public AttributeKey(String key)
    • AttributeKey

      public AttributeKey(String key, T defaultValue)
  • Method Details

    • getFromString

      public T getFromString(Map<String,String> values)
      Get a value for this attribute from a map of string to strings.
      Parameters:
      values - The map from which to get the value.
      Returns:
      The value of this attribute in the specified map, or the default value if the map does not contain the attribute.
    • get

      public T get(Map<String,?> values)
      Get a value for this attribute from a map of string to native value types.
      Parameters:
      values - The map from which to get the value.
      Returns:
      The value of this attribute in the specified map, or the default value if the map does not contain the attribute.
    • toString

      public String toString(T value)
      Convert an instance of AttributeKey to a string.
      Parameters:
      value - The value to convert. Will never be null.
      Returns:
      A string representation of the value.
    • toValue

      public T toValue(String str)
      Convert a string representation of AttributeKey to its native type.

      This implementation always throws an UnsupportedOperationException. Subclasses should override this method to implement it.

      Parameters:
      str - The string representation to convert. Will never be null.
      Returns:
      A corresponding instance of AttributeKey.
    • equals

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

      public final int hashCode()
      Overrides:
      hashCode in class Object