Class StateEvent<T>

java.lang.Object
com.vaadin.hilla.signals.core.event.StateEvent<T>
Type Parameters:
T - The type of the value of the event.

public class StateEvent<T> extends Object
A utility class for representing state events out of an ObjectNode. This helps to serialize and deserialize state events without getting involved with the string literals for field names and event types.
  • Constructor Details

    • StateEvent

      public StateEvent(String id, StateEvent.EventType eventType, T value, T expected)
      Creates a new state event using the given parameters.
      Parameters:
      id - The unique identifier of the event.
      eventType - The type of the event.
      value - The value of the event.
      expected - The expected value of the event before the change is applied.
    • StateEvent

      public StateEvent(String id, StateEvent.EventType eventType, T value)
      Creates a new state event using the given parameters.
      Parameters:
      id - The unique identifier of the event.
      eventType - The type of the event.
      value - The value of the event.
    • StateEvent

      public StateEvent(com.fasterxml.jackson.databind.node.ObjectNode json, Class<T> valueType)
      Creates a new state event using the given JSON representation.
      Parameters:
      json - The JSON representation of the event.
  • Method Details

    • toJson

      public com.fasterxml.jackson.databind.node.ObjectNode toJson()
      Returns the JSON representation of the event.
      Returns:
      The JSON representation of the event.
    • setAccepted

      public static com.fasterxml.jackson.databind.node.ObjectNode setAccepted(com.fasterxml.jackson.databind.node.ObjectNode event, boolean accepted)
    • isAccepted

      public static boolean isAccepted(com.fasterxml.jackson.databind.node.ObjectNode event)
    • getId

      public String getId()
      Returns the unique identifier of the event.
      Returns:
      The unique identifier of the event.
    • getEventType

      public StateEvent.EventType getEventType()
      Returns the type of the event.
      Returns:
      The type of the event.
    • getValue

      public T getValue()
      Returns the value of the event.
      Returns:
      The value of the event.
    • getExpected

      public T getExpected()
      Returns the expected value of the event if exists.
      Returns:
      The expected value of the event if exists.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object