StateUtil

StateUtil provides utility methods for managing and manipulating state properties in your application.

Integer Operations

inc(statePropertyId: String): Integer

  • Increment the value of an integer state property by 1.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

  • Returns: An Integer representing the updated value of the state property.

// Increment an integer state property
var incrementedValue = StateUtil.inc("counter");

dec(statePropertyId: String): Integer

  • Decrement the value of an integer state property by 1.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

  • Returns: An Integer representing the updated value of the state property.

// Decrement an integer state property
var decrementedValue = StateUtil.dec("counter");

plus(statePropertyId: String, delta: Integer): Integer

  • Add a specified value (delta) to an integer state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

    • delta (type: Integer) - The value to add.

  • Returns: An Integer representing the updated value of the state property.


counter(statePropertyId: String): Integer

  • Retrieve the current value of an integer state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

  • Returns:

    • An Integer representing the current value of the state property.


Integer and Long Property Access:

getInteger(statePropertyId: String): Integer

  • Retrieve the value of an integer state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

  • Returns:

    • An Integer representing the value of the state property.


setInteger(statePropertyId: String, value: Integer): void

  • Set the value of an integer state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

    • value (type: Integer) - The new value to set.


setLong(statePropertyId: String, value: Long): void

  • Set the value of a long state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

    • value (type: Long) - The new value to set.


getLong(statePropertyId: String): Long

  • Retrieve the value of a long state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

  • Returns:

    • A Long representing the value of the state property.


String Property Access:

getString(statePropertyId: String): String

  • Retrieve the value of a string state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

  • Returns:

    • A String representing the value of the state property.


setString(statePropertyId: String, value: String): void

  • Set the value of a string state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

    • value (type: String) - The new value to set.


JSON Property Access:

setJson(statePropertyId: String, value: JsonNode): void

  • Set the value of a JSON state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

    • value (type: JsonNode) - The new JSON value to set.


getJson(statePropertyId: String): JsonNode

  • Retrieve the value of a JSON state property.

  • Parameters:

    • statePropertyId (type: String) - The identifier of the state property.

  • Returns:

    • A JsonNode representing the JSON value of the state property.


Examples

Example: Managing Integer State Property (e.g., Count):

Example: Managing String State Property (e.g., User Name):

Example: Managing JSON State Property (e.g., User Data):

These examples demonstrate how the StateUtil methods can be used to manage and manipulate different types of state properties in your application, making it easy to work with integers, strings, and JSON data in a business context.

Was this helpful?