Class Tag

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Map.Entry<java.lang.String,​java.lang.String>, Tagged

    public class Tag
    extends java.lang.Object
    implements Tagged, java.util.Map.Entry<java.lang.String,​java.lang.String>, java.io.Serializable
    Tag represents an immutable key/value-pair. Both the key and the value may be empty, but not null.

    It implements the Tagged interface. However, since instances of this class are immutable, the modifying methods throw an UnsupportedOperationException.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String key  
      private static long serialVersionUID  
      private java.lang.String value  
    • Constructor Summary

      Constructors 
      Constructor Description
      Tag()
      Create an empty tag whose key and value are empty.
      Tag​(java.lang.String key)
      Create a tag whose key is key and whose value is empty.
      Tag​(java.lang.String key, java.lang.String value)
      Creates a tag for a key and a value.
      Tag​(Tag tag)
      Creates clone of the tag tag.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      java.lang.String get​(java.lang.String k)
      Replies the value of the given key; null, if there is no value for this key
      java.lang.String getKey()
      Replies the key of the tag.
      java.util.Map<java.lang.String,​java.lang.String> getKeys()
      Replies the map of key/value pairs.
      int getNumKeys()
      Gets the number of keys
      java.lang.String getValue()
      Replies the value of the tag.
      int hashCode()  
      boolean hasKeys()
      Replies true, if there is at least one key/value pair; false, otherwise
      boolean isDirectionKey()
      true if this is a direction dependent tag (e.g.
      java.util.Collection<java.lang.String> keySet()
      Replies the set of keys
      boolean matchesKey​(java.lang.String key)
      Replies true if the key of this tag is equal to key.
      static Tag ofString​(java.lang.String s)
      This constructs a Tag by splitting s on the first equality sign.
      void put​(java.lang.String key, java.lang.String value)
      Unsupported.
      void remove​(java.lang.String key)
      Unsupported.
      void removeAll()
      Unsupported.
      void setKeys​(java.util.Map<java.lang.String,​java.lang.String> keys)
      Unsupported.
      java.lang.String setValue​(java.lang.String value)
      This is not supported by this implementation.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Tag

        public Tag()
        Create an empty tag whose key and value are empty.
      • Tag

        public Tag​(java.lang.String key)
        Create a tag whose key is key and whose value is empty.
        Parameters:
        key - the key. If null, it is set to the empty key.
      • Tag

        public Tag​(java.lang.String key,
                   java.lang.String value)
        Creates a tag for a key and a value. If key and/or value are null, the empty value "" is assumed.
        Parameters:
        key - the key
        value - the value
      • Tag

        public Tag​(Tag tag)
        Creates clone of the tag tag.
        Parameters:
        tag - the tag.
    • Method Detail

      • getKey

        public java.lang.String getKey()
        Replies the key of the tag. This is never null.
        Specified by:
        getKey in interface java.util.Map.Entry<java.lang.String,​java.lang.String>
        Returns:
        the key of the tag
      • getValue

        public java.lang.String getValue()
        Replies the value of the tag. This is never null.
        Specified by:
        getValue in interface java.util.Map.Entry<java.lang.String,​java.lang.String>
        Returns:
        the value of the tag
      • setValue

        public java.lang.String setValue​(java.lang.String value)
        This is not supported by this implementation.
        Specified by:
        setValue in interface java.util.Map.Entry<java.lang.String,​java.lang.String>
        Parameters:
        value - ignored
        Returns:
        (Does not return)
        Throws:
        java.lang.UnsupportedOperationException - always
      • matchesKey

        public boolean matchesKey​(java.lang.String key)
        Replies true if the key of this tag is equal to key. If key is null, assumes the empty key.
        Parameters:
        key - the key
        Returns:
        true if the key of this tag is equal to key
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map.Entry<java.lang.String,​java.lang.String>
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Map.Entry<java.lang.String,​java.lang.String>
        Overrides:
        equals in class java.lang.Object
      • ofString

        public static Tag ofString​(java.lang.String s)
        This constructs a Tag by splitting s on the first equality sign.
        Parameters:
        s - the string to convert
        Returns:
        the constructed tag
        See Also:
        TextTagParser
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • setKeys

        public void setKeys​(java.util.Map<java.lang.String,​java.lang.String> keys)
        Unsupported.
        Specified by:
        setKeys in interface Tagged
        Parameters:
        keys - ignored
        Throws:
        java.lang.UnsupportedOperationException - always
      • getKeys

        public java.util.Map<java.lang.String,​java.lang.String> getKeys()
        Description copied from interface: Tagged
        Replies the map of key/value pairs. Never null, but may be the empty map.
        Specified by:
        getKeys in interface Tagged
        Returns:
        the map of key/value pairs
      • put

        public void put​(java.lang.String key,
                        java.lang.String value)
        Unsupported.
        Specified by:
        put in interface Tagged
        Parameters:
        key - ignored
        value - ignored
        Throws:
        java.lang.UnsupportedOperationException - always
      • get

        public java.lang.String get​(java.lang.String k)
        Description copied from interface: Tagged
        Replies the value of the given key; null, if there is no value for this key
        Specified by:
        get in interface Tagged
        Parameters:
        k - the key
        Returns:
        the value
      • remove

        public void remove​(java.lang.String key)
        Unsupported.
        Specified by:
        remove in interface Tagged
        Parameters:
        key - ignored
        Throws:
        java.lang.UnsupportedOperationException - always
      • hasKeys

        public boolean hasKeys()
        Description copied from interface: Tagged
        Replies true, if there is at least one key/value pair; false, otherwise
        Specified by:
        hasKeys in interface Tagged
        Returns:
        true, if there is at least one key/value pair; false, otherwise
      • keySet

        public java.util.Collection<java.lang.String> keySet()
        Description copied from interface: Tagged
        Replies the set of keys
        Specified by:
        keySet in interface Tagged
        Returns:
        the set of keys
        See Also:
        Tagged.keys()
      • getNumKeys

        public final int getNumKeys()
        Description copied from interface: Tagged
        Gets the number of keys
        Specified by:
        getNumKeys in interface Tagged
        Returns:
        The number of keys set for this tagged object.
      • removeAll

        public void removeAll()
        Unsupported.
        Specified by:
        removeAll in interface Tagged
        Throws:
        java.lang.UnsupportedOperationException - always
      • isDirectionKey

        public boolean isDirectionKey()
        true if this is a direction dependent tag (e.g. oneway)
        Returns:
        true if this is is a direction dependent tag
        Since:
        10716