Module gg.xp.xivapi

Class KeyedAlikeMapFactory<K>

java.lang.Object
gg.xp.xivapi.collections.KeyedAlikeMapFactory<K>
Type Parameters:
K - The key type.

public class KeyedAlikeMapFactory<K> extends Object
KeyedAlikeMapFactory is used to take a set of allowed keys, and produce many KeyedAlikeMap instances from it.

To use, specify your key set in the constructor. Then, use create() in either form to create a map instance. Every KeyedAlikeMap instance created by a KeyedAlikeMapFactory will share the same underlying map, and store the actual values in an array. This saves memory in a similar manner to Python's "slots".

See Also:
  • Constructor Details

    • KeyedAlikeMapFactory

      public KeyedAlikeMapFactory(Set<K> keys)
      Constructs a KeyedAlikeMapFactory for the given set of keys.

      Note that resulting maps will only be serializable if the keys are serializable.

      Parameters:
      keys - The set of all possible keys.
    • KeyedAlikeMapFactory

      public KeyedAlikeMapFactory(Set<K> keys, KeySerDe<K,?> serDe)
      Constructor that also accepts a serde helper, so that maps with non-serializable keys can still be serialized.
      Parameters:
      keys - The keys
      serDe - A helper to convert the keys to/from a serializable for
  • Method Details

    • create

      public <V> KeyedAlikeMap<K,V> create()
      Create an empty map
      Type Parameters:
      V - The type of values
      Returns:
      An empty map
    • create

      public <V> KeyedAlikeMap<K,V> create(Map<K,V> values)
      Create a map from the given values
      Type Parameters:
      V - The type of values
      Parameters:
      values - The initial values
      Returns:
      A map with the initial values
      Throws:
      IllegalArgumentException - when a key in the initial is not in the set of keys handled by this factory