org.finra.jtaf.core.commands.context
Class ManipulateContextHelper

java.lang.Object
  extended by org.finra.jtaf.core.commands.context.ManipulateContextHelper

public class ManipulateContextHelper
extends Object

Helper class used for context commands plan for context manipulation: action = {replace out with in|prepend in to out|append in to out} valuein indexin|keyin|null foreach = {value in list|key in map|value in map|int|null} change = {expand to singleton list|collapse list to set|expand set to map keys|convert map keys to set|convert set to list|convert map values to list} valueout indexout|keyout|null foreach = {value in list|key in map|value in map|int|null} change = {collapse list to set|expand set to map keys|convert map keys to set|convert set to list|convert map values to list


Field Summary
static String ACTION_ATTRIBUTE
           
static String APPEND_ACTION
           
static String CHANGE_IN_ATTRIBUTE
           
static String INDEX_IN_ATTRIBUTE
           
static String INDEX_OUT_ATTRIBUTE
           
static String KEY_IN_ATTRIBUTE
           
static String KEY_OUT_ATTRIBUTE
           
static String NONE_CHANGE
           
static String PREPEND_ACTION
           
static String REPLACE_ACTION
           
static String SINGLETON_CHANGE
           
static String VALUE_IN_ATTRIBUTE
           
static String VALUE_OUT_ATTRIBUTE
           
 
Constructor Summary
ManipulateContextHelper(AbstractContextCmd cmd, Map<?,?> globalCtx)
           
 
Method Summary
 boolean getBooleanOrDefault(String attributeName, boolean defaultValue)
          Like the above, except it returns a default value if the attribute is not set
 float getFloatOrDefault(String attributeName, float defaultValue)
          Like the above, except it returns a default value if the attribute is not set
 int getIntegerOrDefault(String attributeName, int defaultValue)
          Like the above, except it returns a default value if the attribute is not set
 Integer getOptionalInteger(String key)
          Returns an Integer stored in the context or null if there isn't one
 Object getOptionalObject(String key)
          Grabs an Object from the Context.
 String getOptionalString(String attributeName)
          Returns a String stored in the context or null if there isn't one
 boolean getRequiredBoolean(String attributeName)
          Returns a float stored in the context or throws a NullPointerException is one isn't
 float getRequiredFloat(String attributeName)
          Returns a float stored in the context or throws a NullPointerException is one isn't
 int getRequiredInteger(String attributeName)
          Returns an integer value, or throws a NullPointerException if the value is not present
 Object getRequiredObject(String key)
          Grabs an object from the Context, or throws an exception if the Object does not exist.
 String getRequiredString(String attributeName)
          Returns a String stored in the context or throws a NullPointerException is one isn't
 String getStringOrDefault(String attributeName, String defaultValue)
          Like the above, except it returns a default value if the attribute is not set
 Object getValueIn(String valueInAttribute, Integer index)
          Returns the value stored in a list in the context
 Object getValueIn(String valueInAttribute, Integer index, Object key)
          Returns the values stored in an object in the context
 Object getValueIn(String valueInAttribute, Object key)
          Returns the value stored in a map in the context
 String getVerifiedAction()
          Checks to make sure the current "action" in context is an acceptable value
 void setContext(IInvocationContext ctx)
          Sets a context to use instead of the global context provided in the constructor
 void setValueOut(String valueOutAttribute, List<Object> list, Object value)
          Appends an object to a list stored in the context
 void setValueOut(String valueOutAttribute, List<Object> list, Object value, int index)
          Stores a value in a list in the context
<T> void
setValueOut(String valueOutAttribute, List<T> list, List<T> value)
          Appends all the values of a list into another list that is stored in the context
<T> void
setValueOut(String valueOutAttribute, List<T> list, List<T> value, int index)
          Stores all the values of a list into another list that is stored in the context
<T,K> void
setValueOut(String valueOutAttribute, Map<? super K,? super T> list, T value, K key)
          Stores a value in a map stored in the context
 void setValueOut(String valueOutAttribute, Object value)
          Stored an object in the context
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_ATTRIBUTE

public static final String ACTION_ATTRIBUTE
See Also:
Constant Field Values

REPLACE_ACTION

public static final String REPLACE_ACTION
See Also:
Constant Field Values

PREPEND_ACTION

public static final String PREPEND_ACTION
See Also:
Constant Field Values

APPEND_ACTION

public static final String APPEND_ACTION
See Also:
Constant Field Values

VALUE_IN_ATTRIBUTE

public static final String VALUE_IN_ATTRIBUTE
See Also:
Constant Field Values

INDEX_IN_ATTRIBUTE

public static final String INDEX_IN_ATTRIBUTE
See Also:
Constant Field Values

KEY_IN_ATTRIBUTE

public static final String KEY_IN_ATTRIBUTE
See Also:
Constant Field Values

CHANGE_IN_ATTRIBUTE

public static final String CHANGE_IN_ATTRIBUTE
See Also:
Constant Field Values

SINGLETON_CHANGE

public static final String SINGLETON_CHANGE
See Also:
Constant Field Values

VALUE_OUT_ATTRIBUTE

public static final String VALUE_OUT_ATTRIBUTE
See Also:
Constant Field Values

INDEX_OUT_ATTRIBUTE

public static final String INDEX_OUT_ATTRIBUTE
See Also:
Constant Field Values

KEY_OUT_ATTRIBUTE

public static final String KEY_OUT_ATTRIBUTE
See Also:
Constant Field Values

NONE_CHANGE

public static final String NONE_CHANGE
See Also:
Constant Field Values
Constructor Detail

ManipulateContextHelper

public ManipulateContextHelper(AbstractContextCmd cmd,
                               Map<?,?> globalCtx)
Method Detail

setContext

public void setContext(IInvocationContext ctx)
Sets a context to use instead of the global context provided in the constructor

Parameters:
ctx - The context to use

getVerifiedAction

public String getVerifiedAction()
Checks to make sure the current "action" in context is an acceptable value

Returns:

getValueIn

public Object getValueIn(String valueInAttribute,
                         Integer index,
                         Object key)
Returns the values stored in an object in the context

Parameters:
valueInAttribute - The location of the object in the context
index - The index, if valueInAttribute refers to a list
key - The key if valueInAttribute refers to a map
Returns:

getValueIn

public Object getValueIn(String valueInAttribute,
                         Object key)
Returns the value stored in a map in the context

Parameters:
valueInAttribute - The location of the map in the context
key - the key in the map stored in the context where to retrieve the value
Returns:

getValueIn

public Object getValueIn(String valueInAttribute,
                         Integer index)
Returns the value stored in a list in the context

Parameters:
valueInAttribute - The location of the list in the context
index - The index in the list stored in the context from where to retrieve the value
Returns:

setValueOut

public void setValueOut(String valueOutAttribute,
                        List<Object> list,
                        Object value,
                        int index)
Stores a value in a list in the context

Parameters:
valueOutAttribute - Where to store the resulting list in the context
list - The list in which to store the value
value - The value to store in the list
index - The index in the list in which to store the value

setValueOut

public void setValueOut(String valueOutAttribute,
                        List<Object> list,
                        Object value)
Appends an object to a list stored in the context

Parameters:
valueOutAttribute - Where to store the resulting list in the context
list - The list in which to store the value
value - The value to store in the list

setValueOut

public <T> void setValueOut(String valueOutAttribute,
                            List<T> list,
                            List<T> value)
Appends all the values of a list into another list that is stored in the context

Parameters:
valueOutAttribute - Where to store the resulting list in the context
list - The list in which to store the values
value - The list of values being stored

setValueOut

public <T> void setValueOut(String valueOutAttribute,
                            List<T> list,
                            List<T> value,
                            int index)
Stores all the values of a list into another list that is stored in the context

Parameters:
valueOutAttribute - Where to store the resulting list in the context
list - The list in which to store the values
value - The list of values being stored
index - The index in the list in which to store the value

setValueOut

public <T,K> void setValueOut(String valueOutAttribute,
                              Map<? super K,? super T> list,
                              T value,
                              K key)
Stores a value in a map stored in the context

Parameters:
valueOutAttribute - Where to store the resulting map in the context
list - The map in which to store the values
value - The value being stored in the map
key - The key at which to store the value in the map

setValueOut

public void setValueOut(String valueOutAttribute,
                        Object value)
Stored an object in the context

Parameters:
valueOutAttribute - Where to store the object in the context
value - The object to store in the context

getOptionalObject

public Object getOptionalObject(String key)
Grabs an Object from the Context.

Parameters:
key -
Returns:

getRequiredObject

public Object getRequiredObject(String key)
Grabs an object from the Context, or throws an exception if the Object does not exist.

Parameters:
key -
Returns:

getRequiredInteger

public int getRequiredInteger(String attributeName)
Returns an integer value, or throws a NullPointerException if the value is not present

Parameters:
attributeName -
ctx -
Returns:

getIntegerOrDefault

public int getIntegerOrDefault(String attributeName,
                               int defaultValue)
Like the above, except it returns a default value if the attribute is not set

Parameters:
attributeName -
ctx -
defaultValue -
Returns:

getRequiredFloat

public float getRequiredFloat(String attributeName)
Returns a float stored in the context or throws a NullPointerException is one isn't

Parameters:
attributeName - Where in the context the float is stored
Returns:
The float stored in attributeName

getFloatOrDefault

public float getFloatOrDefault(String attributeName,
                               float defaultValue)
Like the above, except it returns a default value if the attribute is not set

Parameters:
attributeName - Where in the context the float is stored
defaultValue - The value to return if the context does not contain a value at attributeName
Returns:
The float stored in attributeName or defaultValue if one wasn't present

getRequiredString

public String getRequiredString(String attributeName)
Returns a String stored in the context or throws a NullPointerException is one isn't

Parameters:
attributeName - Where in the context the String is stored
Returns:
The String stored in attributeName

getStringOrDefault

public String getStringOrDefault(String attributeName,
                                 String defaultValue)
Like the above, except it returns a default value if the attribute is not set

Parameters:
attributeName - attributeName Where in the context the String is stored
defaultValue - The value to return if the context does not contain a value at attributeName
Returns:
The String stored in attributeName or defaultValue if one wasn't present

getOptionalString

public String getOptionalString(String attributeName)
Returns a String stored in the context or null if there isn't one

Parameters:
attributeName - Where in the context the String is stored
Returns:
The string stored in attributeName or null if there isn't one

getRequiredBoolean

public boolean getRequiredBoolean(String attributeName)
Returns a float stored in the context or throws a NullPointerException is one isn't

Parameters:
attributeName - Where in the context the boolean is stored
Returns:
The boolean stored in attributeName

getBooleanOrDefault

public boolean getBooleanOrDefault(String attributeName,
                                   boolean defaultValue)
Like the above, except it returns a default value if the attribute is not set

Parameters:
attributeName - Where in the context the boolean is stored
defaultValue - The value to return if the context does not contain a value at attributeName
Returns:
The boolean stored in attributeName or defaultValue if one wasn't present

getOptionalInteger

public Integer getOptionalInteger(String key)
Returns an Integer stored in the context or null if there isn't one

Parameters:
key - Where in the context the Integer is stored
Returns:
The string stored in key or null if there isn't one


Copyright © 2014. All rights reserved.