List of usage examples for org.apache.commons.lang StringUtils rightPad
public static String rightPad(String str, int size)
Right pad a String with spaces (' ').
From source file:morphy.command.WhoCommand.java
public void process(String arguments, UserSession userSession) { UserService us = UserService.getInstance(); UserSession[] users = us.getLoggedInUsers(); StringBuilder output = new StringBuilder(150); int counter = 0; for (int i = 0; i < users.length; i++) { String pChar = " "; SocketChannelUserSession s = (SocketChannelUserSession) users[i]; if (s.isPlaying()) { pChar = "^"; } else if (s.isExamining()) { pChar = "#"; } else if (s.getUser().getUserVars().getVariables().get("open").equals("0")) { pChar = ":"; } else if (s.getIdleTimeMillis() > 300000 || !s.getUser().getUserVars().getVariables().get("busy").equals("")) { pChar = "."; } else if (s.getUser().getUserVars().getVariables().get("tourney").equals("1")) { pChar = "&"; }//from ww w. jav a 2 s . c om output.append(String.format("%4s", "9999") + " " + pChar + StringUtils.rightPad(us.getTags(s.getUser().getUserName()), 20)); if (counter >= 4) { output.append("\n"); counter = 0; } } output.append("\n" + users.length + " players displayed (of " + users.length + "). (*) indicates system administrator."); userSession.send(output.toString()); }
From source file:com.flexive.shared.SimpleCacheStats.java
/** {@inheritDoc} */ @Override//from ww w .jav a2 s . c o m public String toString() { return StringUtils.rightPad(description + ":", 16) + hits + " hits, " + misses + " misses (hit rate = " + ((double) hits / (hits + misses)) + ")"; }
From source file:com.cloudbees.plugins.credentials.cli.ListCredentialsProvidersCommand.java
/** * {@inheritDoc}/* ww w . j av a 2 s .com*/ */ @Override protected int run() throws Exception { Map<String, CredentialsProvider> providersByName = CredentialsSelectHelper.getProvidersByName(); int maxNameLen = 0, maxDisplayLen = 0; for (Map.Entry<String, CredentialsProvider> entry : providersByName.entrySet()) { maxNameLen = Math.max(maxNameLen, entry.getKey().length()); maxDisplayLen = Math.max(maxDisplayLen, entry.getValue().getDisplayName().length()); } stdout.println(StringUtils.rightPad("Name", maxNameLen) + " Provider"); stdout.println(StringUtils.repeat("=", maxNameLen) + " " + StringUtils.repeat("=", maxDisplayLen)); for (Map.Entry<String, CredentialsProvider> entry : providersByName.entrySet()) { stdout.println( StringUtils.rightPad(entry.getKey(), maxNameLen) + " " + entry.getValue().getDisplayName()); } return 0; }
From source file:com.cloudbees.plugins.credentials.cli.ListCredentialsContextResolversCommand.java
/** * {@inheritDoc}//from w ww . j a va 2s. c o m */ @Override protected int run() throws Exception { Map<String, CredentialsSelectHelper.ContextResolver> resolversByName = CredentialsSelectHelper .getResolversByName(); int maxNameLen = 0, maxDisplayLen = 0; for (Map.Entry<String, CredentialsSelectHelper.ContextResolver> entry : resolversByName.entrySet()) { maxNameLen = Math.max(maxNameLen, entry.getKey().length()); maxDisplayLen = Math.max(maxDisplayLen, CredentialsSelectHelper.ContextResolver.displayName(entry.getValue()).length()); } stdout.println(StringUtils.rightPad("Name", maxNameLen) + " Resolves"); stdout.println(StringUtils.repeat("=", maxNameLen) + " " + StringUtils.repeat("=", maxDisplayLen)); for (Map.Entry<String, CredentialsSelectHelper.ContextResolver> entry : resolversByName.entrySet()) { stdout.println(StringUtils.rightPad(entry.getKey(), maxNameLen) + " " + CredentialsSelectHelper.ContextResolver.displayName(entry.getValue())); } return 0; }
From source file:herddb.cli.TextTableBuilder.java
@Override public String toString() { if (!hasResults) { return "Empty results set\n"; }//from ww w . j av a 2s . c om StringBuilder buf = new StringBuilder(); int[] colWidths = colWidths(); for (String[] row : rows) { buf.append("| "); for (int colNum = 0; colNum < row.length; colNum++) { buf.append(StringUtils.rightPad(StringUtils.defaultString(row[colNum]), colWidths[colNum])); buf.append(" | "); } buf.append('\n'); } return buf.toString(); }
From source file:morphy.command.BugWhoCommand.java
public void process(String arguments, UserSession userSession) { boolean showGames = false; boolean showPartnerships = false; boolean showUnpartnered = false; if (arguments.equals("")) { arguments = "gpu"; }//w ww.jav a2 s . c o m if (arguments.contains("g")) { showGames = true; } if (arguments.contains("p")) { showPartnerships = true; } if (arguments.contains("u")) { showUnpartnered = true; } StringBuilder b = new StringBuilder(); if (showGames) { b.append("Bughouse games in progress\n"); b.append(String.format("%3d", 160) + " 1770 knighttour 1680 BishopBlud [pBu 2 0] 0:58 - 0:14 (35-23) W: 27\n"); b.append(String.format("%3d", 179) + " 1486 EagleMorphy ++++ DogWithSky [pBu 2 0] 1:09 - 0:22 (43-55) B: 20\n"); b.append("\n" + String.format("%2d", 1) + " game displayed.\n\n"); } if (showPartnerships) { UserService us = UserService.getInstance(); UserSession u = us.getUserSession("johnthegreat"); b.append("Partnerships not playing bughouse\n"); b.append(String.format("%4s", "9999") + " " + getChar(u) + StringUtils.rightPad(us.getTags(u.getUser().getUserName()), 17)); b.append(" / 2789:ChIcKeNcRoSsRoAd(FM)(CA)"); b.append("\n\n" + String.format("%2d", 1) + " partnerships displayed.\n\n"); } if (showUnpartnered) { b.append("Unpartnered players with bugopen on\n\n"); b.append("2789:ChIcKeNcRoSsRoAd(FM)(CA) 1369^bachio"); b.append("\n\n 71 players displayed (of 1702). (*) indicates system administrator."); } userSession.send(b.toString()); }
From source file:aos.lucene.search.advanced.SortingExample.java
public void displayResults(Query query, Sort sort) // throws IOException { IndexSearcher searcher = new IndexSearcher(directory); searcher.setDefaultFieldSortScoring(true, false); // TopDocs results = searcher.search(query, null, // 20, sort); // LOGGER.info("\nResults for: " + // query.toString() + " sorted by " + sort); LOGGER.info(StringUtils.rightPad("Title", 30) + StringUtils.rightPad("pubmonth", 10) + StringUtils.center("id", 4) + StringUtils.center("score", 15)); PrintStream out = new PrintStream(System.out, true, "UTF-8"); // DecimalFormat scoreFormatter = new DecimalFormat("0.######"); for (ScoreDoc sd : results.scoreDocs) { int docID = sd.doc; float score = sd.score; Document doc = searcher.doc(docID); out.println(StringUtils.rightPad( // StringUtils.abbreviate(doc.get("title"), 29), 30) + // StringUtils.rightPad(doc.get("pubmonth"), 10) + // StringUtils.center("" + docID, 4) + // StringUtils.leftPad( // scoreFormatter.format(score), 12)); // out.println(" " + doc.get("category")); //out.println(searcher.explain(query, docID)); // }/*from www.j ava2 s . c om*/ searcher.close(); }
From source file:com.vamonossoftware.core.TextTable.java
public String toString() { StringBuilder sb = new StringBuilder(); for (Object[] objects : data) { sb.append(leftPad);// w ww . ja v a2 s . c o m for (int i = 0; i < objects.length; i++) { Object object = objects[i]; if (alignment.length > i) { switch (alignment[i]) { case CENTER: sb.append(StringUtils.center(object.toString(), maxWidths.get(i))); break; case RIGHT: sb.append(StringUtils.leftPad(object.toString(), maxWidths.get(i))); break; default: sb.append(StringUtils.rightPad(object.toString(), maxWidths.get(i))); break; } } sb.append(" "); } sb.append("\n"); } return sb.toString(); }
From source file:com.enonic.cms.business.core.content.mail.AbstractAssignmentMailTemplate.java
private void appendKeyValuesWithPadding(StringBuffer body, Map<String, String> keyValues) { int maxLength = findKeyMaxLength(keyValues); addNewLine(body);/*from ww w. ja v a 2 s . com*/ for (String key : keyValues.keySet()) { String paddedKey = StringUtils.rightPad(key, maxLength); body.append(paddedKey + "\t" + keyValues.get(key)); addNewLine(body); } }
From source file:es.emergya.ui.base.plugins.Option.java
/** * @param title/*from w ww . j a va 2s .com*/ */ public void setTitle(String title) { if (title.length() == 0) this.title = title; else this.title = StringUtils.rightPad(title, 25); }