示例#1
0
  public void parse(StringInputStream input) throws IOException {
    ArrayList<Double> l = new ArrayList<Double>();

    for (String v = input.getString().toLowerCase();
        !v.equals("/");
        v = input.getString().toLowerCase()) l.add(Double.valueOf(v));

    // copy to double array
    double[] array = new double[l.size()];
    for (int i = 0; i < array.length; i++) array[i] = l.get(i).doubleValue();

    config.putDoubleArray("dy", array);
  }
  private void outputConfiguration(Appendable str, String pre) throws IOException {
    StringBuilder output = MapConfiguration.output.get();
    for (String key : config.keySet()) {
      Object obj = config.get(key);

      if (obj instanceof String)
        str.append(pre).append(key).append(' ').append((String) obj).append('\n');
      else if (obj instanceof Array) {
        // write the type and size hints to output if the array is of a
        // native type (will optimize reading the array back in)
        String length = Integer.toString(Array.getLength(obj));
        if (obj instanceof double[]) {
          str.append(pre).append("double ").append(length).append(' ');
        } else if (obj instanceof int[]) {
          str.append(pre).append("int ").append(length).append(' ');
        }

        // all arrays have this prefix, regardless of type
        str.append(pre).append("array ").append(key).append('\n');

        if (obj instanceof double[]) {
          double[] array = (double[]) obj;
          for (int i = 0; i < array.length; ) {
            output.setLength(0);
            output.append(pre).append('\t');
            for (; i < array.length && output.length() < LINE_LENGTH; i++) {
              output.append(array[i]).append(' ');
            }
            output.append('\n');
            str.append(output);
          }
        } else if (obj instanceof int[]) {
          int[] array = (int[]) obj;
          for (int i = 0; i < array.length; ) {
            output.setLength(0);
            output.append(pre).append('\t');
            for (; i < array.length && output.length() < LINE_LENGTH; i++) {
              output.append(array[i]).append(' ');
            }
            output.append('\n');
            str.append(output);
          }
        } else { // if (obj instanceof String[]) {
          String[] array = (String[]) obj;
          for (int i = 0; i < array.length; ) {
            output.setLength(0);
            output.append(pre).append('\t');
            for (; i < array.length && output.length() < LINE_LENGTH; i++) {
              output.append(array[i]).append(' ');
            }
            output.append('\n');
            str.append(output);
          }
        }

        str.append(pre).append("end").append('\n');
      } else if (obj instanceof Configuration) {
        str.append(pre).append("begin ").append(key).append('\n');
        MapConfiguration sub = (MapConfiguration) obj;
        sub.outputConfiguration(str, pre + '\t');
        str.append(pre).append("end").append('\n');
      }
    }
  }