## ucar.netcdf
Class Attribute

    java.lang.Object
      ucar.netcdf.Attribute

All Implemented Interfaces:
  Cloneable, Named, Serializable

public class Attribute
extends Object
implements Named, Serializable, Cloneable

Attributes are similar to "IndexedProperties" in the lingo of java beans. They have a name, type and an array of values. The array is often of length 1, degenerating into a simple property. The array should never be length 0. An Attribute object is used to contain netcdf "metadata", like units of a measurable quantity or its valid range.

These attributes have fixed values over their lifetime; no setValue() methods are provided.

Instances which have same name and same value elements are equal. We override hashCode() and equals() to be consistent with this semantic.

See Also:
  Serialized Form

Constructor Summary
`Attribute(String name, double value)` Construct simple numeric attribute.
`Attribute(String name, Number value)` Construct simple numeric attribute.
`Attribute(String name, Object theValue)` Construct an array valued Attribute.
`Attribute(String name, String theValue)` Construct a string valued attribute.

Method Summary
`(package private) static Object` `arrayClone(Object src)` Why isn't this in java.lang.reflect.Array as native?
`boolean` `equals(Object oo)` Instances which have same name and same value elements are equal.
`Object` `get(int index)` Retrieve indexed value.
`Class` `getComponentType()` If the value represents an array type, returns the Class object representing the component type of the array; otherwise returns null.
`int` `getLength()` If the value represents an array type, returns the length of the value array; otherwise return String.length of the String value.
`String` `getName()` Returns the name of this Attribute.
`Number` `getNumericValue()` Retrieve simple numeric value.
`Number` `getNumericValue(int index)` Retrieve indexed numeric value.
`String` `getStringValue()` Retrieve String value.
`Object` `getValue()` Retrieve the value in its most general form.
`int` `hashCode()` Instances which have same name and same value elements are equal.
`boolean` `isString()` If the value is an instance of String, return `true` otherwise returns `false`
`(package private) static Class` `primitiveClass(Number nn)` Use reflection to find out the TYPE (primitive class) corresponding to a Number.
`void` `toCdl(StringBuffer buf)` Format as CDL.
`String` `toString()`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Attribute

    public Attribute(String name,
                     Number value)

  Construct simple numeric attribute.

Parameters:
  `name` - String which is to be the name of this Attribute
  `value` - A Number to be the Attribute value

### Attribute

    public Attribute(String name,
                     double value)

  Construct simple numeric attribute.

Parameters:
  `name` - String which is to be the name of this Attribute
  `value` - A double to be the Attribute value

### Attribute

    public Attribute(String name,
                     String theValue)

  Construct a string valued attribute. This will be seen to have component type Character.TYPE

Parameters:
  `name` - String which is to be the name of this Attribute
  `theValue` - The value

### Attribute

    public Attribute(String name,
                     Object theValue)

  Construct an array valued Attribute. Not often used.

Parameters:
  `name` - String which is to be the name of this Attribute
  `theValue` - The value, an array of primitives. The primitive type must be netcdf encodeable.

Method Detail

### hashCode

    public int hashCode()

  Instances which have same name and same value elements are equal. Overrides Object.equals() to be consistent with this semantic.

  Returns:
    the hash code value for this Attribute

### equals

    public boolean equals(Object oo)

  Instances which have same name and same value elements are equal. Overrides Object.equals() to be consistent with this semantic. TODO: test me.

### toString

    public String toString()

  Returns:
    a string representation of this

### getName

    public final String getName()

  Returns the name of this Attribute.

  Specified by:
    `getName` in interface `Named`
  Returns:
    String which identifies this Attribute.

### getValue

    public Object getValue()

  Retrieve the value in its most general form.

  Returns:
    Object which is either a java.lang.String or a 1-dimensional array of primitives.
  See Also:
    `isString()`

### getStringValue

    public String getStringValue()

  Retrieve String value.

  Returns:
    String if this is a String valued attribute.
  Throws:
    `ClassCastException` - if this is not String valued.
  See Also:
    `isString()`

### get

    public Object get(int index)

  Retrieve indexed value.

  Parameters:
    `index` - int which is the index into the value array.
  Returns:
    Number `value[index]`

### getNumericValue

    public Number getNumericValue(int index)

  Retrieve indexed numeric value.

  Parameters:
    `index` - int which is the index into the value array.
  Returns:
    Number `value[index]`

### getNumericValue

    public Number getNumericValue()

  Retrieve simple numeric value. Equivalent to `getNumericValue(0)`

  Returns:
    Number the first element of the value array

### isString

    public boolean isString()

  If the value is an instance of String, return `true` otherwise returns `false`

  Returns:
    boolean value instanceof String

### getComponentType

    public Class getComponentType()

  If the value represents an array type, returns the Class object representing the component type of the array; otherwise returns null.

  Returns:
    Class the component type
  See Also:
    `Class.getComponentType()`

### getLength

    public int getLength()

  If the value represents an array type, returns the length of the value array; otherwise return String.length of the String value.

  Returns:
    int length of the value

### toCdl

    public void toCdl(StringBuffer buf)

  Format as CDL.

  Parameters:
    `buf` - StringBuffer into which to write

### arrayClone

    static Object arrayClone(Object src)

  Why isn't this in java.lang.reflect.Array as native?

### primitiveClass

    static Class primitiveClass(Number nn)

  Use reflection to find out the TYPE (primitive class) corresponding to a Number.