List of usage examples for java.util Formatter format
public Formatter format(String format, Object... args)
From source file:org.mskcc.cbio.portal.util.MakeOncoPrint.java
/** * Format percentage./* w w w .j av a 2s. co m*/ * * <p/> * if value == 0 return "--" * case value * 0: return "--" * 0<value<=0.01: return "<1%" * 1<value: return "<value>%" * * @param value double * * @return String */ public static String alterationValueToString(double value) { // in oncoPrint show 0 percent as 0%, not -- if (0.0 < value && value <= 0.01) { return "<1%"; } // if( 1.0 < value ){ Formatter f = new Formatter(); f.format("%.0f", value * 100.0); return f.out().toString() + "%"; }
From source file:org.ohmage.db.DbHelper.java
public static String getSHA1Hash(String input) throws NoSuchAlgorithmException { Formatter formatter = new Formatter(); MessageDigest md = MessageDigest.getInstance("SHA1"); byte[] hash = md.digest(input.getBytes()); for (byte b : hash) { formatter.format("%02x", b); }// www .j a va 2 s.c om return formatter.toString(); }
From source file:com.knowbout.epg.entities.Program.java
@SuppressWarnings("unchecked") private static Program createMissingTeam(Session session, String sportName, String teamName) { log.debug("Calling createMissingTeam()"); boolean commit = false; if (TransactionManager.currentTransaction() == null) { TransactionManager.beginTransaction(); commit = true;//w w w . j a v a 2 s .c o m } try { Query query = session.getNamedQuery("Program.selectProgramsWithTeam"); query.setString("programTitle", sportName); String episodeTitleLike = "%" + teamName + "%"; query.setString("episodeTitleLike", episodeTitleLike); query.setMaxResults(1); List<Program> programs = query.list(); if (programs == null || programs.size() == 0) { return null; } query = session.createQuery("select MAX(programId) from Program"); String maxProgramId = (String) query.uniqueResult(); String teamId = null; if (maxProgramId != null && maxProgramId.startsWith("TE")) { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("TE%08d0000", Integer.valueOf(maxProgramId.substring(2, 10)) + 1); teamId = sb.toString(); } else { teamId = "TE000000010000"; } Program sample = programs.get(0); Program team = new Program(); team.setAdultSituationsAdvisory(sample.getAdultSituationsAdvisory()); team.setAltSynEpiNum(""); team.setAltTitle(""); team.setBriefNudityAdvisory(sample.getBriefNudityAdvisory()); team.setColorCode(sample.getColorCode()); team.setDescription("Games played by the " + teamName); team.setDescriptionActors(team.getDescription()); team.setEpisodeTitle(sportName); team.setGenreDescription(sample.getGenreDescription()); team.setGraphicLanguageAdvisory(sample.getGraphicLanguageAdvisory()); team.setGraphicViolenceAdvisory(sample.getGraphicViolenceAdvisory()); team.setHoliday(""); team.setProgramId(teamId); team.setLastModified(new Date()); team.setMadeForTv(sample.isMadeForTv()); team.setMpaaRating(""); team.setNetSynSource(sample.getNetSynSource()); team.setNetSynType(sample.getNetSynType()); team.setOrgCountry(sample.getOrgCountry()); team.setOrginalAirDate(null); team.setOrgStudio(sample.getOrgStudio()); team.setProgramLanguage(sample.getProgramLanguage()); team.setRapeAdvisory(sample.getRapeAdvisory()); team.setReducedDescription120(truncateWithDots(120, team.getDescription())); team.setReducedDescription60("Games played by this team."); team.setReducedDescription40("Games played by this team."); team.setReducedDescriptionActors("Games played by this team."); team.setReducedTitle10(teamName.length() > 10 ? teamName.substring(0, 10) : teamName); team.setReducedTitle20(teamName.length() > 20 ? teamName.substring(0, 20) : teamName); team.setReducedTitle40(teamName.length() > 40 ? teamName.substring(0, 40) : teamName); team.setReducedTitle70(teamName.length() > 70 ? teamName.substring(0, 70) : teamName); team.setRunTime(sample.getRunTime()); team.setShowType(sample.getShowType()); team.setSourceType(sample.getSourceType()); team.setSscAdvisory(sample.getSscAdvisory()); team.setStarRating(sample.getStarRating()); team.setSynEpiNum(null); team.setProgramTitle(teamName); team.setUniqueId(""); team.setYear(null); team.insert(); if (commit) { TransactionManager.commitTransaction(); } return team; } catch (Error e) { log.error("Could not create TEam", e); TransactionManager.rollbackTransaction(); throw e; } }
From source file:edu.cmu.tetrad.cli.search.GfcicCli.java
@Override public void printParameterInfos(Formatter fmt) { fmt.format("alpha = %f%n", alpha); super.printParameterInfos(fmt); }
From source file:com.globalsight.ling.tm3.tools.HistoryCommand.java
protected void printEvents(TM3EventLog events, String label, Formatter f) { f.format("== History for %s ==\n", label); SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); f.format("%-22s%-12s%-6s%s\n", "Date", "User", "Type", "Argument"); for (TM3Event e : events.getEvents()) { String user = e.getUsername(); if (user.length() > 10) user = user.substring(0, 10); f.format("%-22s%-12s%-6d%s\n", df.format(e.getTimestamp()), user, e.getType(), e.getArgument()); }/*from w w w.j av a 2s .c o m*/ }
From source file:com.itemanalysis.psychometrics.reliability.AbstractScoreReliability.java
public String confidenceIntervalToString(double[] confidenceInterval) { StringBuilder builder = new StringBuilder(); Formatter f = new Formatter(builder); f.format("(%6.4f, ", confidenceInterval[0]); f.format("%6.4f)", confidenceInterval[1]); return f.toString(); }
From source file:com.slytechs.utils.factory.FactoryLoader.java
@SuppressWarnings("unchecked") public void loadFactoryClass() { String path = System.getProperty(property, defaults); try {//from w w w . j a va 2 s . c o m factory = (T) Class.forName(path).newInstance(); } catch (final Exception e) { final Formatter out = new Formatter(); logger.error(out.format("Unable to load factory class [%s]", path).toString()); // throw new IllegalStateException(e); } }
From source file:fll.web.scoreEntry.ScoreEntry.java
/** * @param formatter where to write//from w ww . j a v a 2 s . c om * @param ifPrefix what goes before "if", either spaces or "else" * @param ele * @throws ParseException */ private static void generateCondition(final Formatter formatter, final String ifPrefix, final AbstractConditionStatement ele) throws ParseException { formatter.format("%sif(", ifPrefix); if (ele instanceof ConditionStatement) { ConditionStatement cond = (ConditionStatement) ele; formatter.format("%s %s %s", polyToString(cond.getLeft()), ineqToString(ele.getComparison()), polyToString(cond.getRight())); } else if (ele instanceof EnumConditionStatement) { EnumConditionStatement cond = (EnumConditionStatement) ele; final String leftStr; if (null != cond.getLeftGoal()) { leftStr = getVarNameForRawScore(cond.getLeftGoal().getName()); } else { leftStr = "'" + cond.getLeftString() + "'"; } final String rightStr; if (null != cond.getRightGoal()) { rightStr = getVarNameForRawScore(cond.getRightGoal().getName()); } else { rightStr = "'" + cond.getLeftString() + "'"; } formatter.format("%s %s %s", leftStr, ineqToString(ele.getComparison()), rightStr); } else { throw new FLLInternalException( "Expecting ConditionStatement or EnumConditionStatement, but was" + ele.getClass().getName()); } formatter.format(")"); }
From source file:com.itemanalysis.psychometrics.reliability.KR21.java
@Override public String toString() { StringBuilder builder = new StringBuilder(); Formatter f = new Formatter(builder); String f2 = "%.4f"; f.format("%7s", "KR-21: "); f.format(f2, this.value()); return f.toString(); }
From source file:fll.web.scoreEntry.ScoreEntry.java
private static void generateComputedGoalFunction(final Formatter formatter, final ComputedGoal compGoal) throws ParseException { final String goalName = compGoal.getName(); formatter.format("function %s() {%n", getComputedMethodName(goalName)); for (final Variable var : compGoal.getVariables()) { final String varName = getComputedGoalLocalVarName(var.getName()); final String varValue = polyToString(var); formatter.format("var %s = %s;%n", varName, varValue); }/*from w w w. j a va2 s .com*/ generateSwitch(formatter, compGoal.getSwitch(), goalName, INDENT_LEVEL); formatter.format("%sdocument.scoreEntry.score_%s.value = %s;%n", generateIndentSpace(INDENT_LEVEL), goalName, getVarNameForComputedScore(goalName)); formatter.format("}%n"); }