Class KeyChain<T extends Keyed>

java.lang.Object
dev.wyck.keys.KeyChain<T>
Type Parameters:
T - the type of the items in the chain

@AsOf("2.4.0") public final class KeyChain<T extends Keyed> extends Object
A collection of items that can be accessed by their respective keys.
Since:
2.4.0
  • Method Details

    • get

      @AsOf("2.4.0") public @Nullable T get(Key key)
      Gets the item associated with the given key.
      Parameters:
      key - the key to get the item for
      Returns:
      the item associated with the given key, or null if not found
      Throws:
      IllegalArgumentException - if the item is not found
      Since:
      2.4.0
    • getOrThrow

      @AsOf("2.4.0") public T getOrThrow(Key key)
      Gets the item associated with the given key, or throws an exception if not found.
      Parameters:
      key - the key to get the item for
      Returns:
      the item associated with the given key
      Throws:
      IllegalArgumentException - if the item is not found
      Since:
      2.4.0
    • getLazily

      @AsOf("2.4.0") public Lazy<@Nullable T> getLazily(Key key)
      Gets the item associated with the given key, or returns a lazy that will return null if not found.
      Parameters:
      key - the key to get the item for
      Returns:
      a lazy that will return the item associated with the given key, or null if not found
      Since:
      2.4.0
    • getOrThrowLazily

      @AsOf("2.4.0") public Lazy<T> getOrThrowLazily(Key key)
      Gets the item associated with the given key, or throws an exception if not found.
      Parameters:
      key - the key to get the item for
      Returns:
      a lazy that will return the item associated with the given key
      Since:
      2.4.0
    • isRegistered

      @AsOf("2.4.0") public boolean isRegistered(Key key)
      Checks if the given key is registered.
      Parameters:
      key - the key to check
      Returns:
      true if the key is registered, false otherwise
      Since:
      2.4.0
    • isRegisteredLazily

      @AsOf("2.4.0") public Lazy<Boolean> isRegisteredLazily(Key key)
      Returns a lazy that will return true if the given key is registered, false otherwise.
      Parameters:
      key - the key to check
      Returns:
      a lazy that will return true if the given key is registered, false otherwise
      Since:
      2.4.0
    • iterator

      @AsOf("2.4.0") public Iterator<T> iterator()
      Returns an iterator over the items in the chain.
      Returns:
      an iterator over the items in the chain
      Since:
      2.4.0
    • size

      @AsOf("2.4.0") public int size()
      Returns the number of items in the chain.
      Returns:
      the number of items in the chain
      Since:
      2.4.0
    • isEmpty

      @AsOf("2.3.0") public boolean isEmpty()
      Returns true if the chain is empty.
      Returns:
      true if the chain is empty
      Since:
      2.4.0
    • items

      @AsOf("2.4.0") public Set<T> items()
      Returns a copy of the items in the chain.
      Returns:
      a copy of the items in the chain
      Since:
      2.4.0
    • append

      @AsOf("2.4.0") @Internal public void append(T item)
      Appends an item to the chain.
      Parameters:
      item - the item to append
      Since:
      2.4.0
    • replace

      @AsOf("2.4.0") @Internal public boolean replace(Key key, T item)
      Replaces an existing key in the chain with a new item.
      Parameters:
      key - the key of the item to replace
      item - the new item to replace the old one with
      Returns:
      true if the item was replaced, false otherwise
      Since:
      2.4.0
    • mutable

      @AsOf("2.4.0") public static <T extends Keyed> KeyChain<T> mutable()
      Creates a new mutable KeyChain.
      Type Parameters:
      T - the type of the items in the chain
      Returns:
      a new mutable KeyChain
      Since:
      2.4.0
    • immutable

      @AsOf("2.4.0") public static <T extends Keyed> KeyChain<T> immutable(Set<T> items)
      Creates a new immutable KeyChain.
      Type Parameters:
      T - the type of the items in the chain
      Parameters:
      items - the items to add to the chain
      Returns:
      a new immutable KeyChain
      Since:
      2.4.0