Class NetricsVarAttr

  • All Implemented Interfaces:
    java.io.Serializable

    public class NetricsVarAttr
    extends java.lang.Object
    implements java.io.Serializable
    Manage a set of Variable Attribute values.

    This class is used to encode, decode and manipulate a set of Variable Attribute values. A Variable Attribute value is a name value pair. The name is a text string consisting of from 1 to 2048 letters, digits dash or underscore characters. The value is any set of 0 to 50,000 characters. Both are represented in Java as String values. A set of Variable Attributes is encoded into a block of characters and passed as a single field value in a record.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      NetricsVarAttr()
      Create an empty set of variable attributes.
      NetricsVarAttr​(java.lang.String enc_str)
      Create a Variable Attributes set from and encoded string.
      NetricsVarAttr​(java.lang.String[] attr_names, java.lang.String[] attr_values)
      Create a set of variable attributes from a list of names and values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int delAttr​(java.lang.String name)
      Delete a named attribute from the Variable Attributes set.
      java.lang.String[] getAllNames()
      return an array of the names of all attributes in the set.
      java.lang.String getAttr​(java.lang.String name)
      Retrieve the value of a named attribute.
      java.lang.String getEncodedStr()
      return this Variable Attributes set as an encoded string.
      int setAttr​(java.lang.String name, java.lang.String value)
      Add or replace an attribute in a Variable Attribute set.
      • Methods inherited from class java.lang.Object

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

      • NetricsVarAttr

        public NetricsVarAttr()
        Create an empty set of variable attributes.

        This constructor creates a new set of Variable Attributes with no attributes in it.
      • NetricsVarAttr

        public NetricsVarAttr​(java.lang.String[] attr_names,
                              java.lang.String[] attr_values)
                       throws java.lang.IllegalArgumentException
        Create a set of variable attributes from a list of names and values.

        This constructor creates a new set of Variable Attributes and populates it from a list of attribute names and attributes values.

        The following validations are performed:
        • length of attr_names != length of attr_values
        • any attr_names or attr_values is null
        • any attr_names length is < 1 or > 2048
        • any attr_names contains invalid characters.
        Parameters:
        attr_names - an array of the names of the attributes.
        attr_values - an array of the values for the attributes.
        Throws:
        java.lang.IllegalArgumentException - if any validation fails.
      • NetricsVarAttr

        public NetricsVarAttr​(java.lang.String enc_str)
                       throws java.lang.IllegalArgumentException,
                              java.lang.IndexOutOfBoundsException,
                              java.lang.NullPointerException
        Create a Variable Attributes set from and encoded string.

        This creates a new Variable Attributes set from a string encoded form of a Variable Attributes as created by the getEncodedStr method.
        Parameters:
        enc_str - the string encoded Variable Attributes set.
        Throws:
        java.lang.IllegalArgumentException - if enc_str is invalid.
        java.lang.IndexOutOfBoundsException - should never be thrown.
        java.lang.NullPointerException - should never be thrown.
        See Also:
        for description of format of the encoded string.
    • Method Detail

      • setAttr

        public int setAttr​(java.lang.String name,
                           java.lang.String value)
                    throws java.lang.IllegalArgumentException,
                           java.lang.NullPointerException
        Add or replace an attribute in a Variable Attribute set.

        This adds a new attribute if name is not already in this set, or replaces an existing attribute if it is.
        Parameters:
        name - the attribute name
        value - the attribute value
        Returns:
        1 if attribute was added, 0 if attribute was replaced
        Throws:
        java.lang.IllegalArgumentException - if name is invalid or value is null.
        java.lang.NullPointerException - should never be thrown.
      • getAttr

        public java.lang.String getAttr​(java.lang.String name)
                                 throws java.lang.IllegalArgumentException
        Retrieve the value of a named attribute.

        This retrieves the value of an attribute from the Variable Attributes set. If the set has no such value null is returned.
        Parameters:
        name - the name of the attribute to be retrieved.
        Returns:
        the value of the named attribute, null if no such attribute.
        Throws:
        java.lang.IllegalArgumentException - if name is null.
      • delAttr

        public int delAttr​(java.lang.String name)
                    throws java.lang.IllegalArgumentException
        Delete a named attribute from the Variable Attributes set.

        This deletes a named attribute from this Variable Attributes set if it exists. It does nothing if it does not exist.
        Parameters:
        name - the name of the attribute to be deleted.
        Returns:
        1 if it was deleted, 0 if no such attribute exists.
        Throws:
        java.lang.IllegalArgumentException - if name is null.
      • getAllNames

        public java.lang.String[] getAllNames()
        return an array of the names of all attributes in the set.

        This return a list of the names of all of the attributes in this Variable Attributes set. The names are returned in the order in which they were added to the set.
        Returns:
        array of names of each attribute in the set.
      • getEncodedStr

        public java.lang.String getEncodedStr()
                                       throws java.lang.IndexOutOfBoundsException,
                                              java.lang.NullPointerException
        return this Variable Attributes set as an encoded string.

        This encodes all of the attributes in this Variable Attributes set into a single String value and returns that value. The encoded string has the format:

        (zero length string if no attributes)

        OR

        <attr-name>:<attr-value>[;<attr-name>:<attr-value>]*

        where attr-name is the attribute name and attr-value is the attribute value with all occurences of ';' changed to ';;'. Names appear in the order they were originally added to this Variable Attributes set.

        If there is some error generating the encoded value for an attribute that attribute is simply skipped.
        Returns:
        the encoded string as described above.
        Throws:
        java.lang.IndexOutOfBoundsException - this should never be thrown.
        java.lang.NullPointerException - this should never be thrown.