Class LocalStorageHelper


  • public class LocalStorageHelper
    extends java.lang.Object
    A helper class for the LocalStorage module in JavaScript.
    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Hokeun Kim
    Pt.AcceptedRating:
    Red (bilung)
    Pt.ProposedRating:
    Yellow (eal)
    • Constructor Summary

      Constructors 
      Constructor Description
      LocalStorageHelper​(java.lang.String persistenceDirectory, java.lang.String containerActorName)
      Construct a LocalStorageHelper using the container's name and the actors' display name for the directory name.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Remove all keys in the local storage.
      java.lang.String getItem​(java.lang.String key)
      Take a key and return its value from the local storage if the key exists, otherwise, return null.
      java.lang.String key​(java.lang.Integer n)
      Return a key with index n, or null if it is not present.
      java.lang.Integer length()
      Return the number of keys stored in the local storage.
      void removeItem​(java.lang.String key)
      Take a key and remove it from the local storage.
      void setItem​(java.lang.String key, java.lang.String value)
      Take a key-value pair and stores the pair into the local storage.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocalStorageHelper

        public LocalStorageHelper​(java.lang.String persistenceDirectory,
                                  java.lang.String containerActorName)
                           throws org.eclipse.paho.client.mqttv3.MqttPersistenceException
        Construct a LocalStorageHelper using the container's name and the actors' display name for the directory name. Also use current time to make the directory name unique.
        Parameters:
        persistenceDirectory - The default Mqtt file persistance
        containerActorName - Container's name plus the actors' display name
        Throws:
        org.eclipse.paho.client.mqttv3.MqttPersistenceException
    • Method Detail

      • getItem

        public java.lang.String getItem​(java.lang.String key)
                                 throws org.eclipse.paho.client.mqttv3.MqttPersistenceException
        Take a key and return its value from the local storage if the key exists, otherwise, return null.
        Parameters:
        key - The key for the value to be returned.
        Returns:
        The string value associated with the key.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttPersistenceException
        See Also:
        setItem(String, String)
      • setItem

        public void setItem​(java.lang.String key,
                            java.lang.String value)
                     throws org.eclipse.paho.client.mqttv3.MqttPersistenceException,
                            java.io.IOException
        Take a key-value pair and stores the pair into the local storage.
        Parameters:
        key - The key to be stored.
        value - The string value associated with the key.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttPersistenceException
        java.io.IOException
        See Also:
        getItem(String)
      • removeItem

        public void removeItem​(java.lang.String key)
                        throws org.eclipse.paho.client.mqttv3.MqttPersistenceException
        Take a key and remove it from the local storage.
        Parameters:
        key - The key to be removed.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttPersistenceException
      • clear

        public void clear()
                   throws org.eclipse.paho.client.mqttv3.MqttPersistenceException
        Remove all keys in the local storage.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttPersistenceException
      • key

        public java.lang.String key​(java.lang.Integer n)
                             throws org.eclipse.paho.client.mqttv3.MqttException
        Return a key with index n, or null if it is not present.
        Parameters:
        n - Index for the key to be returned.
        Returns:
        The key with index n.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttException
      • length

        public java.lang.Integer length()
                                 throws org.eclipse.paho.client.mqttv3.MqttPersistenceException
        Return the number of keys stored in the local storage.
        Returns:
        The number of keys stored.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttPersistenceException