/** * Gets a variable's absolute path name. The dot character '.' is used to separate groups. * * @param variable the entry to get the name from * @return The absolute path name. */ public static String getAbsoluteName(final Variable variable) { final StringBuilder sb = new StringBuilder(variable.getName()); Group group = variable.getParentGroup(); while (group != null) { final String groupName = group.getName(); if (groupName.length() > 0) { sb.insert(0, '.'); sb.insert(0, groupName); } group = group.getParentGroup(); } return sb.toString(); } }
static public String getDAPName(String name, Variable context) { if (RC.getUseGroups()) { // leave off leading '/' for root entries Group xg = context.getParentGroup(); if (!xg.isRoot()) { // Get the list of parent groups List<Group> path = Group.collectPath(xg); Formatter dapname = new Formatter(); for (int i = 1; i < path.size(); i++) { // start at 1 to skip root group Group g = path.get(i); dapname.format("/%s", g.getShortName()); } dapname.format("/%s", name); name = dapname.toString(); } } return name; }
static public String getDAPName(String name, Variable context) { if (RC.getUseGroups()) { // leave off leading '/' for root entries Group xg = context.getParentGroup(); if (!xg.isRoot()) { // Get the list of parent groups List<Group> path = Group.collectPath(xg); Formatter dapname = new Formatter(); for (int i = 1; i < path.size(); i++) { // start at 1 to skip root group Group g = path.get(i); dapname.format("/%s", g.getShortName()); } dapname.format("/%s", name); name = dapname.toString(); } } return name; }
public Variable deleteVariable(String fullName) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); Variable v = ncfile.findVariable(fullName); if (v != null) ncfile.removeVariable(v.getParentGroup(), v.getShortName()); return v; }
static public String getDAPName(String name, Variable context) { if(RC.getUseGroups()) { // leave off leading '/' for root entries Group xg = context.getParentGroup(); if(!xg.isRoot()) { // Get the list of parent groups List<Group> path = Group.collectPath(xg); StringBuilder dapname = new StringBuilder(); for(int i=1;i<path.size();i++) { // start at 1 to skip root group Group g = path.get(i); dapname.append("/"+g.getShortName()); } dapname.append("/" + name); name = dapname.toString(); } } return name; }
/** * Set the dimensions using the dimensions names. The dimension is searched for recursively in the parent groups. * * @param dimString : whitespace separated list of dimension names, or '*' for Dimension.UNKNOWN, or number for anon dimension. null or empty String is a scalar. */ public void setDimensions(String dimString) { if (immutable) throw new IllegalStateException("Cant modify"); try { this.dimensions = Dimension.makeDimensionsList(getParentGroup(), dimString); resetShape(); } catch (IllegalStateException e) { throw new IllegalArgumentException("Variable " + getFullName() + " setDimensions = '" + dimString + "' FAILED: " + e.getMessage() + " file = " + getDatasetLocation()); } }
/** * Reset the dimension array. Anonymous dimensions are left alone. * Shared dimensions are searched for recursively in the parent groups. */ public void resetDimensions() { if (immutable) throw new IllegalStateException("Cant modify"); ArrayList<Dimension> newDimensions = new ArrayList<Dimension>(); for (Dimension dim : dimensions) { if (dim.isShared()) { Dimension newD = getParentGroup().findDimension(dim.getShortName()); if (newD == null) throw new IllegalArgumentException("Variable " + getFullName() + " resetDimensions FAILED, dim doesnt exist in parent group=" + dim); newDimensions.add(newD); } else { newDimensions.add( dim); } } this.dimensions = newDimensions; resetShape(); }
/** * Reset the dimension array. Anonymous dimensions are left alone. * Shared dimensions are searched for recursively in the parent groups. */ public void resetDimensions() { if (immutable) throw new IllegalStateException("Cant modify"); ArrayList<Dimension> newDimensions = new ArrayList<>(); for (Dimension dim : dimensions) { if (dim.isShared()) { Dimension newD = getParentGroup().findDimension(dim.getShortName()); if (newD == null) throw new IllegalArgumentException("Variable " + getFullName() + " resetDimensions FAILED, dim doesnt exist in parent group=" + dim); newDimensions.add(newD); } else { newDimensions.add(dim); } } this.dimensions = newDimensions; resetShape(); }
/** * Reset the dimension array. Anonymous dimensions are left alone. * Shared dimensions are searched for recursively in the parent groups. */ public void resetDimensions() { if (immutable) throw new IllegalStateException("Cant modify"); ArrayList<Dimension> newDimensions = new ArrayList<>(); for (Dimension dim : dimensions) { if (dim.isShared()) { Dimension newD = getParentGroup().findDimension(dim.getShortName()); if (newD == null) throw new IllegalArgumentException("Variable " + getFullName() + " resetDimensions FAILED, dim doesnt exist in parent group=" + dim); newDimensions.add(newD); } else { newDimensions.add(dim); } } this.dimensions = newDimensions; resetShape(); }
/** * Set the dimensions using the dimensions names. The dimension is searched for recursively in the parent groups. * * @param dimString : whitespace separated list of dimension names, or '*' for Dimension.UNKNOWN, or number for anon dimension. null or empty String is a scalar. */ public void setDimensions(String dimString) { if (immutable) throw new IllegalStateException("Cant modify"); try { setDimensions(Dimension.makeDimensionsList(getParentGroup(), dimString)); //this.dimensions = Dimension.makeDimensionsList(getParentGroup(), dimString); resetShape(); } catch (IllegalStateException e) { throw new IllegalArgumentException("Variable " + getFullName() + " setDimensions = '" + dimString + "' FAILED: " + e.getMessage() + " file = " + getDatasetLocation()); } }
public void hashCodeShow(Indent indent) { System.out.printf("%sVar hash = %d%n", indent, hashCode()); System.out.printf("%s shortName %s = %d%n", indent, getShortName(), getShortName().hashCode()); System.out.printf("%s isScalar %s%n", indent, isScalar()); System.out.printf("%s dataType %s%n", indent, getDataType()); System.out.printf("%s parentGroup %s = %d%n", indent, getParentGroup(), getParentGroup().hashCode()); System.out.printf("%s isVariableLength %s%n", indent, isVariableLength); System.out.printf("%s dimensions %d len=%d%n", indent, dimensions.hashCode(), dimensions.size()); indent.incr(); for (Dimension d : dimensions) { d.hashCodeShow(indent); } indent.decr(); if (getParentStructure() != null) { System.out.printf("%s parentStructure %d%n", indent, getParentStructure().hashCode()); getParentStructure().hashCodeShow(indent.incr()); indent.decr(); } }
public void hashCodeShow(Indent indent) { System.out.printf("%sVar hash = %d%n", indent, hashCode()); System.out.printf("%s shortName %s = %d%n", indent, getShortName(), getShortName().hashCode()); System.out.printf("%s isScalar %s%n", indent, isScalar()); System.out.printf("%s dataType %s%n", indent, getDataType()); System.out.printf("%s parentGroup %s = %d%n", indent, getParentGroup(), getParentGroup().hashCode()); System.out.printf("%s isVariableLength %s%n", indent, isVariableLength); System.out.printf("%s dimensions %d len=%d%n", indent, dimensions.hashCode(), dimensions.size()); indent.incr(); for (Dimension d : dimensions) { d.hashCodeShow(indent); } indent.decr(); if (getParentStructure() != null) { System.out.printf("%s parentStructure %d%n", indent, getParentStructure().hashCode()); getParentStructure().hashCodeShow(indent.incr()); indent.decr(); } }
public void testDataset() { Variable v = ncfile.findVariable("lflx"); assert v instanceof VariableDS; VariableDS vds = (VariableDS) v; assert vds.getOriginalDataType() == v.getDataType(); Variable org = vds.getOriginalVariable(); assert vds.getOriginalDataType() == org.getDataType(); assert !(org instanceof VariableDS); assert v.getParentGroup().equals(org.getParentGroup()); assert v.getParentGroup() != org.getParentGroup(); }
public void testDataset() { Variable v = ncfile.findVariable("ReletiveHumidity"); assert v instanceof VariableDS; VariableDS vds = (VariableDS) v; assert vds.getOriginalDataType() == v.getDataType(); Variable org = vds.getOriginalVariable(); assert vds.getOriginalDataType() == org.getDataType(); assert v.getParentGroup().equals(org.getParentGroup()); assert v.getParentGroup() != org.getParentGroup(); // its a VariableDS because the renaming causes a VariableDS wrapper. assert (org instanceof VariableDS); vds = (VariableDS) org; org = vds.getOriginalVariable(); assert vds.getOriginalDataType() == org.getDataType(); assert !(org instanceof VariableDS); assert v.getParentGroup().equals(org.getParentGroup()); assert v.getParentGroup() != org.getParentGroup(); }
/** * Override Object.hashCode() to implement equals. */ public int hashCode() { if(CDMNode.OBJECTHASH) return super.hashCode(); else { if (hashCode == 0) { int result = 17; result = 37 * result + getShortName().hashCode(); if (isScalar()) result++; result = 37 * result + getDataType().hashCode(); result = 37 * result + getParentGroup().hashCode(); if (getParentStructure() != null) result = 37 * result + getParentStructure().hashCode(); if (isVariableLength) result++; result = 37 * result + dimensions.hashCode(); hashCode = result; } return hashCode; } }
/** * Override Object.hashCode() to implement equals. */ @Override public int hashCode() { if (hashCode == 0) { int result = 17; result = 37 * result + getShortName().hashCode(); if (isScalar()) result++; result = 37 * result + getDataType().hashCode(); result = 37 * result + getParentGroup().hashCode(); if (getParentStructure() != null) result = 37 * result + getParentStructure().hashCode(); if (isVariableLength) result++; result = 37 * result + dimensions.hashCode(); hashCode = result; } return hashCode; }
/** * Override Object.hashCode() to implement equals. */ @Override public int hashCode() { if (hashCode == 0) { int result = 17; result = 37 * result + getShortName().hashCode(); if (isScalar()) result++; result = 37 * result + getDataType().hashCode(); result = 37 * result + getParentGroup().hashCode(); if (getParentStructure() != null) result = 37 * result + getParentStructure().hashCode(); if (isVariableLength) result++; result = 37 * result + dimensions.hashCode(); hashCode = result; } return hashCode; }
/** * Instances which have same content are equal. */ public boolean equals(Object oo) { if (this == oo) return true; if (!(oo instanceof Variable)) return false; Variable o = (Variable) oo; if (!getShortName().equals(o.getShortName())) return false; if (isScalar() != o.isScalar()) return false; if (getDataType() != o.getDataType()) return false; if (!getParentGroup().equals(o.getParentGroup())) return false; if ((getParentStructure() != null) && !getParentStructure().equals(o.getParentStructure())) return false; if (isVariableLength() != o.isVariableLength()) return false; if (dimensions.size() != o.getDimensions().size()) return false; for (int i=0; i<dimensions.size(); i++) if (!getDimension(i).equals(o.getDimension(i))) return false; return true; }
/** * Instances which have same content are equal. */ public boolean equals(Object oo) { if (this == oo) return true; if (!(oo instanceof Variable)) return false; Variable o = (Variable) oo; if (!getShortName().equals(o.getShortName())) return false; if (isScalar() != o.isScalar()) return false; if (getDataType() != o.getDataType()) return false; if (!getParentGroup().equals(o.getParentGroup())) return false; if ((getParentStructure() != null) && !getParentStructure().equals(o.getParentStructure())) return false; if (isVariableLength() != o.isVariableLength()) return false; if (dimensions.size() != o.getDimensions().size()) return false; for (int i = 0; i < dimensions.size(); i++) if (!getDimension(i).equals(o.getDimension(i))) return false; return true; }
/** * Instances which have same content are equal. */ public boolean equals(Object oo) { if (this == oo) return true; if (!(oo instanceof Variable)) return false; Variable o = (Variable) oo; if (!getShortName().equals(o.getShortName())) return false; if (isScalar() != o.isScalar()) return false; if (getDataType() != o.getDataType()) return false; if (!getParentGroup().equals(o.getParentGroup())) return false; if ((getParentStructure() != null) && !getParentStructure().equals(o.getParentStructure())) return false; if (isVariableLength() != o.isVariableLength()) return false; if (dimensions.size() != o.getDimensions().size()) return false; for (int i = 0; i < dimensions.size(); i++) if (!getDimension(i).equals(o.getDimension(i))) return false; return true; }