Package ucar.nc2
Class Attribute
- java.lang.Object
-
- ucar.nc2.CDMNode
-
- ucar.nc2.Attribute
-
- Direct Known Subclasses:
DODSAttribute
public class Attribute extends 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
-
Field Summary
Fields Modifier and Type Field Description static String[]
SPECIALS
Deprecated.move to jni.Nc4Iosp-
Fields inherited from class ucar.nc2.CDMNode
annotations, dodsname, group, immutable, parentstruct, shortName, sort
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Attribute(String name)
Deprecated.Use Attribute.builder()Attribute(String name, Number val)
Create a scalar, signed, numeric-valued Attribute.Attribute(String name, Number val, boolean isUnsigned)
Deprecated.Use Attribute.builder()Attribute(String name, String val)
Create a String-valued Attribute.Attribute(String name, List values)
Deprecated.Use Attribute.builder()Attribute(String name, List values, boolean isUnsigned)
Deprecated.Use Attribute.builder()Attribute(String name, Array values)
Deprecated.Use Attribute.builder()Attribute(String name, DataType dataType)
Deprecated.Use Attribute.builder()Attribute(String name, Attribute from)
Deprecated.Use Attribute.toBuilder().build();Attribute(Parameter param)
Deprecated.Use Attribute.builder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated 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)static boolean
isspecial(Attribute a)
Deprecated.move to jni.Nc4Iospboolean
isString()
True if value is of type String and not null.static Map<String,Attribute>
makeMap(List<Attribute> atts)
Deprecated.do not usevoid
setDataType(DataType dt)
Deprecated.Use Attribute.builder()void
setEnumType(EnumTypedef en)
Deprecated.Use Attribute.builder()void
setName(String name)
Deprecated.Use Attribute.builder()void
setValues(List values)
Deprecated.Use Attribute.builder()void
setValues(Array arr)
Deprecated.Use Attribute.builder()Attribute.Builder
toBuilder()
Turn into a mutable Builder.String
toString()
String
toString(boolean strict)
Deprecated.use CDLWriterprotected void
writeCDL(Formatter f, boolean strict, String parentname)
Deprecated.use CDLWriter-
Methods inherited from class ucar.nc2.CDMNode
annotate, annotation, getDODSName, getFullName, getFullNameEscaped, getGroup, getImmutable, getParentGroup, getParentStructure, getShortName, getSort, isMemberOfStructure, localhash, setDODSName, setImmutable, setParentGroup, setParentStructure, setShortName, setSort, unwrap
-
-
-
-
Field Detail
-
SPECIALS
@Deprecated public static final String[] SPECIALS
Deprecated.move to jni.Nc4Iosp
-
-
Constructor Detail
-
Attribute
@Deprecated public Attribute(String name, Attribute from)
Deprecated.Use Attribute.toBuilder().build();Copy constructor- Parameters:
name
- name of new Attributefrom
- copy value from here.
-
Attribute
public Attribute(String name, String val)
Create a String-valued Attribute.- Parameters:
name
- name of Attributeval
- value of Attribute
-
Attribute
public Attribute(String name, Number val)
Create a scalar, signed, numeric-valued Attribute.- Parameters:
name
- name of Attributeval
- value of Attribute
-
Attribute
@Deprecated public Attribute(String name, Number val, boolean isUnsigned)
Deprecated.Use Attribute.builder()Create a scalar numeric-valued Attribute, possibly unsigned.- Parameters:
name
- name of Attributeval
- value of AttributeisUnsigned
- if value is unsigned, used only for integer types.
-
Attribute
@Deprecated public Attribute(String name, Array values)
Deprecated.Use Attribute.builder()Construct attribute with Array of values.- Parameters:
name
- name of attributevalues
- array of values.
-
Attribute
@Deprecated public Attribute(String name, DataType dataType)
Deprecated.Use Attribute.builder()Construct an empty attribute with no values
-
Attribute
@Deprecated public Attribute(String name, List values)
Deprecated.Use Attribute.builder()
-
Attribute
@Deprecated public Attribute(String name, List values, boolean isUnsigned)
Deprecated.Use Attribute.builder()Construct attribute with list of String or Number values. The list determines the attribute type- Parameters:
name
- name of attributevalues
- list of values. must be String or Number, must all be the same type, and have at least 1 memberisUnsigned
- if the data type is unsigned.
-
Attribute
@Deprecated public Attribute(Parameter param)
Deprecated.Use Attribute.builder()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
@Deprecated protected Attribute(String name)
Deprecated.Use Attribute.builder()Constructor. Must also set value- Parameters:
name
- name of Attribute
-
-
Method Detail
-
makeMap
@Deprecated public static Map<String,Attribute> makeMap(List<Attribute> atts)
Deprecated.do not useTurn a list into a map- Parameters:
atts
- list of attributes- Returns:
- map of attributes by name
-
isspecial
@Deprecated public static boolean isspecial(Attribute a)
Deprecated.move to jni.Nc4Iosp
-
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.
-
setDataType
@Deprecated public void setDataType(DataType dt)
Deprecated.Use Attribute.builder()
-
getEnumType
@Nullable public EnumTypedef getEnumType()
Get the EnumTypedef of the Attribute value, if DataType is an ENUM.
-
setEnumType
@Deprecated public void setEnumType(EnumTypedef en)
Deprecated.Use Attribute.builder()
-
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.
-
toString
@Deprecated public String toString(boolean strict)
Deprecated.use CDLWriterCDL representation, may be strict.- Parameters:
strict
- if true, create strict CDL, escaping names- Returns:
- CDL representation
-
writeCDL
@Deprecated protected void writeCDL(Formatter f, boolean strict, String parentname)
Deprecated.use CDLWriterWrite CDL representation into a Formatter.- Parameters:
f
- write into thisstrict
- if true, create strict CDL, escaping names
-
setValues
@Deprecated public void setValues(List values)
Deprecated.Use Attribute.builder()Set the values from a list
-
setValues
@Deprecated public void setValues(Array arr)
Deprecated.Use Attribute.builder()Set the values from an Array- Parameters:
arr
- value of Attribute
-
setName
@Deprecated public void setName(String name)
Deprecated.Use Attribute.builder()Set the name of this Attribute. Attribute names are unique within a NetcdfFile's global set, and within a Variable's set.- Parameters:
name
- name of attribute
-
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.
-
-