List of usage examples for java.util Formatter Formatter
public Formatter(OutputStream os)
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8Schema.java
public static String getDateString(Calendar val) { if (val == null) { return ("null"); } else {//from w ww . ja v a 2s .c om StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append("'"); return (buff.toString()); } }
From source file:com.itemanalysis.psychometrics.irt.estimation.JointMaximumLikelihoodEstimation.java
/** * This method is for displaying person parameter estimates, standard errors, and other information. * It will display statistic for every examinee. * @return/*from w w w . j av a 2 s . c o m*/ */ public String printPersonStats() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("%12s", "Sum Score"); f.format("%12s", "Theta"); f.format("%12s", "Std. Error"); f.format("%12s", "Extreme"); f.format("%n"); f.format("%50s", "--------------------------------------------------"); f.format("%n"); for (int i = 0; i < nPeople; i++) { f.format("%12.2f", sumScore[i]); f.format("%12.2f", theta[i]); f.format("%12.2f", thetaStdError[i]); if (extremePerson[i] == -1) { f.format("%12s", "MINIMUM"); } else if (extremePerson[i] == 1) { f.format("%12s", "MAXIMUM"); } else { f.format("%12s", ""); } f.format("%n"); } f.format("%50s", "--------------------------------------------------"); f.format("%n"); return f.toString(); }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8Schema.java
public static String getTimeString(Calendar val) { if (val == null) { return ("null"); } else {//from w w w .j a v a 2s . co m StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append("'"); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8Schema.java
public static String getTimestampString(Calendar val) { if (val == null) { return ("null"); } else {/*from w ww.j a v a2 s . com*/ StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append("'"); return (buff.toString()); } }
From source file:com.itemanalysis.psychometrics.irt.estimation.JointMaximumLikelihoodEstimation.java
/** * This method is for displaying item parameter estimates, standard errors, and other information. * * @return// ww w. java2 s .co m */ public String printBasicItemStats(String title) { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); int maxCat = 0; for (int j = 0; j < nItems; j++) { maxCat = Math.max(irm[j].getNcat(), maxCat); } f.format("%40s", title); f.format("%n"); String line1 = "========================================================"; int lineLength = 44; if (maxCat > 2) { for (int k = 0; k < maxCat - 1; k++) { line1 += "============"; lineLength += 12; } } f.format("%" + lineLength + "s", line1); f.format("%n"); f.format("%20s", "Name"); f.format("%12s", "Difficulty"); f.format("%12s", "Std. Error"); if (maxCat > 2) { for (int k = 0; k < maxCat - 1; k++) { f.format("%12s", "step" + (k + 1)); } } f.format("%12s", "Extreme"); f.format("%n"); String line = "--------------------------------------------------------"; lineLength = 44; if (maxCat > 2) { for (int k = 0; k < maxCat - 1; k++) { line += "------------"; lineLength += 12; } } f.format("%" + lineLength + "s", line); f.format("%n"); for (int j = 0; j < nItems; j++) { f.format("%20s", irm[j].getName()); if (droppedStatus[j] == 0) { f.format("%12.2f", irm[j].getDifficulty()); f.format("%12.2f", irm[j].getDifficultyStdError()); if (irm[j].getNcat() > 2) { double[] t = irm[j].getThresholdParameters(); for (int k = 0; k < t.length; k++) { f.format("%12.2f", t[k]); } } if (itemSummary[j].isExtremeMaximum()) { f.format("%12s", "MAXIMUM"); } else if (itemSummary[j].isExtremeMinimum()) { f.format("%12s", "MINIMUM"); } else { f.format("%12s", ""); } f.format("%n"); if (irm[j].getNcat() > 2) { String id = irm[j].getGroupId(); double[] tse = rsg.get(id).getThresholdStandardError(); f.format("%44s", ""); for (int k = 0; k < tse.length; k++) { f.format("%12.2f", tse[k]); } f.format("%n"); } } else { f.format("%12s", "DROPPED"); f.format("%n"); } } f.format("%" + lineLength + "s", line1); f.format("%n"); return f.toString(); }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8Schema.java
public static String getTZDateString(Calendar val) { if (val == null) { return ("null"); } else {//from w w w. j av a2 s . c om StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append(" CST"); buff.append("'"); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8Schema.java
public static String getTZTimeString(Calendar val) { if (val == null) { return ("null"); } else {// w w w .ja va 2 s. c om StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append(" CST"); buff.append("'"); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8Schema.java
public static String getTZTimestampString(Calendar val) { if (val == null) { return ("null"); } else {//from www .ja v a2 s . co m StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append(" CST"); buff.append("'"); return (buff.toString()); } }
From source file:com.itemanalysis.psychometrics.irt.estimation.JointMaximumLikelihoodEstimation.java
/** * Joint maximum likelihood estimation is iterative. An iteration history is saved. The history includes * the largest change in logits and the log-likelihood at each iteration. This method provides a string * representation of the iteration history. * * @return a summary of the iteration history. *//*from w w w. j a v a 2s . c o m*/ public String printIterationHistory() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); int index = 0; f.format("%10s", "Iteration"); f.format("%5s", ""); f.format("%17s", "Delta"); f.format("%5s", ""); f.format("%20s", "Log-likelihood"); f.format("%n"); f.format("%62s", "--------------------------------------------------------------"); f.format("%n"); for (IterationRecord ir : iterationHistory) { f.format("%10s", ++index); f.format("%5s", ""); f.format("%42s", ir.toString()); f.format("%n"); } f.format("%62s", "--------------------------------------------------------------"); f.format("%n"); return f.toString(); }
From source file:org.apache.hadoop.dfs.Balancer.java
/** main method of Balancer * @param args arguments to a Balancer/*from w w w .j a v a2 s . com*/ * @exception any exception occurs during datanode balancing */ public int run(String[] args) throws Exception { long startTime = FSNamesystem.now(); OutputStream out = null; try { // initialize a balancer init(parseArgs(args)); /* Check if there is another balancer running. * Exit if there is another one running. */ out = checkAndMarkRunningBalancer(); 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 " + FsShell.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 " + FsShell.byteDesc(bytesToMove) + "bytes in this iteration"); } formatter.format("%-24s %10d %19s %18s %17s\n", DateFormat.getDateTimeInstance().format(new Date()), iterations, FsShell.byteDesc(bytesMoved.get()), FsShell.byteDesc(bytesLeftToMove), FsShell.byteDesc(bytesToMove)); /* For each pair of <source, target>, start a thread that repeatedly * decide a block to be moved and its proxy source, * then initiates the move until all bytes are moved or no more block * available to move. * Exit no byte has been moved for 5 consecutive iterations. */ if (dispatchBlockMoves() > 0) { notChangedIterations = 0; } else { notChangedIterations++; if (notChangedIterations >= 5) { System.out.println("No block has been moved for 5 iterations. Exiting..."); return NO_MOVE_PROGRESS; } } // clean all lists resetData(); try { Thread.sleep(2 * conf.getLong("dfs.heartbeat.interval", 3)); } catch (InterruptedException ignored) { } iterations++; } } catch (IllegalArgumentException ae) { return ILLEGAL_ARGS; } catch (IOException e) { System.out.println("Received an IO exception: " + e.getMessage() + " . Exiting..."); return IO_EXCEPTION; } finally { // shutdown thread pools dispatcherExecutor.shutdownNow(); moverExecutor.shutdownNow(); // close the output file IOUtils.closeStream(out); try { fs.delete(BALANCER_ID_PATH, true); } catch (IOException ignored) { } System.out.println("Balancing took " + time2Str(FSNamesystem.now() - startTime)); } }