Package ucar.nc2
Class Attribute
- java.lang.Object
-
- ucar.nc2.CDMNode
-
- ucar.nc2.Attribute
-
public class Attribute extends ucar.nc2.CDMNode
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. TODO Attributes will be immutable in 6. TODO Attribute will not extend CDMNode in 6. TODO Attribute will not know who it belongs to in 6 (Group or Variable). TODO Attribute.getFullName() will not exist in 6.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Attribute.Builder
A builder for Attributes
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Attribute.Builder
builder()
Create an Attribute builder.static Attribute.Builder
builder(String name)
Create an Attribute builder with the given Attribute name.boolean
equals(Object o)
Instances which have same content are equal.DataType
getDataType()
Get the data type of the Attribute value.EnumTypedef
getEnumType()
Get the EnumTypedef of the Attribute value, if DataType is an ENUM.int
getLength()
Get the length of the array of valuesString
getName()
Get the Attribute name.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.Attribute.Builder
toBuilder()
Turn into a mutable Builder.String
toString()
-
-
-
Method Detail
-
getName
public String getName()
Get the Attribute name. Not deprecated in version 5 for Attribute.
-
getDataType
public DataType getDataType()
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.
-
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 elements in the array.
-
getValues
@Nullable public Array getValues()
Get the value as an Array.- Returns:
- Array of values.
-
getValue
@Nullable 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
@Nullable 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
@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.
- See Also:
isString()
-
getNumericValue
@Nullable public Number getNumericValue()
Retrieve numeric value. Equivalent togetNumericValue(0)
- Returns:
- the first element of the value array, or null if its a String that cant be converted.
-
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.
-
equals
public boolean equals(Object o)
Instances which have same content are equal.
-
hashCode
public int hashCode()
Override Object.hashCode() to implement equals.
-
toBuilder
public Attribute.Builder toBuilder()
Turn into a mutable Builder. Can use toBuilder().build() to copy.
-
builder
public static Attribute.Builder builder()
Create an Attribute builder.
-
builder
public static Attribute.Builder builder(String name)
Create an Attribute builder with the given Attribute name.
-
-