Class TypedIdKey<V>

java.lang.Object
org.jgrapes.core.TypedIdKey<V>
All Implemented Interfaces:
Serializable

public final class TypedIdKey<V> extends Object implements Serializable
Combines a type and an id value to a key for an Associator or Map.

This kind of key can be used if an instance of the type as key is too specific (or objects should not be kept alive only because they are used as keys) and the identifier alone cannot be guaranteed to be unique.

See Also:
  • Method Details

    • associate

      public static <V> V associate(Associator associator, Serializable id, V value)
      Associates the given value’s type and the id with the given value using the given associator.
      Type Parameters:
      V - the value type
      Parameters:
      associator - the associator
      id - the id
      value - the value
      Returns:
      the value for easy chaining
    • put

      public static <V> V put(Map<? super TypedIdKey<V>,? super V> map, Serializable id, V value)
      Associates the given value’s type and the id with the given value using the given map.
      Type Parameters:
      V - the value type
      Parameters:
      map - the map
      id - the id
      value - the value
      Returns:
      the value for easy chaining
    • associated

      public static <V> Optional<V> associated(Associator associator, Class<V> type, Serializable id)
      Retrieves a value with the given type and id from the given associator.
      Type Parameters:
      V - the value type
      Parameters:
      associator - the associator
      type - the type
      id - the id
      Returns:
      the associated value, if any
    • get

      public static <V> Optional<V> get(Map<?,?> map, Class<V> type, Serializable id)
      Retrieves a value with the given type and id from the given map.
      Type Parameters:
      V - the value type
      Parameters:
      map - the map
      type - the type
      id - the id
      Returns:
      the associated value, if any
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

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

      public String toString()
      Overrides:
      toString in class Object