Class SignalKey<T>

java.lang.Object
me.tamkungz.signals.SignalKey<T>
Type Parameters:
T - payload type

public final class SignalKey<T> extends Object
Identifies one signal channel: a payload type plus a name.

Keys with the same type and name address the same channel; derived keys created by Signal.filter(java.util.function.Predicate<T>) and Signal.map(java.lang.Class<R>, java.util.function.Function<T, R>) are always unique.

Primitive payload types are boxed, so int.class and Integer.class address the same channel and eventType() reports Integer.class for both.

  • Method Details

    • of

      public static <T> SignalKey<T> of(Class<T> eventType)
      Returns the default key of a payload type, the same as named(eventType, "default").
      Type Parameters:
      T - payload type
      Parameters:
      eventType - payload type
      Returns:
      the default key for the type
    • named

      public static <T> SignalKey<T> named(Class<T> eventType, String name)
      Returns the key of a named channel for a payload type.
      Type Parameters:
      T - payload type
      Parameters:
      eventType - payload type
      name - channel name
      Returns:
      the key for that type and name
    • eventType

      public Class<T> eventType()
      Returns the payload type, with primitives boxed.
      Returns:
      payload class
    • name

      public String name()
      Returns the channel name.
      Returns:
      channel name
    • cast

      public T cast(Object value)
      Casts a value to this key's payload type.
      Parameters:
      value - value to cast, may be null
      Returns:
      the value as T
      Throws:
      ClassCastException - if the value is not an instance of the payload type
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object