com.vaadin.hilla.signals.core.event.

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.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 

    Possible types of state events.

    static final class 

    The field names used in the JSON representation of the state event.

  • Constructor Summary

    Constructors
    Constructor
    Description
    StateEvent(com.fasterxml.jackson.databind.node.ObjectNode json, Class<T> valueType)

    Creates a new state event using the given JSON representation.

    StateEvent(String id, StateEvent.EventType eventType, T value)

    Creates a new state event using the given parameters.

    StateEvent(String id, StateEvent.EventType eventType, T value, T expected)

    Creates a new state event using the given parameters.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    static void
    clearValidationError(com.fasterxml.jackson.databind.node.ObjectNode event)
     
    static <X> X
    convertValue(com.fasterxml.jackson.databind.JsonNode rawValue, Class<X> valueType)
     
    boolean
     
    extractEventType(com.fasterxml.jackson.databind.JsonNode json)
     
    static com.fasterxml.jackson.databind.JsonNode
    extractExpected(com.fasterxml.jackson.databind.JsonNode json, boolean required)
     
    static String
    extractId(com.fasterxml.jackson.databind.JsonNode json)
     
    static String
    extractRawEventType(com.fasterxml.jackson.databind.JsonNode json)
     
    static String
    extractValidationError(com.fasterxml.jackson.databind.node.ObjectNode event)
     
    static com.fasterxml.jackson.databind.JsonNode
    extractValue(com.fasterxml.jackson.databind.JsonNode json, boolean required)
     

    Returns whether the event was accepted or not.

    Returns the type of the event.

    Returns the expected value of the event if exists.

    Returns the unique identifier of the event.

     

    Returns the value of the event.

    int
     
    static boolean
    isAccepted(com.fasterxml.jackson.databind.node.ObjectNode event)
     
    static boolean
    isRejected(com.fasterxml.jackson.databind.node.ObjectNode event)
     
    static boolean
    isReplaceEvent(com.fasterxml.jackson.databind.node.ObjectNode event)

    Checks if the given JSON object represents a REPLACE state event.

    static boolean
    isSetEvent(com.fasterxml.jackson.databind.node.ObjectNode event)

    Checks if the given JSON object represents a SET state event.

    void
    setAccepted(Boolean accepted)

    Sets whether the event was accepted or not.

    static void
    setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)

    Sets the object mapper to be used for serialization and deserialization of state events in Signal library.

    void
    setValidationError(String validationError)
     
    com.fasterxml.jackson.databind.node.ObjectNode

    Returns the JSON representation of the event.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • 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

    • setMapper

      public static void setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)

      Sets the object mapper to be used for serialization and deserialization of state events in Signal library.

      Parameters:

      mapper - The object mapper to be used for serialization and deserialization of state events.

    • convertValue

      public static <X> X convertValue(com.fasterxml.jackson.databind.JsonNode rawValue, Class<X> valueType)
    • extractId

      public static String extractId(com.fasterxml.jackson.databind.JsonNode json)
    • extractValue

      public static com.fasterxml.jackson.databind.JsonNode extractValue(com.fasterxml.jackson.databind.JsonNode json, boolean required)
    • extractExpected

      public static com.fasterxml.jackson.databind.JsonNode extractExpected(com.fasterxml.jackson.databind.JsonNode json, boolean required)
    • extractRawEventType

      public static String extractRawEventType(com.fasterxml.jackson.databind.JsonNode json)
    • extractEventType

      public static StateEvent.EventType extractEventType(com.fasterxml.jackson.databind.JsonNode json)
    • isSetEvent

      public static boolean isSetEvent(com.fasterxml.jackson.databind.node.ObjectNode event)

      Checks if the given JSON object represents a SET state event.

      Parameters:

      event - The JSON object to check.

      Returns:

      true if the given JSON object represents a SET state event, false otherwise.

      Throws:

      MissingFieldException - If the event does not contain the TYPE field.

      InvalidEventTypeException - If the event contains an invalid event type.

    • isReplaceEvent

      public static boolean isReplaceEvent(com.fasterxml.jackson.databind.node.ObjectNode event)

      Checks if the given JSON object represents a REPLACE state event.

      Parameters:

      event - The JSON object to check.

      Returns:

      true if the given JSON object represents a REPLACE state event, false otherwise.

      Throws:

      MissingFieldException - If the event does not contain the TYPE field.

      InvalidEventTypeException - If the event contains an invalid event type.

    • toJson

      public com.fasterxml.jackson.databind.node.ObjectNode toJson()

      Returns the JSON representation of the event.

      Returns:

      The JSON representation of the event.

    • isAccepted

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

      public static boolean isRejected(com.fasterxml.jackson.databind.node.ObjectNode event)
    • extractValidationError

      public static String extractValidationError(com.fasterxml.jackson.databind.node.ObjectNode event)
    • clearValidationError

      public static void clearValidationError(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.

    • getAccepted

      public Boolean getAccepted()

      Returns whether the event was accepted or not.

      Returns:

      whether the event was accepted or not.

    • setAccepted

      public void setAccepted(Boolean accepted)

      Sets whether the event was accepted or not.

      Parameters:

      accepted - whether the event was accepted or not.

    • equals

      public boolean equals(Object o)

      Overrides:

      equals in class Object

    • hashCode

      public int hashCode()

      Overrides:

      hashCode in class Object

    • getValidationError

      public String getValidationError()
    • setValidationError

      public void setValidationError(String validationError)
    • clearValidationError

      public void clearValidationError()