List of usage examples for java.util Formatter format
public Formatter format(String format, Object... args)
From source file:net.chrissearle.flickrvote.web.admin.ChallengeAction.java
@Override public String input() throws Exception { if (tag != null && !"".equals(tag)) { editFlag = true;//from w w w.j a va 2 s. c o m ChallengeSummary challengeSummary = challengeService.getChallengeSummary(tag); challenge = new ChallengeAdmin(); challenge.setTag(challengeSummary.getTag()); challenge.setTitle(challengeSummary.getTitle()); challenge.setStartDate(challengeSummary.getStartDate()); challenge.setNotes(challengeSummary.getNotes()); } else { // Set some defaults ChallengeSummary mostRecentChallenge = challengeService.getMostRecent(); if (mostRecentChallenge != null) { challenge = new ChallengeAdmin(); challenge.setStartDate(mostRecentChallenge.getVoteDate()); int numIndex = mostRecentChallenge.getTag().indexOf(FlickrVoteWebConstants.TAGPREFIX) + FlickrVoteWebConstants.TAGPREFIX.length(); int tagNum = Integer.valueOf(mostRecentChallenge.getTag().substring(numIndex)); StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.getDefault()); formatter.format(FlickrVoteWebConstants.TAGPREFIX + "%03d", tagNum + 1); challenge.setTag(sb.toString()); } } return INPUT; }
From source file:org.jasig.cas.monitor.EhCacheStatistics.java
@Override public void toString(final StringBuilder builder) { final String name = this.getName(); if (StringUtils.isNotBlank(name)) { builder.append(name).append(':'); }// w w w.j a v a 2 s.co m final int free = getPercentFree(); final Formatter formatter = new Formatter(builder); if (useBytes) { formatter.format("%.2f", heapSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE); builder.append("MB heap, "); formatter.format("%.2f", diskSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE); builder.append("MB disk, "); } else { builder.append(heapSize).append(" items in heap, "); builder.append(diskSize).append(" items on disk, "); } formatter.format("%.2f", offHeapSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE); builder.append("MB off-heap, "); builder.append(free).append("% free, "); builder.append(getEvictions()).append(" evictions"); formatter.close(); }
From source file:com.quarterfull.newsAndroid.VersionInfoDialogFragment.java
private String getVersionString() { String version = "?"; try {/*ww w .j ava 2 s . c o m*/ PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); version = pInfo.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Formatter formatter = new Formatter(); String versionString = getString(R.string.current_version); return formatter.format(versionString, version).toString(); }
From source file:org.efaps.ui.wicket.models.EmbeddedLink.java
/** * Getter method for the instance variable {@link #tag}. * * @return value of instance variable {@link #tag} */// w ww .j a va 2s. c o m public String getTag() { String ret = this.tag; final Formatter formatter = new Formatter(); formatter.format(ret, getId()); ret = formatter.toString(); formatter.close(); return ret; }
From source file:com.itemanalysis.psychometrics.factoranalysis.RotationResults.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); int nrow = L.getRowDimension(); int ncol = L.getColumnDimension(); f.format("%-40s", "Factor Loadings: " + rotationMethod.toString()); f.format("%n"); f.format("%40s", "========================================"); f.format("%n"); for (int i = 0; i < nrow; i++) { for (int j = 0; j < ncol; j++) { f.format("% 6.4f", L.getEntry(i, j)); f.format("%4s", ""); }/*from ww w. ja va2s.com*/ f.format("%n"); } f.format("%n"); f.format("%n"); f.format("%-30s", "Factor Correlations"); f.format("%n"); f.format("%30s", "=============================="); f.format("%n"); for (int i = 0; i < Phi.getRowDimension(); i++) { for (int j = 0; j < Phi.getColumnDimension(); j++) { f.format("% 6.4f", Phi.getEntry(i, j)); f.format("%4s", ""); } f.format("%n"); } f.format("%n"); return f.toString(); }
From source file:com.itemanalysis.psychometrics.measurement.ClassicalItemStatistics.java
/** * A string that contains all of the item statistics. * * @return string of estimated statistics *///from w w w . ja v a 2 s.c o m @Override public String toString() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("% 10.4f", getDifficulty()); f.format("%2s", " ");//category proportion endorsing f.format("% 10.4f", getStdDev()); f.format("%2s", " ");//category standard deviation f.format("% 10.4f", getDiscrimination()); f.format("%2s", " "); //item discrimination return f.toString(); }
From source file:ome.io.nio.AbstractFileSystemService.java
private String getPath(String prefix, Long id) { String suffix = ""; Long remaining = id;// ww w . j a v a 2 s . c o m Long dirno = 0L; if (id == null) { throw new NullPointerException("Expecting a not-null id."); } while (remaining > 999) { remaining /= 1000; if (remaining > 0) { Formatter formatter = new Formatter(); dirno = remaining % 1000; suffix = formatter.format("Dir-%03d", dirno).out().toString() + File.separator + suffix; } } String path = FilenameUtils.concat(root, prefix + suffix + id); return path; }
From source file:de.tudarmstadt.ukp.dkpro.core.performance.Stopwatch.java
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { super.collectionProcessComplete(); if (isDownstreamTimer()) { getLogger().info("Results from Timer '" + timerName + "' after processing all documents."); DescriptiveStatistics statTimes = new DescriptiveStatistics(); for (Long timeValue : times) { statTimes.addValue((double) timeValue / 1000); }/* ww w . ja va2 s.co m*/ double sum = statTimes.getSum(); double mean = statTimes.getMean(); double stddev = statTimes.getStandardDeviation(); StringBuilder sb = new StringBuilder(); sb.append("Estimate after processing " + times.size() + " documents."); sb.append("\n"); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("Aggregated time: %,.1fs\n", sum); formatter.format("Time / Document: %,.3fs (%,.3fs)\n", mean, stddev); formatter.close(); getLogger().info(sb.toString()); if (outputFile != null) { try { Properties props = new Properties(); props.setProperty(KEY_SUM, "" + sum); props.setProperty(KEY_MEAN, "" + mean); props.setProperty(KEY_STDDEV, "" + stddev); OutputStream out = new FileOutputStream(outputFile); props.store(out, "timer " + timerName + " result file"); } catch (FileNotFoundException e) { throw new AnalysisEngineProcessException(e); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } }
From source file:com.itemanalysis.psychometrics.reliability.ReliabilityInterval.java
public String print() { StringBuilder builder = new StringBuilder(); Formatter f = new Formatter(builder); String f2 = ""; if (precision == 2) { f2 = "%.2f"; } else if (precision == 4) { f2 = "%.4f"; }//w w w . ja va 2 s . c om f.format("%18s", "95% Confidence Interval: ("); f.format(f2, this.confidenceInterval()[0]); f.format("%2s", ", "); f.format(f2, this.confidenceInterval()[1]); f.format("%1s", ")"); return f.toString(); }
From source file:scenario.EncodingTest.java
@Test public void utf16EncodingFromBytesTest() throws IOException { System.setProperty("javax.xml.transform.TransformerFactory", XslScenario.SAXON_TRANSFORMER_FACTORY_FQCN); File xmlFile = new File(testResources.get("utf16-doc.xml").getURI()); File xslFile = new File(testResources.get("encoding.xsl").getURI()); XslScenario sc = new XslScenario(xslFile); byte[] bytes = FileUtils.readFileToByteArray(xmlFile); for (byte b : bytes) { System.out.format("%02x ", b); }//from www .j av a2s . com System.out.println(); // BOM UTF-16LE StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); formatter.format("%02x", bytes[0]); assertEquals("ff", sb.toString()); sb.delete(0, 2); formatter.format("%02x", bytes[1]); assertEquals("fe", sb.toString()); Map<String, String> outputs = sc.apply(bytes); assertNotNull("outputs object cannot be null.", outputs); }