Package com.adobe.granite.ui.components
Class State
- java.lang.Object
-
- com.adobe.granite.ui.components.State
-
public class State extends java.lang.Object
A key-value map of client-side state. A client may set a state such that the server can retrieve it to do something specific about this client based on the state.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
State.Item
An item in the state.
-
Constructor Summary
Constructors Constructor Description State(SlingHttpServletRequest request)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
get(java.lang.String name)
Returns the item value of the given name.boolean
get(java.lang.String name, boolean defaultValue)
Returns the item value of the given name.int
get(java.lang.String name, int defaultValue)
Returns the item value of the given name.java.lang.String
get(java.lang.String name, java.lang.String defaultValue)
Returns the item value of the given name.State.Item
getItem(java.lang.String name)
Returns the state item with the given name.java.util.Iterator<java.lang.String>
names()
Returns the available names.
-
-
-
Constructor Detail
-
State
public State(@Nonnull SlingHttpServletRequest request)
-
-
Method Detail
-
get
@CheckForNull public java.lang.String get(@Nonnull java.lang.String name)
Returns the item value of the given name. Returnsnull
if the item is not found.- Parameters:
name
- the name of the item- Returns:
- the item value as a string
-
get
@Nonnull public java.lang.String get(@Nonnull java.lang.String name, @Nonnull java.lang.String defaultValue)
Returns the item value of the given name. Returns the given defaultValue if the item is not found.- Parameters:
name
- the name of the itemdefaultValue
- the default value- Returns:
- the item value as a string or the default value if the item is not found
-
get
public boolean get(@Nonnull java.lang.String name, boolean defaultValue)
Returns the item value of the given name. Returns the given defaultValue if the item is not found, or the value is not a boolean string ("true" or "false").- Parameters:
name
- the name of the itemdefaultValue
- the default value- Returns:
- the item value as a boolean or the default value if the value is not a boolean string
-
get
public int get(@Nonnull java.lang.String name, int defaultValue)
Returns the item value of the given name. Returns the given defaultValue if the item is not found, or the value is not an integer string.- Parameters:
name
- the name of the itemdefaultValue
- the default value- Returns:
- the item value as an int or the default value if the value is not an int
-
names
@Nonnull public java.util.Iterator<java.lang.String> names()
Returns the available names.- Returns:
- the available names
-
getItem
@CheckForNull public State.Item getItem(@Nonnull java.lang.String name)
Returns the state item with the given name. Returnsnull
if the item is not found.- Parameters:
name
- the name of the item- Returns:
- the state item
-
-