ucar.nc2
Class Attribute

java.lang.Object
  extended by ucar.nc2.Attribute

@Immutable
public class Attribute
extends java.lang.Object

An Attribute has a name and a value, used for associating arbitrary metadata with a Variable or a Group. The value can be a one dimensional array of Strings or numeric values.

Attributes are immutable.

Author:
caron

Constructor Summary
Attribute(Parameter param)
          A copy constructor using a ucar.unidata.util.Parameter.
Attribute(java.lang.String name, Array values)
          Construct attribute with Array of values.
Attribute(java.lang.String name, Attribute from)
          Copy constructor
Attribute(java.lang.String name, java.util.List values)
          Construct attribute with list of String or Number values.
Attribute(java.lang.String name, java.lang.Number val)
          Create a scalar numeric-valued Attribute.
Attribute(java.lang.String name, java.lang.String val)
          Create a String-valued Attribute.
 
Method Summary
 boolean equals(java.lang.Object o)
          Instances which have same content are equal.
 DataType getDataType()
          Get the data type of the Attribute value.
 int getLength()
          Get the length of the array of values; = 1 if scaler.
 java.lang.String getName()
          Get the name of this Attribute.
 java.lang.Number getNumericValue()
          Retrieve numeric value.
 java.lang.Number getNumericValue(int index)
          Retrieve a numeric value by index.
 java.lang.String getStringValue()
          Retrieve String value; only call if isString() is true.
 java.lang.String getStringValue(int index)
          Retrieve ith String value; only call if isString() is true.
 java.lang.Object getValue(int index)
          Get the value as an Object.
 Array getValues()
          Get the value as an Array.
 int hashCode()
          Override Object.hashCode() to implement equals.
 boolean isArray()
          True if value is an array (getLength() > 1)
 boolean isString()
          True if value is a String or String[].
 java.lang.String toString()
          CDL representation, not strict
 java.lang.String toString(boolean strict)
          CDL representation
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Attribute

public Attribute(java.lang.String name,
                 Attribute from)
Copy constructor

Parameters:
name - name of Attribute
from - copy value from here.

Attribute

public Attribute(java.lang.String name,
                 java.lang.String val)
Create a String-valued Attribute.

Parameters:
name - name of Attribute
val - value of Attribute

Attribute

public Attribute(java.lang.String name,
                 java.lang.Number val)
Create a scalar numeric-valued Attribute.

Parameters:
name - name of Attribute
val - value of Attribute

Attribute

public Attribute(java.lang.String name,
                 Array values)
Construct attribute with Array of values.

Parameters:
name - name of attribute
values - array of values.

Attribute

public Attribute(java.lang.String name,
                 java.util.List values)
Construct attribute with list of String or Number values.

Parameters:
name - name of attribute
values - list of values. must be String or Number, must all be the same type, and have at least 1 member

Attribute

public Attribute(Parameter param)
A copy constructor using a ucar.unidata.util.Parameter. Need to do this so ucar.unidata.geoloc package doesnt depend on ucar.nc2 library

Parameters:
param - copy info from here.
Method Detail

getName

public java.lang.String getName()
Get the name of this Attribute. Attribute names are unique within a NetcdfFile's global set, and within a Variable's set.

Returns:
name

getDataType

public DataType getDataType()
Get the data type of the Attribute value.

Returns:
DataType

isString

public boolean isString()
True if value is a String or String[].

Returns:
if its a String.

isArray

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

Returns:
if its an array.

getLength

public int getLength()
Get the length of the array of values; = 1 if scaler.

Returns:
number of elementss in the array.

getValues

public Array getValues()
Get the value as an Array.

Returns:
Array of values.

getValue

public java.lang.Object getValue(int index)
Get the value as an Object.

Parameters:
index - which index
Returns:
ith value as an Object.

getStringValue

public java.lang.String getStringValue()
Retrieve String value; only call if isString() is true.

Returns:
String if this is a String valued attribute, else null.
See Also:
isString()

getStringValue

public java.lang.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.
See Also:
isString()

getNumericValue

public java.lang.Number getNumericValue()
Retrieve numeric value. Equivalent to getNumericValue(0)

Returns:
the first element of the value array, or null if its a String.

getNumericValue

public java.lang.Number getNumericValue(int index)
Retrieve a numeric value by index. If its 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-parsable String or the index is out of range.

equals

public boolean equals(java.lang.Object o)
Instances which have same content are equal.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Override Object.hashCode() to implement equals.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
CDL representation, not strict

Overrides:
toString in class java.lang.Object
Returns:
CDL representation

toString

public java.lang.String toString(boolean strict)
CDL representation

Parameters:
strict - if true, create strict CDL, escaping names
Returns:
CDL representation