Package com.adobe.granite.ui.components
Class State
- java.lang.Object
-
- com.adobe.granite.ui.components.State
-
public class State extends 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 interfaceState.ItemAn 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 Stringget(String name)Returns the item value of the given name.booleanget(String name, boolean defaultValue)Returns the item value of the given name.intget(String name, int defaultValue)Returns the item value of the given name.Stringget(String name, String defaultValue)Returns the item value of the given name.State.ItemgetItem(String name)Returns the state item with the given name.Iterator<String>names()Returns the available names.
-
-
-
Constructor Detail
-
State
public State(@Nonnull SlingHttpServletRequest request)
-
-
Method Detail
-
get
@CheckForNull public String get(@Nonnull String name)
Returns the item value of the given name. Returnsnullif the item is not found.- Parameters:
name- the name of the item- Returns:
- the item value as a string
-
get
@Nonnull public String get(@Nonnull String name, @Nonnull 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 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 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 Iterator<String> names()
Returns the available names.- Returns:
- the available names
-
getItem
@CheckForNull public State.Item getItem(@Nonnull String name)
Returns the state item with the given name. Returnsnullif the item is not found.- Parameters:
name- the name of the item- Returns:
- the state item
-
-