@Test public void testFindAttribute() { Variable.Builder<?> vb = Variable.builder().setName("varName").setDataType(DataType.STRING) .addAttribute(new Attribute("attName", "nestedGroupVariable")); Group.Builder nested = Group.builder().setName("child").addAttribute(new Attribute("attName", "nestedGroup")).addVariable(vb); Group.Builder rootb = Group.builder().setName("").addAttribute(new Attribute("attName", "rootGroup")).addGroup(nested); NetcdfFile.Builder<?> builder = NetcdfFile.builder().setId("Hid").setLocation("location").setRootGroup(rootb).setTitle("title"); NetcdfFile ncfile = builder.build(); Attribute att = ncfile.findAttribute("@attName"); assertThat(att).isNotNull(); assertThat(att.getStringValue()).isEqualTo("rootGroup"); att = ncfile.findAttribute("/@attName"); assertThat(att).isNotNull(); assertThat(att.getStringValue()).isEqualTo("rootGroup"); att = ncfile.findAttribute("attName"); assertThat(att).isNull(); att = ncfile.findAttribute("/child/@attName"); assertThat(att).isNotNull(); assertThat(att.getStringValue()).isEqualTo("nestedGroup"); att = ncfile.findAttribute("child/@attName"); assertThat(att).isNotNull(); assertThat(att.getStringValue()).isEqualTo("nestedGroup"); att = ncfile.findAttribute("/child/varName@attName"); assertThat(att).isNotNull(); assertThat(att.getStringValue()).isEqualTo("nestedGroupVariable"); att = ncfile.findAttribute("child/varName@attName"); assertThat(att).isNotNull(); assertThat(att.getStringValue()).isEqualTo("nestedGroupVariable"); }
@Nullable public Attribute findAttribute(String fullNameEscaped) { if (fullNameEscaped == null || fullNameEscaped.isEmpty()) { return null; } int posAtt = fullNameEscaped.indexOf('@'); if (posAtt < 0 || posAtt >= fullNameEscaped.length() - 1) return null; if (posAtt == 0) { return findGlobalAttribute(fullNameEscaped.substring(1)); } String path = fullNameEscaped.substring(0, posAtt); String attName = fullNameEscaped.substring(posAtt + 1); Group g = rootGroup; int pos = path.lastIndexOf('/'); String varName = (pos > 0 && pos < path.length() - 1) ? path.substring(pos + 1) : null; if (pos >= 0) { String groups = path.substring(0, pos); StringTokenizer stoke = new StringTokenizer(groups, "/"); while (stoke.hasMoreTokens()) { String token = NetcdfFiles.makeNameUnescaped(stoke.nextToken()); g = g.findGroupLocal(token); if (g == null) return null; } } if (varName == null) return g.findAttribute(attName); List<String> snames = EscapeStrings.tokenizeEscapedName(varName); if (snames.isEmpty()) return null; String varShortName = NetcdfFiles.makeNameUnescaped(snames.get(0)); Variable v = g.findVariableLocal(varShortName); if (v == null) return null; int memberCount = 1; while (memberCount < snames.size()) { if (!(v instanceof Structure)) return null; String name = NetcdfFiles.makeNameUnescaped(snames.get(memberCount++)); v = ((Structure) v).findVariable(name); if (v == null) return null; } return v.findAttribute(attName); }
NetcdfFile implements FileCacheable, Closeable { @Nullable public Attribute findAttribute(String fullNameEscaped) { if (fullNameEscaped == null || fullNameEscaped.isEmpty()) { return null; } int posAtt = fullNameEscaped.indexOf('@'); if (posAtt < 0 || posAtt >= fullNameEscaped.length() - 1) return null; if (posAtt == 0) { return findGlobalAttribute(fullNameEscaped.substring(1)); } String path = fullNameEscaped.substring(0, posAtt); String attName = fullNameEscaped.substring(posAtt + 1); Group g = rootGroup; int pos = path.lastIndexOf('/'); String varName = (pos > 0 && pos < path.length() - 1) ? path.substring(pos + 1) : null; if (pos >= 0) { String groups = path.substring(0, pos); StringTokenizer stoke = new StringTokenizer(groups, "/"); while (stoke.hasMoreTokens()) { String token = NetcdfFiles.makeNameUnescaped(stoke.nextToken()); g = g.findGroupLocal(token); if (g == null) return null; } } if (varName == null) return g.findAttribute(attName); List<String> snames = EscapeStrings.tokenizeEscapedName(varName); if (snames.isEmpty()) return null; String varShortName = NetcdfFiles.makeNameUnescaped(snames.get(0)); Variable v = g.findVariableLocal(varShortName); if (v == null) return null; int memberCount = 1; while (memberCount < snames.size()) { if (!(v instanceof Structure)) return null; String name = NetcdfFiles.makeNameUnescaped(snames.get(memberCount++)); v = ((Structure) v).findVariable(name); if (v == null) return null; } return v.findAttribute(attName); } }
NetcdfFile implements FileCacheable, Closeable { @Nullable public Attribute findAttribute(String fullNameEscaped) { if (fullNameEscaped == null || fullNameEscaped.isEmpty()) { return null; } int posAtt = fullNameEscaped.indexOf('@'); if (posAtt < 0 || posAtt >= fullNameEscaped.length() - 1) return null; if (posAtt == 0) { return findGlobalAttribute(fullNameEscaped.substring(1)); } String path = fullNameEscaped.substring(0, posAtt); String attName = fullNameEscaped.substring(posAtt + 1); Group g = rootGroup; int pos = path.lastIndexOf('/'); String varName = (pos > 0 && pos < path.length() - 1) ? path.substring(pos + 1) : null; if (pos >= 0) { String groups = path.substring(0, pos); StringTokenizer stoke = new StringTokenizer(groups, "/"); while (stoke.hasMoreTokens()) { String token = NetcdfFiles.makeNameUnescaped(stoke.nextToken()); g = g.findGroupLocal(token); if (g == null) return null; } } if (varName == null) return g.findAttribute(attName); List<String> snames = EscapeStrings.tokenizeEscapedName(varName); if (snames.isEmpty()) return null; String varShortName = NetcdfFiles.makeNameUnescaped(snames.get(0)); Variable v = g.findVariableLocal(varShortName); if (v == null) return null; int memberCount = 1; while (memberCount < snames.size()) { if (!(v instanceof Structure)) return null; String name = NetcdfFiles.makeNameUnescaped(snames.get(memberCount++)); v = ((Structure) v).findVariable(name); if (v == null) return null; } return v.findAttribute(attName); } protected  NetcdfFile(Builder<?> builder); }
NetcdfFile implements FileCacheable, Closeable { @Nullable public Attribute findAttribute(String fullNameEscaped) { if (fullNameEscaped == null || fullNameEscaped.isEmpty()) { return null; } int posAtt = fullNameEscaped.indexOf('@'); if (posAtt < 0 || posAtt >= fullNameEscaped.length() - 1) return null; if (posAtt == 0) { return findGlobalAttribute(fullNameEscaped.substring(1)); } String path = fullNameEscaped.substring(0, posAtt); String attName = fullNameEscaped.substring(posAtt + 1); Group g = rootGroup; int pos = path.lastIndexOf('/'); String varName = (pos > 0 && pos < path.length() - 1) ? path.substring(pos + 1) : null; if (pos >= 0) { String groups = path.substring(0, pos); StringTokenizer stoke = new StringTokenizer(groups, "/"); while (stoke.hasMoreTokens()) { String token = NetcdfFiles.makeNameUnescaped(stoke.nextToken()); g = g.findGroupLocal(token); if (g == null) return null; } } if (varName == null) return g.findAttribute(attName); List<String> snames = EscapeStrings.tokenizeEscapedName(varName); if (snames.isEmpty()) return null; String varShortName = NetcdfFiles.makeNameUnescaped(snames.get(0)); Variable v = g.findVariableLocal(varShortName); if (v == null) return null; int memberCount = 1; while (memberCount < snames.size()) { if (!(v instanceof Structure)) return null; String name = NetcdfFiles.makeNameUnescaped(snames.get(memberCount++)); v = ((Structure) v).findVariable(name); if (v == null) return null; } return v.findAttribute(attName); } protected  NetcdfFile(Builder<?> builder); @Deprecated static void setDebugFlags(DebugFlags debugFlag); synchronized void close(); @Nullable Attribute findAttribute(String fullNameEscaped); @Nullable Dimension findDimension(String fullName); @Nullable Attribute findGlobalAttribute(String attName); @Nullable Attribute findGlobalAttributeIgnoreCase(String name); @Nullable Group findGroup(@Nullable String fullName); @Nullable Variable findVariable(String fullNameEscaped); ImmutableList<Dimension> getDimensions(); String getFileTypeId(); String getFileTypeDescription(); String getFileTypeVersion(); ImmutableList<Attribute> getGlobalAttributes(); String getLocation(); @Nullable String getId(); Group getRootGroup(); @Nullable String getTitle(); ImmutableList<Variable> getVariables(); @Nullable Dimension getUnlimitedDimension(); boolean hasUnlimitedDimension(); Array readSection(String variableSection); Object sendIospMessage(Object message); @Override String toString(); String toNcml(String url); void writeNcml(OutputStream os, String uri); void writeNcml(Writer writer, String uri); @Deprecated @Override long getLastModified(); @Deprecated void release(); @Deprecated void reacquire(); @Deprecated synchronized void setFileCache(FileCacheIF cache); @Deprecated String getDetailInfo(); @Deprecated void getDetailInfo(Formatter f); Builder<?> toBuilder(); static Builder<?> builder(); }
NetcdfFile implements FileCacheable, Closeable { @Nullable public Attribute findAttribute(String fullNameEscaped) { if (fullNameEscaped == null || fullNameEscaped.isEmpty()) { return null; } int posAtt = fullNameEscaped.indexOf('@'); if (posAtt < 0 || posAtt >= fullNameEscaped.length() - 1) return null; if (posAtt == 0) { return findGlobalAttribute(fullNameEscaped.substring(1)); } String path = fullNameEscaped.substring(0, posAtt); String attName = fullNameEscaped.substring(posAtt + 1); Group g = rootGroup; int pos = path.lastIndexOf('/'); String varName = (pos > 0 && pos < path.length() - 1) ? path.substring(pos + 1) : null; if (pos >= 0) { String groups = path.substring(0, pos); StringTokenizer stoke = new StringTokenizer(groups, "/"); while (stoke.hasMoreTokens()) { String token = NetcdfFiles.makeNameUnescaped(stoke.nextToken()); g = g.findGroupLocal(token); if (g == null) return null; } } if (varName == null) return g.findAttribute(attName); List<String> snames = EscapeStrings.tokenizeEscapedName(varName); if (snames.isEmpty()) return null; String varShortName = NetcdfFiles.makeNameUnescaped(snames.get(0)); Variable v = g.findVariableLocal(varShortName); if (v == null) return null; int memberCount = 1; while (memberCount < snames.size()) { if (!(v instanceof Structure)) return null; String name = NetcdfFiles.makeNameUnescaped(snames.get(memberCount++)); v = ((Structure) v).findVariable(name); if (v == null) return null; } return v.findAttribute(attName); } protected  NetcdfFile(Builder<?> builder); @Deprecated static void setDebugFlags(DebugFlags debugFlag); synchronized void close(); @Nullable Attribute findAttribute(String fullNameEscaped); @Nullable Dimension findDimension(String fullName); @Nullable Attribute findGlobalAttribute(String attName); @Nullable Attribute findGlobalAttributeIgnoreCase(String name); @Nullable Group findGroup(@Nullable String fullName); @Nullable Variable findVariable(String fullNameEscaped); ImmutableList<Dimension> getDimensions(); String getFileTypeId(); String getFileTypeDescription(); String getFileTypeVersion(); ImmutableList<Attribute> getGlobalAttributes(); String getLocation(); @Nullable String getId(); Group getRootGroup(); @Nullable String getTitle(); ImmutableList<Variable> getVariables(); @Nullable Dimension getUnlimitedDimension(); boolean hasUnlimitedDimension(); Array readSection(String variableSection); Object sendIospMessage(Object message); @Override String toString(); String toNcml(String url); void writeNcml(OutputStream os, String uri); void writeNcml(Writer writer, String uri); @Deprecated @Override long getLastModified(); @Deprecated void release(); @Deprecated void reacquire(); @Deprecated synchronized void setFileCache(FileCacheIF cache); @Deprecated String getDetailInfo(); @Deprecated void getDetailInfo(Formatter f); Builder<?> toBuilder(); static Builder<?> builder(); @Deprecated
  static final String IOSP_MESSAGE_ADD_RECORD_STRUCTURE; static final String IOSP_MESSAGE_RANDOM_ACCESS_FILE; static final String IOSP_MESSAGE_GET_IOSP; static final String IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT; }