com.vaadin.hilla.signals.core.event.
Class StateEvent<T>
Type Parameters:
T
- The type of the value of the event.
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 ClassesModifier and TypeClassDescriptionstatic enum
Possible types of state events.
static final class
The field names used in the JSON representation of the state event.
-
Constructor Summary
ConstructorsConstructorDescriptionStateEvent
(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 TypeMethodDescriptionvoid
static void
clearValidationError
(com.fasterxml.jackson.databind.node.ObjectNode event) static <X> X
convertValue
(com.fasterxml.jackson.databind.JsonNode rawValue, Class<X> valueType) boolean
static StateEvent.EventType
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.
getId()
Returns the unique identifier of the event.
getValue()
Returns the value of the event.
int
hashCode()
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
toJson()
Returns the JSON representation of the event.
-
Constructor Details
-
StateEvent
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
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
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
-
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
-
extractEventType
-
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
-
clearValidationError
public static void clearValidationError(com.fasterxml.jackson.databind.node.ObjectNode event) -
getId
Returns the unique identifier of the event.
Returns:
The unique identifier of the event.
-
getEventType
Returns the type of the event.
Returns:
The type of the event.
-
getValue
Returns the value of the event.
Returns:
The value of the event.
-
getExpected
Returns the expected value of the event if exists.
Returns:
The expected value of the event if exists.
-
getAccepted
Returns whether the event was accepted or not.
Returns:
whether the event was accepted or not.
-
setAccepted
Sets whether the event was accepted or not.
Parameters:
accepted
- whether the event was accepted or not. -
equals
-
hashCode
public int hashCode() -
getValidationError
-
setValidationError
-
clearValidationError
public void clearValidationError()
-