ucar.nc2
Class Attribute

java.lang.Object
  extended by ucar.nc2.Attribute
Direct Known Subclasses:
DODSAttribute

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 considered immutable : do not change them after they have been constructed.

Author:
caron

Field Summary
protected  DataType dataType
           
protected  Index ima
           
protected  java.lang.String name
           
protected  int nelems
           
protected  Array values
           
 
Constructor Summary
protected Attribute()
           
  Attribute(Parameter param)
          A copy constructor using a ucar.unidata.util.Parameter.
  Attribute(java.lang.String name)
          Constructor.
  Attribute(java.lang.String name, Array values)
          Construct attribute with list of values.
  Attribute(java.lang.String name, Attribute from)
          Copy constructor
  Attribute(java.lang.String name, boolean validate)
          Constructor.
  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.
 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[].
 void setName(java.lang.String name)
          Set the name of the Attribute.
 void setStringValue(java.lang.String val)
          set the value as a String, trimming trailing zeroes
protected  void setValueOld(java.lang.Object val)
          Deprecated. use setValues( Array val)
 void setValues(Array arr)
          set the values from an Array
 java.lang.String toString()
          String representation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

dataType

protected DataType dataType

nelems

protected int nelems

values

protected Array values

ima

protected Index ima
Constructor Detail

Attribute

protected Attribute()

Attribute

public Attribute(java.lang.String name)
Constructor. Must also set value

Parameters:
name - name of Attribute

Attribute

public Attribute(java.lang.String name,
                 boolean validate)
Constructor. Must also set value

Parameters:
name - name of Attribute
validate - whther to validate the name.

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 list of values.

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

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.

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()
String representation

Overrides:
toString in class java.lang.Object

setName

public void setName(java.lang.String name)
Set the name of the Attribute.

Parameters:
name - name of Attribute

setValueOld

protected void setValueOld(java.lang.Object val)
Deprecated. use setValues( Array val)

Create an Attribute with a String or a 1-dimensional array of primitives.

Parameters:
val - value of Attribute

setStringValue

public void setStringValue(java.lang.String val)
set the value as a String, trimming trailing zeroes

Parameters:
val - value of Attribute

setValues

public void setValues(Array arr)
set the values from an Array

Parameters:
arr - value of Attribute