ucar.nc2
Class Group

java.lang.Object
  extended by ucar.nc2.Group

public class Group
extends Object

A Group is a logical collection of Variables. 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.

Author:
caron

Field Summary
protected  List<Attribute> attributes
           
protected  List<Dimension> dimensions
           
protected  List<EnumTypedef> enumTypedefs
           
protected  List<Group> groups
           
protected  NetcdfFile ncfile
           
protected  Group parent
           
protected  String shortName
           
protected  List<Variable> variables
           
 
Constructor Summary
Group(NetcdfFile ncfile, Group parent, String shortName)
          Constructor
 
Method Summary
 void addAttribute(Attribute att)
          Add new Attribute; replace old if has same name.
 void addDimension(Dimension d)
          Add a shared Dimension
 void addEnumeration(EnumTypedef e)
          Add an Enumeration
 void addGroup(Group g)
          Add a nested Group
 void addVariable(Variable v)
          Add a Variable
 Group commonParent(Group other)
          Get the common parent of this and the other group.
 boolean equals(Object oo)
          Instances which have same name and parent are equal.
 Attribute findAttribute(String name)
          Find an Attribute in this Group by its name.
 Attribute findAttributeIgnoreCase(String name)
          Find an Attribute in this Group by its name, ignore case.
 Dimension findDimension(String name)
          Retrieve a Dimension using its (short) name.
 Dimension findDimensionLocal(String name)
          Retrieve a Dimension using its (short) name, in this group only
 EnumTypedef findEnumeration(String name)
          Find an Enumeration Typedef using its (short) name.
 Group findGroup(String groupShortName)
          Retrieve the Group with the specified (short) name.
 Variable findVariable(String varShortName)
          Find the Variable with the specified (short) name in this group.
 Variable findVariableOrInParent(String varShortName)
          Find the Variable with the specified (short) name in this group or a parent group.
 List<Attribute> getAttributes()
          Get the set of attributes contained directly in this Group.
 List<Dimension> getDimensions()
          Get the Dimensions contained directly in this group.
 List<EnumTypedef> getEnumTypedefs()
          Get the enumerations contained directly in this group.
 List<Group> getGroups()
          Get the Groups contained directly in this Group.
 String getName()
          Get the full name, starting from the root Group.
 String getNameAndAttributes()
          Get String with name and attributes.
 NetcdfFile getNetcdfFile()
          Get the owning NetcdfFile
 Group getParentGroup()
          Get its parent Group, or null if its the root group.
 String getShortName()
          Get the "short" name, unique within its parent Group.
 List<Variable> getVariables()
          Get the Variables contained directly in this group.
 int hashCode()
          Override Object.hashCode() to implement equals.
 boolean isParent(Group other)
          Is this a parent of the other Group?
 boolean isRoot()
          Is this the root group?
 boolean remove(Attribute a)
          Remove an Attribute : uses the attribute hashCode to find it.
 boolean remove(Dimension d)
          Remove an Dimension : uses the dimension hashCode to find it.
 boolean remove(Group g)
          Remove an Attribute : uses the Group hashCode to find it.
 boolean remove(Variable v)
          Remove a Variable : uses the variable hashCode to find it.
 boolean removeDimension(String dimName)
          remove a Dimension using its name, in this group only
 boolean removeVariable(String shortName)
          remove a Variable using its (short) name, in this group only
 Group setImmutable()
          Make this immutable.
 String setName(String shortName)
          Set the short name, converting to valid CDM object name if needed.
 void setParentGroup(Group parent)
          Set the Group's parent Group
 String toString()
           
protected  void writeCDL(PrintWriter out, String indent, boolean strict)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ncfile

protected NetcdfFile ncfile

parent

protected Group parent

shortName

protected String shortName

variables

protected List<Variable> variables

dimensions

protected List<Dimension> dimensions

groups

protected List<Group> groups

attributes

protected List<Attribute> attributes

enumTypedefs

protected List<EnumTypedef> enumTypedefs
Constructor Detail

Group

public Group(NetcdfFile ncfile,
             Group parent,
             String shortName)
Constructor

Parameters:
ncfile - NetcdfFile owns this Group
parent - parent of Group. If null, this is the root Group.
shortName - short name of Group.
Method Detail

getName

public String getName()
Get the full name, starting from the root Group.

Returns:
group full name

isRoot

public boolean isRoot()
Is this the root group?

Returns:
true if root group

getShortName

public String getShortName()
Get the "short" name, unique within its parent Group.

Returns:
group short name

getParentGroup

public Group getParentGroup()
Get its parent Group, or null if its the root group.

Returns:
parent Group

getVariables

public List<Variable> getVariables()
Get the Variables contained directly in this group.

Returns:
List of type Variable; may be empty, not null.

findVariable

public Variable findVariable(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

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

getGroups

public List<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

Returns:
owning NetcdfFile.

findGroup

public Group findGroup(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

getDimensions

public List<Dimension> getDimensions()
Get the Dimensions contained directly in this group.

Returns:
List of type Dimension; may be empty, not null.

getEnumTypedefs

public List<EnumTypedef> getEnumTypedefs()
Get the enumerations contained directly in this group.

Returns:
List of type EnumTypedef; may be empty, not null.

findDimension

public Dimension findDimension(String name)
Retrieve a Dimension using its (short) name. If it doesnt exist in this group, recursively look in parent groups.

Parameters:
name - Dimension name.
Returns:
the Dimension, or null if not found

findDimensionLocal

public Dimension findDimensionLocal(String name)
Retrieve a Dimension using its (short) name, in this group only

Parameters:
name - Dimension name.
Returns:
the Dimension, or null if not found

getAttributes

public List<Attribute> getAttributes()
Get the set of attributes contained directly in this Group.

Returns:
List of type Attribute; may be empty, not null.

findAttribute

public Attribute findAttribute(String name)
Find an Attribute in this Group by its name.

Parameters:
name - the name of the attribute.
Returns:
the attribute, or null if not found

findAttributeIgnoreCase

public Attribute findAttributeIgnoreCase(String name)
Find an Attribute in this Group by its name, ignore case.

Parameters:
name - the name of the attribute
Returns:
the attribute, or null if not found

findEnumeration

public EnumTypedef findEnumeration(String name)
Find an Enumeration Typedef using its (short) name. If it doesnt exist in this group, recursively look in parent groups.

Parameters:
name - Enumeration name.
Returns:
the Enumeration, or null if not found

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

protected void writeCDL(PrintWriter out,
                        String indent,
                        boolean strict)

setParentGroup

public void setParentGroup(Group parent)
Set the Group's parent Group

Parameters:
parent - parent group.

setName

public String setName(String shortName)
Set the short name, converting to valid CDM object name if needed.

Parameters:
shortName - set to this value
Returns:
valid CDM object name

addAttribute

public void addAttribute(Attribute att)
Add new Attribute; replace old if has same name.

Parameters:
att - add this Attribute.

addDimension

public void addDimension(Dimension d)
Add a shared Dimension

Parameters:
d - add this Dimension

addGroup

public void addGroup(Group g)
Add a nested Group

Parameters:
g - add this Group.

addEnumeration

public void addEnumeration(EnumTypedef e)
Add an Enumeration

Parameters:
e - add this Enumeration.

addVariable

public void addVariable(Variable v)
Add a Variable

Parameters:
v - add this Variable.

remove

public boolean remove(Attribute a)
Remove an Attribute : uses the attribute hashCode to find it.

Parameters:
a - remove this Attribute.
Returns:
true if was found and removed

remove

public boolean remove(Dimension d)
Remove an Dimension : uses the dimension hashCode to find it.

Parameters:
d - remove this Dimension.
Returns:
true if was found and removed

remove

public boolean remove(Group g)
Remove an Attribute : uses the Group hashCode to find it.

Parameters:
g - remove this Group.
Returns:
true if was found and removed

remove

public boolean remove(Variable v)
Remove a Variable : uses the variable hashCode to find it.

Parameters:
v - remove this Variable.
Returns:
true if was found and removed

removeDimension

public boolean removeDimension(String dimName)
remove a Dimension using its name, in this group only

Parameters:
dimName - Dimension name.
Returns:
true if dimension found and removed

removeVariable

public boolean removeVariable(String shortName)
remove a Variable using its (short) name, in this group only

Parameters:
shortName - Variable name.
Returns:
true if Variable found and removed

setImmutable

public Group setImmutable()
Make this immutable.

Returns:
this

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object oo)
Instances which have same name and parent are equal.

Overrides:
equals in class Object

hashCode

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

Overrides:
hashCode in class Object


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