Package java.util

Examples of java.util.Formatter$FormatSpecifier


    public static String getTimeString(DateTime date) {
        return getTimeString(date.getTime());
    }

    public static String getTimeString(long time) {
        return new Formatter().format("%020d", time).toString();
    }
View Full Code Here


        }
        return true;
    }

    private String wordProbToString(double[] prob) {
        Formatter formatter = new Formatter();
        for(int j=0;j<prob.length;++j) {
            double p = prob[j];
            if (p>=0.00001) {
                formatter.format(" %s:%.5f", langlist.get(j), p);
            }
        }
        String string = formatter.toString();
        formatter.close();
        return string;
    }
View Full Code Here

        int readLen;
        while ((readLen = str.read(buffer, 0, buffer.length)) != -1) {
            dgest.update(buffer, 0, readLen);
        }
        str.close();
        Formatter fmt = new Formatter();
        for (byte b : dgest.digest()) {
            fmt.format("%02X", b);
        }
        String result = fmt.toString();
        fmt.close();
        return result;
    }
View Full Code Here

    }
    int bucketWidth = (int)Math.ceil((float)(max - min) / height);
    int[] counts = count(bucketWidth, values);
    int maxCount = max(counts);
    StringBuilder out = new StringBuilder();
    Formatter formatter = new Formatter(out);
    formatter.format("%8d %" + width + "d", 0, maxCount);
    rows[0] = out.toString();
    for (int i = 0; i < counts.length; i++) {
      out.setLength(0);
      int bucketId = (int) (min + bucketWidth * i + bucketWidth / 2f);
      PieGraph pieGraph = new PieGraph(width, new CharMarker(marker.get(i, bucketId), ' '));
      String bar = pieGraph.render(counts[i], maxCount - counts[i]);
      formatter.format("%6d |%s:%6d", bucketId, bar, counts[i]);
      rows[i + 1] = out.toString();
    }
    return rows;
  }
View Full Code Here

      if (out == null) {
        System.out.println("Another balancer is running. Exiting...");
        return ALREADY_RUNNING;
      }

      Formatter formatter = new Formatter(System.out);
      System.out.println("Time Stamp               Iteration#  Bytes Already Moved  Bytes Left To Move  Bytes Being Moved");
      int iterations = 0;
      while (true ) {
        /* get all live datanodes of a cluster and their disk usage
         * decide the number of bytes need to be moved
         */
        long bytesLeftToMove = initNodes();
        if (bytesLeftToMove == 0) {
          System.out.println("The cluster is balanced. Exiting...");
          return SUCCESS;
        } else {
          LOG.info( "Need to move "+ StringUtils.byteDesc(bytesLeftToMove)
              +" bytes to make the cluster balanced." );
        }
       
        /* Decide all the nodes that will participate in the block move and
         * the number of bytes that need to be moved from one node to another
         * in this iteration. Maximum bytes to be moved per node is
         * Min(1 Band worth of bytes,  MAX_SIZE_TO_MOVE).
         */
        long bytesToMove = chooseNodes();
        if (bytesToMove == 0) {
          System.out.println("No block can be moved. Exiting...");
          return NO_MOVE_BLOCK;
        } else {
          LOG.info( "Will move " + StringUtils.byteDesc(bytesToMove) +
              "bytes in this iteration");
        }
  
        formatter.format("%-24s %10d  %19s  %18s  %17s\n",
            DateFormat.getDateTimeInstance().format(new Date()),
            iterations,
            StringUtils.byteDesc(bytesMoved.get()),
            StringUtils.byteDesc(bytesLeftToMove),
            StringUtils.byteDesc(bytesToMove)
View Full Code Here

  }
  public static int unlimited() {
    return -1;
  }
  public static String inKb(long bytes) {   
    return new Formatter().format("%(,.1fKb", (double)bytes/1024).toString();
  }
View Full Code Here

  }
  public static String inKb(long bytes) {   
    return new Formatter().format("%(,.1fKb", (double)bytes/1024).toString();
  }
  public static String inMb(long bytes) {   
    return new Formatter().format("%(,.1fMb", (double)bytes/1024/1024).toString();
  }
View Full Code Here

  }
  public static String inMb(long bytes) {   
    return new Formatter().format("%(,.1fMb", (double)bytes/1024/1024).toString();
  }
  public static String inGb(long bytes) {   
    return new Formatter().format("%(,.1fKb", (double)bytes/1024/1024/1024).toString();
  }
View Full Code Here

      /*
       * Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. TODO:
       * replace/compare to with Rewrite Encoding
       */
      StringBuilder outBuf = null;
      Formatter formatter = null;
      for (int i = 0; i < in.length(); i++)
      {
         char c = in.charAt(i);
         boolean escape = true;
         if (c < 128)
         {
            if (asciiQueryChars.get(c))
            {
               escape = false;
            }
         }
         else if (!Character.isISOControl(c) && !Character.isSpaceChar(c))
         {
            /*
             * not-ascii
             */
            escape = false;
         }
         if (!escape)
         {
            if (outBuf != null)
               outBuf.append(c);
         }
         else
         {
            /*
             * escape
             */
            if (outBuf == null)
            {
               outBuf = new StringBuilder(in.length() + 5 * 3);
               outBuf.append(in, 0, i);
               formatter = new Formatter(outBuf);
            }
            /*
             * leading %, 0 padded, width 2, capital hex
             */
            formatter.format("%%%02X", (int) c);// TODO
         }
      }
      return outBuf != null ? outBuf : in;
   }
View Full Code Here

    }

    @Override
    public String toString() {
        // Output into coordinate format. Indices start from 1 instead of 0
        Formatter out = new Formatter();

        out.format("%10d %10d %19d\n", numRows, numColumns, Matrices
                .cardinality(this));

        int i = 0;
        for (MatrixEntry e : this) {
            if (e.get() != 0)
                out.format("%10d %10d % .12e\n", e.row() + 1, e.column() + 1, e.get());
            if (++i == 100) {
                out.format("...\n");
                break;
            }
        }

        return out.toString();
    }
View Full Code Here

TOP

Related Classes of java.util.Formatter$FormatSpecifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.