Exemplo n.º 1
1
  // Communications
  public void updateStatus(InputStream in) throws IOException {
    DataInputStream din = new DataInputStream(in);
    if (builder.length() != 0) {
      builder.delete(0, builder.length());
    }

    eventTotal.setText(form.format(new Long(din.readLong())));
    dataTotal.setText(Util.convertBytes(builder, din.readLong(), true).toString());
    builder.delete(0, builder.length());
    dataRate.setText(Util.convertBytesRate(builder, din.readDouble(), true).toString());
    eventRate.setText(form.format(new Integer((int) din.readDouble())) + "e/s");
  }
Exemplo n.º 2
0
 @ExposedClassMethod(doc = BuiltinDocs.float___getformat___doc)
 public static String float___getformat__(PyType type, String typestr) {
   if ("double".equals(typestr)) {
     return double_format.format();
   } else if ("float".equals(typestr)) {
     return float_format.format();
   } else {
     throw Py.ValueError("__getformat__() argument 1 must be 'double' or 'float'");
   }
 }
  /**
   * Returns a String representation of the Object <code>value</code>. This invokes <code>format
   * </code> on the current <code>Format</code>.
   *
   * @throws ParseException if there is an error in the conversion
   * @param value Value to convert
   * @return String representation of value
   */
  public String valueToString(Object value) throws ParseException {
    if (value == null) {
      return "";
    }
    Format f = getFormat();

    if (f == null) {
      return value.toString();
    }
    return f.format(value);
  }
Exemplo n.º 4
0
  public void solve1216(int kaseno) throws Exception {
    int r1 = iread(), r2 = iread(), h = iread(), p = iread();

    double R1 = (double) r2;
    double R2 = ((double) ((r1 - r2) * p)) / h;
    R2 += r2;
    double H = (double) p;

    double ret = pii * (R1 * R1 + R2 * R2 + R1 * R2) * H;
    ret /= 3.;
    Format df = new DecimalFormat("0.0000000000");
    String res = df.format(ret);
    out.write("Case " + kaseno + ": " + res + "\n");
  }
Exemplo n.º 5
0
  /**
   * Changes the output of all probes to the specified file. This method may be called multiple
   * times during the execution of the JVM.
   *
   * @param pathname the pathname of the output file.
   */
  public static void setOutput(String pathname) {

    // open specified file
    PrintStream previous = outputStream;
    try {
      outputStream = new PrintStream(new FileOutputStream(pathname));
    } catch (FileNotFoundException e) {
      // if file cannot be opened, output remains unchanged
      return;
    }

    // close previous output if not standard output
    if (previous != null && !previous.equals(System.out)) {
      previous.close();
    }

    // print date and time
    Format format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    outputStream.println("Starting on " + format.format(new Date()));
  }
Exemplo n.º 6
0
 @Override
 public String toString() {
   return format.format(value, unsigned);
 }
Exemplo n.º 7
0
 public String get(Number value) {
   return format.format(value);
 }
Exemplo n.º 8
0
 /**
  * 패턴에 따라 String을 리턴해줌
  *
  * @return ex) toFormat("123456",*.FORMAT_INT) => "123,456"
  */
 public String get(String str) {
   return format.format(Strings.getDoubleValue(str));
 }
Exemplo n.º 9
0
  public static int format(
      Format fmt,
      Object[] args,
      int start,
      Writer dst,
      char padChar,
      int minWidth,
      int colInc,
      int minPad,
      int where,
      FieldPosition fpos)
      throws java.io.IOException {
    /*
       if (where == 100)
         {
    int oldLength = sbuf.length();
    fmt.format(obj, sbuf, fpos);
    int newLength = sbuf.length();
    int pad = padNeeded(newLength - oldLength, minWidth, colInc, minPad);
    while (--pad >= 0)
      sbuf.append(padChar);
    return start + ?;
         }
       */

    StringBuffer tbuf = new StringBuffer(200);
    if (fmt instanceof ReportFormat) start = ((ReportFormat) fmt).format(args, start, tbuf, fpos);
    else if (fmt instanceof MessageFormat) {
      // FIXME - only correct if start == 0.
      fmt.format(args, tbuf, fpos);
      start = args.length;
    } else {
      fmt.format(args[start], tbuf, fpos);
      start++;
    }
    int len = tbuf.length();
    int pad = padNeeded(len, minWidth, colInc, minPad);
    int prefix = 0;
    String text = tbuf.toString();
    if (pad > 0) {
      if (where == -1) {
        if (len > 0) {
          char ch = text.charAt(0);
          if (ch == '-' || ch == '+') {
            prefix++;
            dst.write(ch);
          }
          if (len - prefix > 2 && text.charAt(prefix) == '0') {
            dst.write('0');
            ch = text.charAt(++prefix);
            if (ch == 'x' || ch == 'X') {
              prefix++;
              dst.write(ch);
            }
          }
          if (prefix > 0) text = text.substring(prefix);
        }
        where = 0;
      }
      int padAfter = (pad * where) / 100;
      int padBefore = pad - padAfter;
      /*
      if (fpos != null && padBefore > 0)
        {
          // This is still broken in JDK 1.2 beta2.  Check beta3.  FIXME.
          fpos.setBeginIndex(fpos.getBeginIndex() + padBefore);
          fpos.setEndIndex(fpos.getEndIndex() + padBefore);
        }
      */
      while (--padBefore >= 0) dst.write(padChar);
      dst.write(text);
      while (--padAfter >= 0) dst.write(padChar);
    } else {
      dst.write(text);
    }
    return start;
  }
  private StringBuffer formatInternal(
      Object arguments[],
      StringBuffer appendBuf,
      FieldPosition fp,
      FormatCharacterIterator output_iterator) {
    appendBuf.append(leader);
    if (output_iterator != null) output_iterator.append(leader);

    for (int i = 0; i < elements.length; ++i) {
      Object thisArg = null;
      boolean unavailable = false;
      if (arguments == null || elements[i].argNumber >= arguments.length) unavailable = true;
      else thisArg = arguments[elements[i].argNumber];

      AttributedCharacterIterator iterator = null;

      Format formatter = null;

      if (fp != null && i == fp.getField() && fp.getFieldAttribute() == Field.ARGUMENT)
        fp.setBeginIndex(appendBuf.length());

      if (unavailable) appendBuf.append("{" + elements[i].argNumber + "}");
      else {
        if (elements[i].setFormat != null) formatter = elements[i].setFormat;
        else if (elements[i].format != null) {
          if (elements[i].formatClass != null && !elements[i].formatClass.isInstance(thisArg))
            throw new IllegalArgumentException("Wrong format class");

          formatter = elements[i].format;
        } else if (thisArg instanceof Number) formatter = NumberFormat.getInstance(locale);
        else if (thisArg instanceof Date)
          formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
        else appendBuf.append(thisArg);
      }

      if (fp != null && fp.getField() == i && fp.getFieldAttribute() == Field.ARGUMENT)
        fp.setEndIndex(appendBuf.length());

      if (formatter != null) {
        // Special-case ChoiceFormat.
        if (formatter instanceof ChoiceFormat) {
          StringBuffer buf = new StringBuffer();
          formatter.format(thisArg, buf, fp);
          MessageFormat mf = new MessageFormat();
          mf.setLocale(locale);
          mf.applyPattern(buf.toString());
          mf.format(arguments, appendBuf, fp);
        } else {
          if (output_iterator != null) iterator = formatter.formatToCharacterIterator(thisArg);
          else formatter.format(thisArg, appendBuf, fp);
        }

        elements[i].format = formatter;
      }

      if (output_iterator != null) {
        HashMap hash_argument = new HashMap();
        int position = output_iterator.getEndIndex();

        hash_argument.put(MessageFormat.Field.ARGUMENT, new Integer(elements[i].argNumber));

        if (iterator != null) {
          output_iterator.append(iterator);
          output_iterator.addAttributes(hash_argument, position, output_iterator.getEndIndex());
        } else output_iterator.append(thisArg.toString(), hash_argument);

        output_iterator.append(elements[i].trailer);
      }

      appendBuf.append(elements[i].trailer);
    }

    return appendBuf;
  }