Package adams.flow.control
Class Storage
- java.lang.Object
-
- adams.flow.control.Storage
-
- All Implemented Interfaces:
CloneHandler<Storage>,Serializable
public class Storage extends Object implements Serializable, CloneHandler<Storage>
Used for temporary storage during flow execution.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringCHARSallowed characters.static StringENDthe end of a storage placeholder.protected HashMap<String,LRUCache<String,Object>>m_Cachesname LRU caches.protected Set<StorageChangeListener>m_ChangeListenersthe listeners.protected HashMap<String,Object>m_Datafor storing the data.static StringSTARTthe start of a storage placeholder.
-
Constructor Summary
Constructors Constructor Description Storage()Initializes the storage.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCache(String name, int size)Adds a LRU cache under the name with the specified size.voidaddChangeListener(StorageChangeListener l)Adds the change listener.voidassign(Storage other)Adds all the items from the other Storage object (overwrites any existing ones).voidassign(Storage other, BaseRegExp filter)Adds all the items from the other Storage object (overwrites any existing ones).Iterator<String>caches()Returns the names of the LRU caches currently available.voidclear()Empties the storage.protected StringdoExpand(String s)Expands storage placeholders.Stringexpand(String s)Replaces all storage placeholders in the string with the currently stored values.protected Stringexpand(String s, boolean recurse)Replaces all storage placeholders in the string with the currently stored values (ie string representation).Map<String,Object>get(BaseRegExp nameRegExp)Returns the objects associated with the regexp matching their name.Objectget(StorageName name)Returns the object associated with the name.Map<String,Object>get(String cache, BaseRegExp nameRegExp)Returns the objects associated with the regexp matching the names from the specified LRU cache.Objectget(String cache, StorageName name)Returns the object associated with the name from the named LRU cache.StoragegetClone()Returns a clone (deep copy) of the object.StoragegetClone(BaseRegExp filter)Returns a clone (deep copy) of the object.StoragegetShallowCopy()Returns a shallow copy of the object.booleanhas(StorageName name)Checks whether a value is stored under the given name.booleanhas(String cache, StorageName name)Checks whether a value is stored under the given name in the named LRU cache.protected voidinitChangeListeners()Initializes the change listeners.static booleanisValidName(String s)Checks whether the string represents a valid name.Set<StorageName>keySet()Returns the set of keys.Set<StorageName>keySet(String cache)Returns the set of keys from the named LRU cache.protected voidnotifyChangeListeners(StorageChangeEvent e)Notifies all listeners.Objectput(StorageName name, Object value)Adds the given value under the specified name.voidput(String cache, StorageName name, Object value)Adds the given value under the specified name to the named LRU cache.booleanremove(BaseRegExp regexp)Removes the object(s) which name(s) match the regular expression.Objectremove(StorageName name)Removes the object associated with the name.booleanremove(String cache, BaseRegExp regexp)Removes the object(s) which name(s) match the regular expression using the named LRU cache.Objectremove(String cache, StorageName name)Removes the object associated with the name using the named LRU cache.voidremoveChangeListener(StorageChangeListener l)Removes the change listener.intsize()Returns the number of elements stored.intsize(String cache)Returns the number of elements stored in the named LRU cache.StringtoString()Returns a string representation of all stored values.static StringtoValidName(String s)Turns any string into a valid storage name, by replacing invalid characters with underscores ("_").static StringtoValidName(String s, String replace)Turns any string into a valid storage name, by replacing invalid characters with the specified replacement string.
-
-
-
Field Detail
-
CHARS
public static final String CHARS
allowed characters.- See Also:
- Constant Field Values
-
START
public static final String START
the start of a storage placeholder.- See Also:
- Constant Field Values
-
END
public static final String END
the end of a storage placeholder.- See Also:
- Constant Field Values
-
m_ChangeListeners
protected transient Set<StorageChangeListener> m_ChangeListeners
the listeners.
-
-
Method Detail
-
clear
public void clear()
Empties the storage. Also removes all the LRU caches.
-
caches
public Iterator<String> caches()
Returns the names of the LRU caches currently available.- Returns:
- the names of the LRU caches
-
addCache
public void addCache(String name, int size)
Adds a LRU cache under the name with the specified size.- Parameters:
name- the name of the cachesize- the size of the cache
-
put
public Object put(StorageName name, Object value)
Adds the given value under the specified name.- Parameters:
name- the name to store the value undervalue- the value to store- Returns:
- any previous value stored under the same name
-
put
public void put(String cache, StorageName name, Object value)
Adds the given value under the specified name to the named LRU cache. Value gets dropped if cache is not available.- Parameters:
cache- the name of the cache to add it toname- the name to store the value undervalue- the value to store
-
has
public boolean has(StorageName name)
Checks whether a value is stored under the given name.- Parameters:
name- the name to check- Returns:
- true if a value is stored under the name
-
has
public boolean has(String cache, StorageName name)
Checks whether a value is stored under the given name in the named LRU cache.- Parameters:
cache- the LRU cache to checkname- the name to check- Returns:
- true if a value is stored under the name
-
get
public Object get(StorageName name)
Returns the object associated with the name.- Parameters:
name- the name of the value to retrieve- Returns:
- the associated value, or null if not found
-
get
public Object get(String cache, StorageName name)
Returns the object associated with the name from the named LRU cache.- Parameters:
cache- the LRU cache to accessname- the name of the value to retrieve- Returns:
- the associated value, or null if not found
-
get
public Map<String,Object> get(BaseRegExp nameRegExp)
Returns the objects associated with the regexp matching their name.- Parameters:
nameRegExp- the regexp for the names must match- Returns:
- the matching names with their associated values
-
get
public Map<String,Object> get(String cache, BaseRegExp nameRegExp)
Returns the objects associated with the regexp matching the names from the specified LRU cache.- Parameters:
cache- the LRU cache to accessnameRegExp- the regexp that the names must match- Returns:
- the matching names with their associated values
-
remove
public Object remove(StorageName name)
Removes the object associated with the name.- Parameters:
name- the name of the value to remove- Returns:
- the previously associated value, or null if none present
-
remove
public boolean remove(BaseRegExp regexp)
Removes the object(s) which name(s) match the regular expression.- Parameters:
regexp- the regular expression to match against- Returns:
- true if at least one removed
-
remove
public Object remove(String cache, StorageName name)
Removes the object associated with the name using the named LRU cache.- Parameters:
cache- the LRU cache to usename- the name of the value to remove- Returns:
- the previously associated value, or null if none present
-
remove
public boolean remove(String cache, BaseRegExp regexp)
Removes the object(s) which name(s) match the regular expression using the named LRU cache.- Parameters:
cache- the LRU cache to useregexp- the regular expression to match against- Returns:
- true if at least one removed
-
assign
public void assign(Storage other)
Adds all the items from the other Storage object (overwrites any existing ones).- Parameters:
other- the Storage to copy
-
assign
public void assign(Storage other, BaseRegExp filter)
Adds all the items from the other Storage object (overwrites any existing ones).- Parameters:
other- the Storage to copyfilter- the regular expression that the item names must match, null to ignore
-
size
public int size()
Returns the number of elements stored.- Returns:
- the number of stored values
-
size
public int size(String cache)
Returns the number of elements stored in the named LRU cache.- Parameters:
cache- the cache to get the size for- Returns:
- the number of stored values, 0 if cache not available
-
keySet
public Set<StorageName> keySet()
Returns the set of keys.- Returns:
- the set
-
keySet
public Set<StorageName> keySet(String cache)
Returns the set of keys from the named LRU cache.- Parameters:
cache- the cache to query- Returns:
- the set, emoty set if cache not available
-
getClone
public Storage getClone()
Returns a clone (deep copy) of the object.- Specified by:
getClonein interfaceCloneHandler<Storage>- Returns:
- the clone
-
getClone
public Storage getClone(BaseRegExp filter)
Returns a clone (deep copy) of the object.- Parameters:
filter- the regular expression that the storage item names must match (not applied to caches!), null to ignore- Returns:
- the clone
-
getShallowCopy
public Storage getShallowCopy()
Returns a shallow copy of the object.- Returns:
- the shallow copy
-
toString
public String toString()
Returns a string representation of all stored values.
-
isValidName
public static boolean isValidName(String s)
Checks whether the string represents a valid name.- Parameters:
s- the name to check- Returns:
- true if valid
-
expand
public String expand(String s)
Replaces all storage placeholders in the string with the currently stored values.- Parameters:
s- the string to process- Returns:
- the processed string
-
doExpand
protected String doExpand(String s)
Expands storage placeholders.- Parameters:
s- the string to expand- Returns:
- the potentially expanded string
-
expand
protected String expand(String s, boolean recurse)
Replaces all storage placeholders in the string with the currently stored values (ie string representation).- Parameters:
s- the string to processrecurse- whether to recurse, i.e., replacing "%{%{"- Returns:
- the processed string
-
initChangeListeners
protected void initChangeListeners()
Initializes the change listeners.
-
addChangeListener
public void addChangeListener(StorageChangeListener l)
Adds the change listener.- Parameters:
l- the listener to add
-
removeChangeListener
public void removeChangeListener(StorageChangeListener l)
Removes the change listener.- Parameters:
l- the listener to remove
-
notifyChangeListeners
protected void notifyChangeListeners(StorageChangeEvent e)
Notifies all listeners.- Parameters:
e- the event to send
-
toValidName
public static String toValidName(String s)
Turns any string into a valid storage name, by replacing invalid characters with underscores ("_").- Parameters:
s- the string to convert into a valid storage name- Returns:
- the (potentially) fixed name
-
toValidName
public static String toValidName(String s, String replace)
Turns any string into a valid storage name, by replacing invalid characters with the specified replacement string.- Parameters:
s- the string to convert into a valid storage namereplace- the replacement string for invalida chars- Returns:
- the (potentially) fixed name
-
-