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 String
CHARS
allowed characters.static String
END
the end of a storage placeholder.protected HashMap<String,LRUCache<String,Object>>
m_Caches
name LRU caches.protected Set<StorageChangeListener>
m_ChangeListeners
the listeners.protected HashMap<String,Object>
m_Data
for storing the data.static String
START
the 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 void
addCache(String name, int size)
Adds a LRU cache under the name with the specified size.void
addChangeListener(StorageChangeListener l)
Adds the change listener.void
assign(Storage other)
Adds all the items from the other Storage object (overwrites any existing ones).void
assign(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.void
clear()
Empties the storage.protected String
doExpand(String s)
Expands storage placeholders.String
expand(String s)
Replaces all storage placeholders in the string with the currently stored values.protected String
expand(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.Object
get(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.Object
get(String cache, StorageName name)
Returns the object associated with the name from the named LRU cache.Storage
getClone()
Returns a clone (deep copy) of the object.Storage
getClone(BaseRegExp filter)
Returns a clone (deep copy) of the object.Storage
getShallowCopy()
Returns a shallow copy of the object.boolean
has(StorageName name)
Checks whether a value is stored under the given name.boolean
has(String cache, StorageName name)
Checks whether a value is stored under the given name in the named LRU cache.protected void
initChangeListeners()
Initializes the change listeners.static boolean
isValidName(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 void
notifyChangeListeners(StorageChangeEvent e)
Notifies all listeners.Object
put(StorageName name, Object value)
Adds the given value under the specified name.void
put(String cache, StorageName name, Object value)
Adds the given value under the specified name to the named LRU cache.boolean
remove(BaseRegExp regexp)
Removes the object(s) which name(s) match the regular expression.Object
remove(StorageName name)
Removes the object associated with the name.boolean
remove(String cache, BaseRegExp regexp)
Removes the object(s) which name(s) match the regular expression using the named LRU cache.Object
remove(String cache, StorageName name)
Removes the object associated with the name using the named LRU cache.void
removeChangeListener(StorageChangeListener l)
Removes the change listener.int
size()
Returns the number of elements stored.int
size(String cache)
Returns the number of elements stored in the named LRU cache.String
toString()
Returns a string representation of all stored values.static String
toValidName(String s)
Turns any string into a valid storage name, by replacing invalid characters with underscores ("_").static String
toValidName(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:
getClone
in 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
-
-