List of usage examples for com.google.common.base Strings padEnd
public static String padEnd(String string, int minLength, char padChar)
From source file:org.openengsb.core.ekb.transformation.wonderland.internal.operation.PadOperation.java
/** * Perform the pad operation itself and returns the result *//*from ww w . ja v a 2 s . c o m*/ private String performPadOperation(String source, Integer length, Character padChar, String direction) { if (direction.equals("Start")) { return Strings.padStart(source, length, padChar); } else { return Strings.padEnd(source, length, padChar); } }
From source file:org.ldp4j.xml.Generator.java
private String normalize(final String string) { final List<String> normalized = Lists.newArrayList(); int max = 0;//from w ww . j av a2s .c o m for (final String part : Splitter.on('|').split(string)) { String normal = part.trim(); if (normal.startsWith("\"")) { normal = "codePoint == '" + normal.substring(1, 2) + "'"; } else if (normal.startsWith("[")) { final String def = normal.substring(1, normal.length() - 1); final String[] split = def.split("-"); normal = "(codePoint >= '" + split[0] + "' && codePoint <= '" + split[1] + "')"; } else if (!normal.contains("codePoint")) { normal = "is" + normal + "(codePoint)"; } if (normal.contains("==")) { normal = "(" + normal + ")"; } normalized.add(normal); max = Math.max(max, normal.length()); } final List<String> padded = Lists.newArrayList(); for (final String normal : normalized) { padded.add(Strings.padEnd(normal, max + 1, ' ')); } return Joiner.on('|').join(padded).trim(); }
From source file:ninja.template.TemplateEngineManagerImpl.java
protected void logTemplateEngines() { List<String> outputTypes = Lists.newArrayList(getContentTypes()); Collections.sort(outputTypes); if (outputTypes.isEmpty()) { logger.error("No registered template engines?! Please install a template module!"); return;// w w w . j av a 2 s . co m } int maxContentTypeLen = 0; int maxTemplateEngineLen = 0; for (String contentType : outputTypes) { TemplateEngine templateEngine = getTemplateEngineForContentType(contentType); maxContentTypeLen = Math.max(maxContentTypeLen, contentType.length()); maxTemplateEngineLen = Math.max(maxTemplateEngineLen, templateEngine.getClass().getName().length()); } int borderLen = 6 + maxContentTypeLen + maxTemplateEngineLen; String border = Strings.padEnd("", borderLen, '-'); logger.info(border); logger.info("Registered response template engines"); logger.info(border); for (String contentType : outputTypes) { TemplateEngine templateEngine = getTemplateEngineForContentType(contentType); logger.info("{} => {}", Strings.padEnd(contentType, maxContentTypeLen, ' '), templateEngine.getClass().getName()); } }
From source file:org.jeo.cli.JeoCLI.java
public void usage() { Set<String> commands = cmdr.getCommands().keySet(); int maxLength = new Ordering<String>() { public int compare(String left, String right) { return Ints.compare(left.length(), right.length()); };//from w w w.jav a 2 s. c o m }.max(commands).length(); try { console.println("usage: jeo <command> [<args>]"); console.println(); console.println("Commands:"); console.println(); for (String cmd : commands) { console.print("\t"); console.print(Strings.padEnd(cmd, maxLength, ' ')); console.print("\t"); console.println(cmdr.getCommandDescription(cmd)); } console.println(); console.println("For detailed help on a specific command use jeo <command> -h"); console.flush(); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:org.gradle.api.reporting.model.internal.ModelNodeRenderer.java
private String attributeLabel(String label) { return Strings.padEnd(label, LABEL_LENGTH, ' '); }
From source file:com.github.jcustenborder.kafka.connect.utils.config.MarkdownFormatter.java
static String markdownTable(List<List<String>> rows) { StringBuilder builder = new StringBuilder(); List<Integer> lengths = lengths(rows); int index = 0; for (List<String> row : rows) { List<String> copy = new ArrayList<>(row.size()); for (int i = 0; i < row.size(); i++) { String f = Strings.padEnd(row.get(i) == null ? "" : row.get(i), lengths.get(i), ' '); copy.add(f);/* w ww .j av a 2 s . c o m*/ } builder.append("| "); Joiner.on(" | ").appendTo(builder, copy); builder.append(" |\n"); if (index == 0) { List<String> bar = new ArrayList<>(lengths.size()); for (Integer length : lengths) { bar.add(Strings.repeat("-", length + 2)); } builder.append("|"); Joiner.on("|").appendTo(builder, bar); builder.append("|\n"); } index++; } return builder.toString(); }
From source file:AvailableTickets.java
/** * Outputs the available tickets file in memory to file, over-writing * the old available tickets file.//www . j a v a2 s .c om * * @throws FatalError Fatal errors occur under the following circumstances: * <br>The Available Tickets File is corrupted. * @throws IOException */ public void write() throws IOException { BufferedWriter writer; String entry; File file = new File(atfFile); writer = new BufferedWriter(new FileWriter(file.getAbsoluteFile())); /* Format each entry and write it to the file */ for (Ticket ticket : tickets) { /* Format the event */ entry = ticket.getEvent().replace(' ', '_'); entry = Strings.padEnd(entry, 20, '_'); /* Format the seller */ entry += Strings.padEnd(ticket.getSeller(), 16, '_'); /* Format the number of tickets */ entry += Strings.padStart(ticket.getVolume().toString(), 3, '0') + "_"; /* Format the price of tickets */ entry += Strings.padStart(String.format("%.2f", ticket.getPrice()), 6, '0') + "\n"; writer.write(entry); } /* Add the END of file identifier and close the file */ writer.write("END_________________________________000_000.00"); writer.close(); }
From source file:org.ldp4j.server.utils.CharsetPreference.java
/** Create a charset preference that matches the following grammar: * <pre> {@code//from w w w .ja v a2s . c om CHAR = <any US-ASCII character (octets 0 - 127)> DIGIT = <any US-ASCII digit "0".."9"> CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)> SP = <US-ASCII SP, space (32)> HT = <US-ASCII HT, horizontal-tab (9)> <"> = <US-ASCII double-quote mark (34)> token = 1*<any CHAR except CTLs or separators> separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HT charset = token qvalue = ( "0" [ "." 0*3DIGIT ] ) | ( "1" [ "." 0*3("0") ] ) preference = ( charset | "*" )[ ";" "q" "=" qvalue ]}</pre> */ public static CharsetPreference valueOf(String str) { String[] parts = str.split(";"); if (parts.length <= 2) { String charsetName = parts[0].trim(); if ("*".equals(charsetName) || TOKEN_MATCHER.matchesAllOf(charsetName)) { int weight = MAX_WEIGHT; if (parts.length == 2) { String weightValue = parts[1].trim(); Matcher matcher = QUALITY_PATTERN.matcher(weightValue); if (!matcher.matches()) { return null; } if (weightValue.charAt(2) == '0') { weight = Integer.parseInt(Strings.padEnd(weightValue.substring(4), 3, '0')); } } return new CharsetPreference(charsetName, weight); } } return null; }
From source file:org.cinchapi.concourse.util.TLinkedTableMap.java
@Override public String toString() { int total = 0; Object[] header = new String[columns.size() + 1]; header[0] = rowName;/* ww w .java2 s.com*/ String format = "| %-" + rowLength + "s | "; int i = 1; for (java.util.Map.Entry<C, Integer> entry : columns.entrySet()) { format += "%-" + entry.getValue() + "s | "; total += entry.getValue() + 3; header[i] = entry.getKey(); i++; } format += "%n"; String hr = Strings.padEnd("+", rowLength + 3 + total, '-'); hr += "+" + System.getProperty("line.separator"); StringBuilder sb = new StringBuilder(); sb.append(System.getProperty("line.separator")); sb.append(hr); sb.append(String.format(format, header)); sb.append(hr); for (R row : keySet()) { Object[] rowdata = new Object[columns.size() + 1]; rowdata[0] = row; i = 1; for (C column : columns.keySet()) { rowdata[i] = get(row).get(column); i++; } sb.append(String.format(format, rowdata)); } sb.append(hr); return sb.toString(); }
From source file:com.cinchapi.concourse.util.PrettyLinkedTableMap.java
@Override public String toString() { int total = 0; Object[] header = new Object[columns.size() + 1]; header[0] = rowName;//w ww .java 2 s . c o m String format = "| %-" + rowLength + "s | "; int i = 1; for (java.util.Map.Entry<C, Integer> entry : columns.entrySet()) { format += "%-" + entry.getValue() + "s | "; total += entry.getValue() + 3; header[i] = entry.getKey(); ++i; } format += "%n"; String hr = Strings.padEnd("+", rowLength + 3 + total, '-'); hr += "+" + System.getProperty("line.separator"); StringBuilder sb = new StringBuilder(); sb.append(System.getProperty("line.separator")); sb.append(hr); sb.append(String.format(format, header)); sb.append(hr); for (R row : keySet()) { Object[] rowdata = new Object[columns.size() + 1]; rowdata[0] = row; i = 1; for (C column : columns.keySet()) { rowdata[i] = get(row).get(column); ++i; } sb.append(String.format(format, rowdata)); } sb.append(hr); return sb.toString(); }