@Test public void testWriteCDL() { Map<Integer, String> map = ImmutableMap.of(1, "name1", 2, "name2", 3, "name3"); EnumTypedef typedef = new EnumTypedef("typeName", map); assertThat(typedef.toString()).isEqualTo("enum typeName { 'name1' = 1, 'name2' = 2, 'name3' = 3};"); EnumTypedef typedef1 = new EnumTypedef("typeName", map, DataType.ENUM1); assertThat(typedef1.toString()).isEqualTo("byte enum typeName { 'name1' = 1, 'name2' = 2, 'name3' = 3};"); EnumTypedef typedef2 = new EnumTypedef("typeName", map, DataType.ENUM2); assertThat(typedef2.toString()).isEqualTo("short enum typeName { 'name1' = 1, 'name2' = 2, 'name3' = 3};"); }
void writeCDL(Formatter out, Indent indent, boolean strict) { String name = strict ? NetcdfFiles.makeValidCDLName(this.name) : this.name; String basetype = ""; switch (this.basetype) { case ENUM1: basetype = "byte "; break; case ENUM2: basetype = "short "; break; case ENUM4: basetype = ""; break; default: assert false : "Internal error"; } out.format("%s%senum %s { ", indent, basetype, name); int count = 0; List<Integer> keysetList = new ArrayList<>(map.keySet()); Collections.sort(keysetList); for (Integer key : keysetList) { String s = map.get(key); if (0 < count++) out.format(", "); if (strict) out.format("%s = %s", NetcdfFiles.makeValidCDLName(s), key); else out.format("'%s' = %s", s, key); } out.format("};"); }
EnumTypedef { void writeCDL(Formatter out, Indent indent, boolean strict) { String name = strict ? NetcdfFiles.makeValidCDLName(this.name) : this.name; String basetype = ""; switch (this.basetype) { case ENUM1: basetype = "byte "; break; case ENUM2: basetype = "short "; break; case ENUM4: basetype = ""; break; default: assert false : "Internal error"; } out.format("%s%senum %s { ", indent, basetype, name); int count = 0; List<Integer> keysetList = new ArrayList<>(map.keySet()); Collections.sort(keysetList); for (Integer key : keysetList) { String s = map.get(key); if (0 < count++) out.format(", "); if (strict) out.format("%s = %s", NetcdfFiles.makeValidCDLName(s), key); else out.format("'%s' = %s", s, key); } out.format("};"); } }
EnumTypedef { void writeCDL(Formatter out, Indent indent, boolean strict) { String name = strict ? NetcdfFiles.makeValidCDLName(this.name) : this.name; String basetype = ""; switch (this.basetype) { case ENUM1: basetype = "byte "; break; case ENUM2: basetype = "short "; break; case ENUM4: basetype = ""; break; default: assert false : "Internal error"; } out.format("%s%senum %s { ", indent, basetype, name); int count = 0; List<Integer> keysetList = new ArrayList<>(map.keySet()); Collections.sort(keysetList); for (Integer key : keysetList) { String s = map.get(key); if (0 < count++) out.format(", "); if (strict) out.format("%s = %s", NetcdfFiles.makeValidCDLName(s), key); else out.format("'%s' = %s", s, key); } out.format("};"); } EnumTypedef(String name, Map<Integer, String> map);  EnumTypedef(String name, Map<Integer, String> map, DataType basetype); }
EnumTypedef { void writeCDL(Formatter out, Indent indent, boolean strict) { String name = strict ? NetcdfFiles.makeValidCDLName(this.name) : this.name; String basetype = ""; switch (this.basetype) { case ENUM1: basetype = "byte "; break; case ENUM2: basetype = "short "; break; case ENUM4: basetype = ""; break; default: assert false : "Internal error"; } out.format("%s%senum %s { ", indent, basetype, name); int count = 0; List<Integer> keysetList = new ArrayList<>(map.keySet()); Collections.sort(keysetList); for (Integer key : keysetList) { String s = map.get(key); if (0 < count++) out.format(", "); if (strict) out.format("%s = %s", NetcdfFiles.makeValidCDLName(s), key); else out.format("'%s' = %s", s, key); } out.format("};"); } EnumTypedef(String name, Map<Integer, String> map);  EnumTypedef(String name, Map<Integer, String> map, DataType basetype); DataType getBaseType(); String getShortName(); ImmutableMap<Integer, String> getMap(); @Nullable Integer lookupEnumInt(String name); @Nullable String lookupEnumString(int e); @Override boolean equals(Object o); boolean equalsMapOnly(Object o); @Override int hashCode(); @Override String toString(); }
EnumTypedef { void writeCDL(Formatter out, Indent indent, boolean strict) { String name = strict ? NetcdfFiles.makeValidCDLName(this.name) : this.name; String basetype = ""; switch (this.basetype) { case ENUM1: basetype = "byte "; break; case ENUM2: basetype = "short "; break; case ENUM4: basetype = ""; break; default: assert false : "Internal error"; } out.format("%s%senum %s { ", indent, basetype, name); int count = 0; List<Integer> keysetList = new ArrayList<>(map.keySet()); Collections.sort(keysetList); for (Integer key : keysetList) { String s = map.get(key); if (0 < count++) out.format(", "); if (strict) out.format("%s = %s", NetcdfFiles.makeValidCDLName(s), key); else out.format("'%s' = %s", s, key); } out.format("};"); } EnumTypedef(String name, Map<Integer, String> map);  EnumTypedef(String name, Map<Integer, String> map, DataType basetype); DataType getBaseType(); String getShortName(); ImmutableMap<Integer, String> getMap(); @Nullable Integer lookupEnumInt(String name); @Nullable String lookupEnumString(int e); @Override boolean equals(Object o); boolean equalsMapOnly(Object o); @Override int hashCode(); @Override String toString();  }