println(out,"    ,"+fexpr);
println(out,"    "+fexpr+",");
    void writeClass(PrintWriter out, String context, String className) {      String isDep = p.get(context,"deprecated");      if (isDep!=null) {        println(out,"/** @deprecated "+isDep+" **/");      }      String ext = p.get(context,"extends");      if (ext == null) ext = "AbstractMeasure";      boolean isFinal = !("false".equals(p.get(context,"final")));      println(out,"public "+                  (isFinal?"final ":"")+                  "class "+className+" extends "+ext+" implements Externalizable {");      // get units      List<String> units = getUnitV(context);      String base = getBaseUnit(context);      String baseabbrev = p.get(context, "baseabbrev");      if (baseabbrev == null) baseabbrev=base;            // write static factors      println(out,"  // Conversion factor constants");      for (String unit : units) {        if (! unit.equals(base)) {          // f is the factor of (1 unit) = f * (1 baseunit);          String fact1 = toConstantName(base+"_PER_"+unit);          String fromf = computeFromFactor(context,unit);          println(out,"  public static final double "+fact1+" = "+fromf+";");          String fact2 = toConstantName(unit+"_PER_"+base);          String tof = computeToFactor(context,unit);          println(out,"  public static final double "+fact2+" = "+tof+";");        }      }      println(out);      // the storage      println(out,"  // the value is stored as "+base);      println(out,"  private double theValue;");      println(out);      println(out,"  /** No-arg constructor is only for use by serialization **/");      println(out,"  public "+className+"() {}");      println(out);      // constructor      println(out,"  // private constructor");      println(out,"  private "+className+"(double v) {");      println(out,"    theValue = v;");      println(out,"  }");      println(out);      // public constructor      println(out,"  /** parameterized constructor **/");      println(out,"  public "+className+"(double v, int unit) {");      println(out,"    if (unit >= 0 && unit <= MAXUNIT)");      println(out,"      theValue = v*convFactor[unit];");      println(out,"    else");      println(out,"      throw new UnknownUnitException();");      println(out,"  }");      println(out);      println(out,"  /** takes strings of the form \"Number unit\" **/");      println(out,"  public "+className+"(String s) {");      println(out,"    int i = indexOfType(s);");      println(out,"    if (i < 0) throw new UnknownUnitException();");      println(out,"    double n = Double.valueOf(s.substring(0,i).trim()).doubleValue();");      println(out,"    String u = s.substring(i).trim().toLowerCase();");      print(out,"    ");      for (String unit : units) {        String unitName = toClassName(unit);        String fexpr="";        if (!unit.equals(base)) {          fexpr = "*"+toConstantName(base+"_PER_"+unit);        }        println(out,"if (u.equals(\""+unitName.toLowerCase()+"\")) ");        println(out,"      theValue=n"+fexpr+";");        print(out,"    else ");      }      println(out,"\n      throw new UnknownUnitException();");      println(out,"  }");      println(out);      // Named type factory methods      println(out,"  // TypeNamed factory methods");      for (String unit : units) {        String unitName = toClassName(unit);        String fexpr="";        if (!unit.equals(base)) {          fexpr = "*"+toConstantName(base+"_PER_"+unit);        }        println(out,"  public static final "+className+" new"+unitName+"(double v) {");        println(out,"    return new "+className+"(v"+fexpr+");");        println(out,"  }");        println(out,"  public static final "+className+" new"+unitName+"(String s) {");        println(out,"    return new "+className+"((Double.valueOf(s).doubleValue())"+fexpr+");");        println(out,"  }");      }      println(out);      // common unit support - mostly a bogon      println(out);      println(out,"  public int getCommonUnit() {");      String cus = p.get(context, "common");      if (cus == null) {         println(out,"    return 0;");      } else {                println(out,"    return "+cus.toUpperCase()+";");      }      println(out,"  }");      println(out);      println(out,"  public int getMaxUnit() { return MAXUNIT; }");      println(out);      println(out,"  // unit names for getUnitName");      println(out,"  private static final String unitNames[]={");      for (String unit : units) {        println(out,"    \""+unit+"\",");      }      println(out,"  };");      println(out);      println(out,"  public String getUnitName(int unit) {");      println(out,"    return unitNames[unit];");      println(out,"  }");      println(out);      // index typed factory methods      println(out,"  // Index Typed factory methods");      println(out,"  static final double convFactor[]={");      for (String unit : units) {        String fexpr="1.0";        if (!unit.equals(base)) {          fexpr = toConstantName(base+"_PER_"+unit);        }        println(out,"    ,"+fexpr);      }      println(out,"  };");      println(out,"  // indexes into factor array");      int i = 0;      for (String unit : units) {        String unitName = toConstantName(unit);        println(out,"  public static final int "+unitName+" = "+i+";");        i++;      }      println(out,"  public static final int MAXUNIT = "+(i-1)+";");      println(out);      println(out,"  // Index Typed factory methods");      println(out,"  public static final "+className+" new"+className+"(double v, int unit) {");      println(out,"    if (unit >= 0 && unit <= MAXUNIT)");      println(out,"      return new "+className+"(v*convFactor[unit]);");      println(out,"    else");      println(out,"      throw new UnknownUnitException();");      println(out,"  }");      println(out);      println(out,"  public static final "+className+" new"+className+"(String s, int unit) {");      println(out,"    if (unit >= 0 && unit <= MAXUNIT)");      println(out,"      return new "+className+"((Double.valueOf(s).doubleValue())*convFactor[unit]);");      println(out,"    else");      println(out,"      throw new UnknownUnitException();");      println(out,"  }");      println(out);      // abstractmeasure-level concretefactory      println(out,"  // Support for AbstractMeasure-level constructor");      println(out,"  public static final AbstractMeasure newMeasure(String s, int unit) {");      println(out,"    return new"+className+"(s, unit);");      println(out,"  }");      println(out,"  public static final AbstractMeasure newMeasure(double v, int unit) {");      println(out,"    return new"+className+"(v, unit);");      println(out,"  }");      // getters      println(out,"  // Unit-based Reader methods");      for (String unit : units) {        String unitName = toClassName(unit);        String fexpr="";        if (!unit.equals(base)) {          //fexpr = "*"+toConstantName(unit+"_PER_"+base);          fexpr = "/"+toConstantName(base+"_PER_"+unit);        }        println(out,"  public double get"+unitName+"() {");        println(out,"    return (theValue"+fexpr+");");        println(out,"  }");      }      println(out);      // unit-as-argument getter      println(out,"  public double getValue(int unit) {");      println(out,"    if (unit >= 0 && unit <= MAXUNIT)");      println(out,"      return (theValue/convFactor[unit]);");      println(out,"    else");      println(out,"      throw new UnknownUnitException();");      println(out,"  }");      println(out);      // equals et al      println(out,"  public boolean equals(Object o) {");      println(out,"    return ( o instanceof "+className+" &&");      println(out,"             theValue == (("+className+") o).theValue);");      println(out,"  }");      println(out,"  public String toString() {");      println(out,"    return Double.toString(theValue) + \""+                  baseabbrev+"\";");      println(out,"  }");      println(out,"  public int hashCode() {");      println(out,"    return (new Double(theValue)).hashCode();");      println(out,"  }");      println(out);      println(out,"  // serialization");      println(out,"  public void writeExternal(ObjectOutput out) throws IOException {\n"+                  "    out.writeDouble(theValue);\n"+                  "  }");      println(out,"  public void readExternal(ObjectInput in) throws IOException {\n"+                  "    theValue = in.readDouble();\n"+                  "  }");      // that's all, folks      println(out,"}");    }