Package ucar.nc2
Class Attribute
- java.lang.Object
-
- ucar.nc2.Attribute
-
@Immutable public class Attribute extends Object
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Attribute.Builder
-
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.static Attribute
emptyValued(String name, ArrayType dtype)
Create an Attribute with a datatype but no value.boolean
equals(Object o)
static Attribute
fromArray(String name, Array<?> values)
Create an Attribute from an Array.ArrayType
getArrayType()
Get the data type of the Attribute value.Array<?>
getArrayValues()
Get the values as an ucar.array.Array.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, same as the short name.Number
getNumericValue()
Retrieve first numeric value.Number
getNumericValue(int index)
Retrieve a numeric value by index.Array<Byte>
getOpaqueValue(int index)
Retrieve the ith Opaque value, only call if isOpaque().String
getShortName()
Get the Attribute name.String
getStringValue()
Retrieve first String value if this is a String valued attribute, else null.String
getStringValue(int index)
Retrieve ith String value; only call if isString() is true.Object
getValue(int index)
Get the value as an Object (String or Number).int
hashCode()
boolean
isArray()
True if value is an array (getLength() > 1)boolean
isOpaque()
True if value is of type Opaque and values instanceof ArrayVlen.boolean
isString()
True if value is of type String and not null.Attribute.Builder
toBuilder()
Turn into a mutable Builder.String
toString()
-
-
-
Method Detail
-
fromArray
public static Attribute fromArray(String name, Array<?> values)
Create an Attribute from an Array.
-
emptyValued
public static Attribute emptyValued(String name, ArrayType dtype)
Create an Attribute with a datatype but no value.
-
getArrayType
public ArrayType getArrayType()
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.
-
getLength
public int getLength()
Get the length of the array of values
-
getName
public String getName()
Get the Attribute name, same as the short name.
-
getNumericValue
@Nullable public Number getNumericValue()
Retrieve first numeric value. Equivalent togetNumericValue(0)
-
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.
-
getShortName
public String getShortName()
Get the Attribute name.
-
getStringValue
@Nullable public String getStringValue()
Retrieve first String value if this is a String valued attribute, else null.
-
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.
-
getOpaqueValue
@Nullable public Array<Byte> getOpaqueValue(int index)
Retrieve the ith Opaque value, only call if isOpaque().
-
getValue
@Nullable public Object getValue(int index)
Get the value as an Object (String or Number).- Parameters:
index
- index into value Array.2- Returns:
- ith value as an Object.
-
getArrayValues
@Nullable public Array<?> getArrayValues()
Get the values as an ucar.array.Array.
-
isArray
public boolean isArray()
True if value is an array (getLength() > 1)
-
isString
public boolean isString()
True if value is of type String and not null.
-
isOpaque
public boolean isOpaque()
True if value is of type Opaque and values instanceof ArrayVlen.
-
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.
-
-