ucar.nc2
Class Attribute

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

@Immutable
public class Attribute
extends 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.
protected Attribute(String name)
          Constructor.
  Attribute(String name, Array values)
          Construct attribute with Array of values.
  Attribute(String name, Attribute from)
          Copy constructor
  Attribute(String name, DataType dataType)
          Construct an empty attribute with no values
  Attribute(String name, List values)
          Construct attribute with list of String or Number values.
  Attribute(String name, Number val)
          Create a scalar numeric-valued Attribute.
  Attribute(String name, String val)
          Create a String-valued Attribute.
 
Method Summary
 boolean equals(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
 String getName()
          Get the name of this Attribute.
 Number getNumericValue()
          Retrieve numeric value.
 Number getNumericValue(int index)
          Retrieve a numeric value by index.
 String getStringValue()
          Retrieve String value; only call if isString() is true.
 String getStringValue(int index)
          Retrieve ith String value; only call if isString() is true.
 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 of type String and not null.
 boolean isUnsigned()
          Find whether the underlying data should be interpreted as unsigned.
protected  void setValues(Array arr)
          set the values from an Array
 String toString()
          CDL representation, not strict
 String toString(boolean strict)
          CDL representation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Attribute

public Attribute(String name,
                 Attribute from)
Copy constructor

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

Attribute

public Attribute(String name,
                 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 numeric-valued Attribute.

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

Attribute

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

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

Attribute

public Attribute(String name,
                 DataType dataType)
Construct an empty attribute with no values

Parameters:
name - name of attribute
dataType - type of Attribute.

Attribute

public Attribute(String name,
                 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.

Attribute

protected Attribute(String name)
Constructor. Must also set value

Parameters:
name - name of Attribute
Method Detail

getName

public 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

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

Returns:
number of elementss in the array.

isUnsigned

public boolean isUnsigned()
Find whether the underlying data should be interpreted as unsigned. Only affects byte, short, and int.

Returns:
true if the data is unsigned integer type.

getValues

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

Returns:
Array of values.

getValue

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

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

isString

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

Returns:
if its a String and not null.

getStringValue

public 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 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 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 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(Object o)
Instances which have same content are equal.

Overrides:
equals in class Object

hashCode

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

Overrides:
hashCode in class Object

toString

public String toString()
CDL representation, not strict

Overrides:
toString in class Object
Returns:
CDL representation

toString

public String toString(boolean strict)
CDL representation

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

setValues

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

Parameters:
arr - value of Attribute


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.