Package ucar.nc2

Class Attribute


  • @Immutable
    public class Attribute
    extends Object
    An Attribute is a name and a value, used for associating arbitrary metadata with another object. The value can be a one dimensional array of Strings or numeric values.
    • Constructor Detail

      • Attribute

        public Attribute​(String name,
                         @Nullable
                         String val)
        Create a String-valued Attribute.
        Parameters:
        name - name of Attribute
        val - value of Attribute
      • Attribute

        public Attribute​(String name,
                         Number val)
        Create a scalar, signed, numeric-valued Attribute. Use builder for unsigned.
        Parameters:
        name - name of Attribute
        val - value of Attribute, assumed unsigned.
    • Method Detail

      • fromArray

        public static Attribute fromArray​(String name,
                                          Array<?> values)
        Create an Attribute from an Array.
      • emptyValued

        public static Attribute emptyValued​(String name,
                                            ArrayType dtype)
        Create an Attribute with a datatype but no value.
      • getArrayType

        public ArrayType getArrayType()
        Get the data type of the Attribute value.
      • getEnumType

        @Nullable
        public EnumTypedef getEnumType()
        Get the EnumTypedef of the Attribute value, if DataType is an ENUM.
      • getLength

        public int getLength()
        Get the length of the array of values
      • getName

        public String getName()
        Get the Attribute name, same as the short name.
      • getNumericValue

        @Nullable
        public Number getNumericValue()
        Retrieve first numeric value. Equivalent to getNumericValue(0)
      • getNumericValue

        @Nullable
        public Number getNumericValue​(int index)
        Retrieve a numeric value by index. If it's a String, it will try to parse it as a double.
        Parameters:
        index - the index into the value array.
        Returns:
        Number value[index], or null if its a non-parseable String or the index is out of range.
      • getShortName

        public String getShortName()
        Get the Attribute name.
      • getStringValue

        @Nullable
        public String getStringValue()
        Retrieve first String value if this is a String valued attribute, else null.
      • getStringValue

        @Nullable
        public String getStringValue​(int index)
        Retrieve ith String value; only call if isString() is true.
        Parameters:
        index - which index
        Returns:
        ith String value (if this is a String valued attribute and index in range), else null.
      • getOpaqueValue

        @Nullable
        public Array<Byte> getOpaqueValue​(int index)
        Retrieve the ith Opaque value, only call if isOpaque().
      • getValue

        @Nullable
        public Object getValue​(int index)
        Get the value as an Object (String or Number).
        Parameters:
        index - index into value Array.2
        Returns:
        ith value as an Object.
      • getArrayValues

        @Nullable
        public Array<?> getArrayValues()
        Get the values as an ucar.array.Array.
      • isArray

        public boolean isArray()
        True if value is an array (getLength() > 1)
      • isString

        public boolean isString()
        True if value is of type String and not null.
      • isOpaque

        public boolean isOpaque()
        True if value is of type Opaque and values instanceof ArrayVlen.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toBuilder

        public Attribute.Builder toBuilder()
        Turn into a mutable Builder. Can use toBuilder().build() to copy.
      • builder

        public static Attribute.Builder builder​(String name)
        Create an Attribute builder with the given Attribute name.