Class Storage

    • Constructor Detail

      • Storage

        public Storage()
        Initializes the storage.
    • 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 cache
        size - 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 under
        value - 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 to
        name - the name to store the value under
        value - 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 check
        name - 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 access
        name - 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 access
        nameRegExp - 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 use
        name - 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 use
        regexp - 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 copy
        filter - 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​(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.
        Overrides:
        toString in class Object
        Returns:
        the string representation
      • 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 process
        recurse - 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 name
        replace - the replacement string for invalida chars
        Returns:
        the (potentially) fixed name