Class OrderedRegistry<T>

java.lang.Object
net.buildtheearth.terraminusminus.util.OrderedRegistry<T>

public final class OrderedRegistry<T> extends Object
A sort of "registry", in which entries are identified by a String key.

Entries maintain a strict order, and can be inserted/removed at either end of the registry, or at positions relative to each other.

Not thread-safe.

Inspired by Netty's ChannelPipeline.

Will probably be hoisted into PorkLib at some point.

  • Field Details

    • list

      protected final List<net.buildtheearth.terraminusminus.util.OrderedRegistry.Entry<T>> list
  • Constructor Details

    • OrderedRegistry

      public OrderedRegistry()
  • Method Details

    • addFirst

      public OrderedRegistry<T> addFirst(@NonNull @NonNull String name, @NonNull T value)
      Adds a new entry at the beginning of the registry.
      Parameters:
      name - the name
      value - the value
    • addLast

      public OrderedRegistry<T> addLast(@NonNull @NonNull String name, @NonNull T value)
      Adds a new entry at the end of the registry.
      Parameters:
      name - the name
      value - the value
    • addBefore

      public OrderedRegistry<T> addBefore(@NonNull @NonNull String targetName, @NonNull @NonNull String name, @NonNull T value)
      Adds a new entry immediately before the entry with the given name.
      Parameters:
      targetName - the name of the entry that the new entry should be inserted before
      name - the name
      value - the value
    • addAfter

      public OrderedRegistry<T> addAfter(@NonNull @NonNull String targetName, @NonNull @NonNull String name, @NonNull T value)
      Adds a new entry immediately before the entry with the given name.
      Parameters:
      targetName - the name of the entry that the new entry should be inserted before
      name - the name
      value - the value
    • set

      public OrderedRegistry<T> set(@NonNull @NonNull String targetName, @NonNull T value)
      Replaces the existing entry with the given name.
      Parameters:
      targetName - the name of the entry that the new entry should be inserted before
      value - the value
    • set

      public OrderedRegistry<T> set(@NonNull @NonNull String targetName, @NonNull @NonNull String newName, @NonNull T value)
      Replaces the existing entry with the given name.
      Parameters:
      targetName - the name of the entry that the new entry should be inserted before
      newName - the name
      value - the value
    • remove

      public OrderedRegistry<T> remove(@NonNull @NonNull String name)
      Removes the existing entry with the given name.
      Parameters:
      name - the name of the entry to remove
    • get

      public T get(@NonNull @NonNull String name)
      Removes the existing entry with the given name.
      Parameters:
      name - the name of the entry to remove
    • assertUniqueName

      protected void assertUniqueName(@NonNull @NonNull String name)
    • entryStream

      public Stream<Map.Entry<String,T>> entryStream()
      Returns:
      a Stream over all the entries in this registry
    • toString

      public String toString()
      Overrides:
      toString in class Object