Package ucar.nc2
Class Group
- java.lang.Object
-
- ucar.nc2.CDMNode
-
- ucar.nc2.Group
-
- All Implemented Interfaces:
Iterable<Attribute>,AttributeContainer
public class Group extends CDMNode implements AttributeContainer
A logical collection of Variables, Attributes, and Dimensions. The Groups in a Dataset form a hierarchical tree, like directories on a disk. A Group has a name and optionally a set of Attributes. There is always at least one Group in a dataset, the root Group, whose name is the empty string. Immutable if setImmutable() was called. TODO Group will be immutable in 6. TODO Group will not implement AttributeContainer in 6, use Group.attributes(). TODO Group will not extend CDMNode in 6.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGroup.BuilderA builder of Groups.
-
Field Summary
Fields Modifier and Type Field Description protected AttributeContainerattributesprotected List<Dimension>dimensionsprotected List<EnumTypedef>enumTypedefsprotected List<Group>groupsprotected NetcdfFilencfileprotected List<Variable>variables-
Fields inherited from class ucar.nc2.CDMNode
annotations, dodsname, group, immutable, parentstruct, shortName, sort
-
-
Constructor Summary
Constructors Constructor Description Group(NetcdfFile ncfile, Group parent, String shortName)Deprecated.Use Group.builder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddAll(Iterable<Attribute> atts)Deprecated.Use Group.builder()AttributeaddAttribute(Attribute att)Deprecated.Use Group.builder()voidaddDimension(Dimension dim)Deprecated.Use Group.builder()booleanaddDimensionIfNotExists(Dimension dim)Deprecated.Use Group.builder()voidaddEnumeration(EnumTypedef e)Deprecated.Use Group.builder()voidaddGroup(Group g)Deprecated.Use Group.builder()voidaddVariable(Variable v)Deprecated.Use Group.builder()AttributeContainerattributes()The attributes contained by this Group.static Group.Builderbuilder()GroupcommonParent(Group other)Get the common parent of this and the other group.booleanequals(Object oo)Instances which have same name and parent are equal.AttributefindAttribute(String name)Find the attribute by name, return null if not existdoublefindAttributeDouble(String attName, double defaultValue)Deprecated.Use attributes().findAttributeDouble()AttributefindAttributeIgnoreCase(String name)Deprecated.Use findAttributeString()intfindAttributeInteger(String attName, int defaultValue)Deprecated.Use attributes().findAttributeInteger()StringfindAttributeString(String attName, String defaultValue)Find a String-valued Attribute by name (ignore case), return the String value of the Attribute.DimensionfindDimension(String name)Find a Dimension in this or a parent Group, matching on short name.DimensionfindDimension(Dimension dim)Find a Dimension in this or a parent Group, using equals.DimensionfindDimensionLocal(String shortName)Find a Dimension using its (short) name, in this group onlyEnumTypedeffindEnumeration(String name)Find a Enumeration in this or a parent Group, using its short name.GroupfindGroup(String groupShortName)Deprecated.use findGroupLocal()GroupfindGroupLocal(String groupShortName)Retrieve the Group with the specified (short) name.VariablefindVariable(String varShortName)Deprecated.use findVariableLocal()VariablefindVariableByAttribute(String attName, String attValue)Look in this Group and in its nested Groups for a Variable with a String valued Attribute with the given name and value.VariablefindVariableLocal(String varShortName)Find the Variable with the specified (short) name in this group.VariablefindVariableOrInParent(String varShortName)Find the Variable with the specified (short) name in this group or a parent group.List<Attribute>getAttributes()Deprecated.Use attributes()List<Dimension>getDimensions()Get the shared Dimensions contained directly in this group.com.google.common.collect.ImmutableList<EnumTypedef>getEnumTypedefs()Get the enumerations contained directly in this group.StringgetFullName()Get the full name of this object.com.google.common.collect.ImmutableList<Group>getGroups()Get the Groups contained directly in this Group.StringgetNameAndAttributes()Get String with name and attributes.NetcdfFilegetNetcdfFile()Get the owning NetcdfFileGroupgetParentGroup()Get the parent Group, or null if its the root group.List<Variable>getVariables()Get the Variables contained directly in this group.inthashCode()Override Object.hashCode() to implement equals.booleanisEmpty()Deprecated.Use attributes()booleanisParent(Group other)Is this a parent of the other Group?booleanisRoot()Is this the root group?com.google.common.collect.ImmutableList<Dimension>makeDimensionsList(String dimString)Create a dimension list using dimension names.GroupmakeRelativeGroup(NetcdfFile ncf, String path, boolean ignorelast)Deprecated.will move to dap2 in ver6booleanremove(Attribute a)Deprecated.Use Group.builder()booleanremove(Dimension d)Deprecated.Use Group.builder()booleanremove(Group g)Deprecated.Use Group.builder()booleanremove(Variable v)Deprecated.Use Group.builder()booleanremoveAttribute(String attName)Deprecated.Use Group.builder()booleanremoveAttributeIgnoreCase(String attName)Deprecated.Use Group.builder()booleanremoveDimension(String dimName)Deprecated.Use Group.builder()booleanremoveVariable(String shortName)Deprecated.Use Group.builder()GroupsetImmutable()Deprecated.Use Group.builder()StringsetName(String shortName)Deprecated.Use Group.builder()voidsetParentGroup(Group parent)Deprecated.Use Group.builder()Group.BuildertoBuilder()Turn into a mutable Builder.StringtoString()StringwriteCDL(boolean strict)Deprecated.use CDLWriter-
Methods inherited from class ucar.nc2.CDMNode
annotate, annotation, getDODSName, getFullNameEscaped, getGroup, getImmutable, getName, getParentStructure, getShortName, getSort, isMemberOfStructure, localhash, setDODSName, setParentStructure, setShortName, setSort, unwrap
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ucar.nc2.AttributeContainer
findAttValueIgnoreCase, getName, hasAttribute, hasAttributeIgnoreCase, iterator
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
ncfile
protected NetcdfFile ncfile
-
attributes
protected AttributeContainer attributes
-
enumTypedefs
protected List<EnumTypedef> enumTypedefs
-
-
Constructor Detail
-
Group
@Deprecated public Group(NetcdfFile ncfile, Group parent, String shortName)
Deprecated.Use Group.builder()Constructor- Parameters:
ncfile- NetcdfFile owns this Groupparent- parent of Group. If null, this is the root Group.shortName- short name of Group.
-
-
Method Detail
-
isRoot
public boolean isRoot()
Is this the root group?- Returns:
- true if root group
-
getVariables
public List<Variable> getVariables()
Get the Variables contained directly in this group.- Returns:
- List of type Variable; may be empty, not null. TODO return ImmutableList
-
findVariable
@Deprecated @Nullable public Variable findVariable(String varShortName)
Deprecated.use findVariableLocal()
-
findVariableLocal
@Nullable public Variable findVariableLocal(String varShortName)
Find the Variable with the specified (short) name in this group.- Parameters:
varShortName- short name of Variable within this group.- Returns:
- the Variable, or null if not found
-
findVariableOrInParent
@Nullable public Variable findVariableOrInParent(String varShortName)
Find the Variable with the specified (short) name in this group or a parent group.- Parameters:
varShortName- short name of Variable.- Returns:
- the Variable, or null if not found
-
findVariableByAttribute
@Nullable public Variable findVariableByAttribute(String attName, String attValue)
Look in this Group and in its nested Groups for a Variable with a String valued Attribute with the given name and value.- Parameters:
attName- look for an Attribuite with this name.attValue- look for an Attribuite with this value.- Returns:
- the first Variable that matches, or null if none match.
-
getParentGroup
@Nullable public Group getParentGroup()
Get the parent Group, or null if its the root group. Not deprecated.- Overrides:
getParentGroupin classCDMNode- Returns:
- parent Group
-
getFullName
public String getFullName()
Get the full name of this object. Certain characters are backslash escaped (see NetcdfFiles.getFullName(Group)) Not deprecated.- Overrides:
getFullNamein classCDMNode- Returns:
- full name with backslash escapes
-
getGroups
public com.google.common.collect.ImmutableList<Group> getGroups()
Get the Groups contained directly in this Group.- Returns:
- List of type Group; may be empty, not null.
-
getNetcdfFile
public NetcdfFile getNetcdfFile()
Get the owning NetcdfFile
-
findGroupLocal
@Nullable public Group findGroupLocal(String groupShortName)
Retrieve the Group with the specified (short) name.- Parameters:
groupShortName- short name of the nested group you are looking for.- Returns:
- the Group, or null if not found
-
findGroup
@Deprecated public Group findGroup(String groupShortName)
Deprecated.use findGroupLocal()
-
getDimensions
public List<Dimension> getDimensions()
Get the shared Dimensions contained directly in this group.- Returns:
- List of type Dimension; may be empty, not null. TODO return ImmutableList
-
makeDimensionsList
public com.google.common.collect.ImmutableList<Dimension> makeDimensionsList(String dimString) throws IllegalArgumentException
Create a dimension list using dimension names. The dimension is searched for recursively in the parent groups.- Parameters:
dimString- : whitespace separated list of dimension names, or '*' for Dimension.UNKNOWN, or number for anon dimension. null or empty String is a scalar.- Returns:
- list of dimensions, will return ImmutableList<> in version 6
- Throws:
IllegalArgumentException- if cant find dimension or parse error.
-
getEnumTypedefs
public com.google.common.collect.ImmutableList<EnumTypedef> getEnumTypedefs()
Get the enumerations contained directly in this group.- Returns:
- List of type EnumTypedef; may be empty, not null.
-
findDimension
@Nullable public Dimension findDimension(String name)
Find a Dimension in this or a parent Group, matching on short name.- Parameters:
name- Dimension name.- Returns:
- the Dimension, or null if not found
-
findDimension
@Nullable public Dimension findDimension(Dimension dim)
Find a Dimension in this or a parent Group, using equals.- Parameters:
dim- Dimension .- Returns:
- the Dimension, or null if not found
-
findDimensionLocal
@Nullable public Dimension findDimensionLocal(String shortName)
Find a Dimension using its (short) name, in this group only- Parameters:
shortName- Dimension name.- Returns:
- the Dimension, or null if not found
-
attributes
public AttributeContainer attributes()
The attributes contained by this Group.
-
findAttribute
@Nullable public Attribute findAttribute(String name)
Find the attribute by name, return null if not exist- Specified by:
findAttributein interfaceAttributeContainer
-
findAttributeString
public String findAttributeString(String attName, String defaultValue)
Find a String-valued Attribute by name (ignore case), return the String value of the Attribute.- Specified by:
findAttributeStringin interfaceAttributeContainer- Returns:
- the attribute value, or defaultValue if not found
-
getAttributes
@Deprecated public List<Attribute> getAttributes()
Deprecated.Use attributes()Description copied from interface:AttributeContainerReturns immutable list of attributes.- Specified by:
getAttributesin interfaceAttributeContainer
-
isEmpty
public boolean isEmpty()
Deprecated.Use attributes()Description copied from interface:AttributeContainerTrue is there are no attributes in the container.- Specified by:
isEmptyin interfaceAttributeContainer
-
findAttributeIgnoreCase
@Deprecated public Attribute findAttributeIgnoreCase(String name)
Deprecated.Use findAttributeString()Description copied from interface:AttributeContainerFind an Attribute by name, first doing an exact match, then ignoring case.- Specified by:
findAttributeIgnoreCasein interfaceAttributeContainer
-
findAttributeDouble
@Deprecated public double findAttributeDouble(String attName, double defaultValue)
Deprecated.Use attributes().findAttributeDouble()Description copied from interface:AttributeContainerFind a Numeric Attribute by name (ignore case), return the double value of the Attribute.- Specified by:
findAttributeDoublein interfaceAttributeContainer- Returns:
- the attribute value, or defaultValue if not found
-
findAttributeInteger
@Deprecated public int findAttributeInteger(String attName, int defaultValue)
Deprecated.Use attributes().findAttributeInteger()Description copied from interface:AttributeContainerFind a Numeric Attribute by name (ignore case), return the integer value of the Attribute.- Specified by:
findAttributeIntegerin interfaceAttributeContainer- Returns:
- the attribute value, or defaultValue if not found
-
addAttribute
@Deprecated public Attribute addAttribute(Attribute att)
Deprecated.Use Group.builder()Description copied from interface:AttributeContainerAdd new or replace old if has same name- Specified by:
addAttributein interfaceAttributeContainer- Parameters:
att- add this Attribute- Returns:
- the added attribute
-
addAll
@Deprecated public void addAll(Iterable<Attribute> atts)
Deprecated.Use Group.builder()Description copied from interface:AttributeContainerAdd all; replace old if has same name- Specified by:
addAllin interfaceAttributeContainer
-
remove
@Deprecated public boolean remove(Attribute a)
Deprecated.Use Group.builder()Description copied from interface:AttributeContainerRemove an Attribute : uses the attribute hashCode to find it.- Specified by:
removein interfaceAttributeContainer- Parameters:
a- remove this attribute- Returns:
- true if was found and removed
-
removeAttribute
@Deprecated public boolean removeAttribute(String attName)
Deprecated.Use Group.builder()Description copied from interface:AttributeContainerRemove an Attribute by name.- Specified by:
removeAttributein interfaceAttributeContainer- Parameters:
attName- if exists, remove this attribute- Returns:
- true if was found and removed
-
removeAttributeIgnoreCase
@Deprecated public boolean removeAttributeIgnoreCase(String attName)
Deprecated.Use Group.builder()Description copied from interface:AttributeContainerRemove an Attribute by name, ignoring case- Specified by:
removeAttributeIgnoreCasein interfaceAttributeContainer- Parameters:
attName- if exists, remove this attribute- Returns:
- true if was found and removed
-
findEnumeration
@Nullable public EnumTypedef findEnumeration(String name)
Find a Enumeration in this or a parent Group, using its short name.
-
commonParent
public Group commonParent(Group other)
Get the common parent of this and the other group. Cant fail, since the root group is always a parent of any 2 groups.- Parameters:
other- the other group- Returns:
- common parent of this and the other group
-
isParent
public boolean isParent(Group other)
Is this a parent of the other Group?- Parameters:
other- another Group- Returns:
- true is it is equal or a parent
-
getNameAndAttributes
public String getNameAndAttributes()
Get String with name and attributes. Used in short descriptions like tooltips.- Returns:
- name and attributes String.
-
writeCDL
@Deprecated public String writeCDL(boolean strict)
Deprecated.use CDLWriterCDL representation.- Parameters:
strict- if true, write in strict adherence to CDL definition.- Returns:
- CDL representation.
-
setParentGroup
@Deprecated public void setParentGroup(Group parent)
Deprecated.Use Group.builder()Set the Group's parent Group- Overrides:
setParentGroupin classCDMNode- Parameters:
parent- parent group.
-
setName
@Deprecated public String setName(String shortName)
Deprecated.Use Group.builder()Set the short name, converting to valid CDM object name if needed.- Parameters:
shortName- set to this value- Returns:
- valid CDM object name
-
addDimension
@Deprecated public void addDimension(Dimension dim)
Deprecated.Use Group.builder()Adds the specified shared dimension to this group.- Parameters:
dim- the dimension to add.- Throws:
IllegalStateException- if this dimension isimmutable.IllegalArgumentException- ifdimisn't shared or a dimension withdim's name already exists within the group.
-
addDimensionIfNotExists
@Deprecated public boolean addDimensionIfNotExists(Dimension dim)
Deprecated.Use Group.builder()Adds the specified shared dimension to this group, but only if another dimension with the same name doesn't already exist.- Parameters:
dim- the dimension to add.- Returns:
trueifdimwas successfully added to the group. Otherwise,falsewill be returned, meaning that a dimension withdim's name already exists within the group.- Throws:
IllegalStateException- if this dimension isimmutable.IllegalArgumentException- ifdimisn't shared.
-
addGroup
@Deprecated public void addGroup(Group g)
Deprecated.Use Group.builder()Add a nested Group- Parameters:
g- add this Group.
-
addEnumeration
@Deprecated public void addEnumeration(EnumTypedef e)
Deprecated.Use Group.builder()Add an Enumeration- Parameters:
e- add this Enumeration.
-
addVariable
@Deprecated public void addVariable(Variable v)
Deprecated.Use Group.builder()Add a Variable- Parameters:
v- add this Variable.
-
remove
@Deprecated public boolean remove(Dimension d)
Deprecated.Use Group.builder()Remove an Dimension : uses the dimension hashCode to find it.- Parameters:
d- remove this Dimension.- Returns:
- true if was found and removed
-
remove
@Deprecated public boolean remove(Group g)
Deprecated.Use Group.builder()Remove an Attribute : uses the Group hashCode to find it.- Parameters:
g- remove this Group.- Returns:
- true if was found and removed
-
remove
@Deprecated public boolean remove(Variable v)
Deprecated.Use Group.builder()Remove a Variable : uses the variable hashCode to find it.- Parameters:
v- remove this Variable.- Returns:
- true if was found and removed
-
removeDimension
@Deprecated public boolean removeDimension(String dimName)
Deprecated.Use Group.builder()remove a Dimension using its name, in this group only- Parameters:
dimName- Dimension name.- Returns:
- true if dimension found and removed
-
removeVariable
@Deprecated public boolean removeVariable(String shortName)
Deprecated.Use Group.builder()remove a Variable using its (short) name, in this group only- Parameters:
shortName- Variable name.- Returns:
- true if Variable found and removed
-
setImmutable
@Deprecated public Group setImmutable()
Deprecated.Use Group.builder()Make this immutable.- Overrides:
setImmutablein classCDMNode- Returns:
- this
-
equals
public boolean equals(Object oo)
Instances which have same name and parent are equal.
-
hashCode
public int hashCode()
Override Object.hashCode() to implement equals.
-
makeRelativeGroup
@Deprecated public Group makeRelativeGroup(NetcdfFile ncf, String path, boolean ignorelast)
Deprecated.will move to dap2 in ver6Create groups to ensure path is defined- Parameters:
ncf- the containing netcdf file objectpath- the path to the desired groupignorelast- true => ignore last element in the path- Returns:
- the Group, or null if not found
-
toBuilder
public Group.Builder toBuilder()
Turn into a mutable Builder. Can use toBuilder().build() to copy.
-
builder
public static Group.Builder builder()
-
-