List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:com.google.template.soy.error.PrettyErrorFactory.java
private String getFormattedError(SourceLocation sourceLocation, String message) { StringBuilder builder = new StringBuilder(); // Start by printing the actual text of the exception. builder.append("In file " + sourceLocation + ": " + message).append("\n"); // Try to find a snippet of source code associated with the exception and print it. Optional<String> snippet; try {// w ww . j ava 2s . com snippet = snippetFormatter.getSnippet(sourceLocation); } catch (IOException exception) { snippet = Optional.absent(); } // TODO(user): this is a result of calling SoySyntaxException#createWithoutMetaInfo, // which occurs almost 100 times. Clean them up. if (snippet.isPresent()) { builder.append(snippet.get()).append("\n"); // Print a caret below the error. // TODO(brndn): SourceLocation.beginColumn is occasionally -1. Review all SoySyntaxException // instantiations and ensure the SourceLocation is well-formed. int beginColumn = Math.max(sourceLocation.getBeginColumn(), 1); String caretLine = Strings.repeat(" ", beginColumn - 1) + "^"; builder.append(caretLine).append("\n"); } return builder.toString(); }
From source file:jetbrains.jetpad.cell.toView.IndentRootCellMapper.java
IndentRootCellMapper(IndentCell source, CellToViewContext ctx) { super(source, new VerticalView(), ctx); myCellMappers = createChildSet();//from w w w .j a v a 2 s. c o m myIndentUpdater = new IndentUpdater<View>(getSource(), getTarget(), new IndentUpdaterTarget<View>() { @Override public View newLine() { return new HorizontalView(); } @Override public View newIndent(int size) { TextView result = new TextView(); result.text().set(Strings.repeat(" ", size)); return result; } @Override public CellWrapper<View> wrap(final Cell cell) { final BaseCellMapper<?, ?> mapper = createMapper(cell); CounterUtil.updateOnAdd(getSource(), cell, mapper); mapper.setAncestorBackground(AncestorUtil.getAncestorBackground(getSource(), cell)); myCellMappers.add(mapper); return new CellWrapper<View>() { @Override public View item() { return mapper.getTarget(); } @Override public void remove() { CounterUtil.updateOnRemove(getSource(), cell, mapper); myCellMappers.remove(mapper); } }; } @Override public List<View> children(View item) { return item.children(); } @Override public View parent(View item) { return item.getParent(); } }) { @Override protected void onVisibilityChanged(Cell cell, PropertyChangeEvent<Boolean> event) { myIndentUpdater.visibilityChanged(cell, event); } }; }
From source file:org.apache.kudu.util.DecimalUtil.java
/** * Returns the maximum value of a Decimal give a precision and scale. * @param precision the precision of the decimal. * @param scale the scale of the decimal. * @return the maximum decimal value.//from w w w . j a v a 2s . co m */ public static BigDecimal maxValue(int precision, int scale) { String maxPrecision = Strings.repeat("9", precision); return new BigDecimal(new BigInteger(maxPrecision), scale); }
From source file:fr.jcgay.maven.plugin.buildplan.ListMojo.java
private String lineSeparator(TableDescriptor descriptor) { return Strings.repeat("-", descriptor.width()); }
From source file:com.google.api.codegen.configgen.ConfigGenerator.java
@VisitsBefore void generate(ListItemConfigNode node) { appendComment(node.getComment().generate()); ConfigGenerator childGenerator = new ConfigGenerator(indent); childGenerator.visit(node.getChild()); String child = childGenerator.toString().trim(); boolean isFirst = true; for (String line : Splitter.on(System.lineSeparator()).split(child)) { if (!isFirst) { configBuilder.append(whitespace().trimTrailingFrom(line)); } else if (line.trim().startsWith("#")) { appendIndent().append(whitespace().trimTrailingFrom(line)); } else {/*from w w w . j a v a2 s. c o m*/ configBuilder.append(Strings.repeat(" ", indent - TAB_WIDTH)).append("- ").append(line.trim()); isFirst = false; } configBuilder.append(System.lineSeparator()); } }
From source file:fr.jcgay.maven.plugin.buildplan.ListPluginMojo.java
private String pluginTitleLine(TableDescriptor descriptor, String key) { return key + " " + Strings.repeat("-", descriptor.width() - key.length()); }
From source file:org.excalibur.fm.configuration.MainConsole.java
static void print(Iterable<InstanceType> instanceTypes) {//https://code.google.com/p/j-text-utils/ http://docs.oracle.com/javase/6/docs/api/java/util/Formatter.html http://stackoverflow.com/questions/2745206/output-in-a-table-format-in-javas-system-out System.out.format("%10s|%15s|%8s|%8s|%10s|%12s|%15s|", "Provider", "Instance type", "# cores", "RAM (GB)", "Cost (US)", "Family type", "Region"); System.out.printf("\n%s\n", Strings.repeat("~", 85)); for (InstanceType type : instanceTypes) { System.out.format("%10s|%15s|%8s|%8s|%10s|%12s|%15s|", type.getProvider().getName(), type.getName(), type.getConfiguration().getNumberOfCores(), type.getConfiguration().getRamMemorySizeGb(), type.getCost(), type.getFamilyType().name(), type.getRegion().getName()); System.out.printf("\n%s\n", Strings.repeat("-", 85)); }//from w w w. j av a2s . c o m System.out.printf("\n%s\n", Strings.repeat("=", 85)); }
From source file:fr.jcgay.maven.plugin.buildplan.ListPhaseMojo.java
private String phaseTitleLine(TableDescriptor descriptor, String key) { return key + " " + Strings.repeat("-", descriptor.width() - key.length()); }
From source file:com.google.api.codegen.util.CommonRenderingUtil.java
/** * Creates a whitespace string of the specified width. * * @param width number of spaces/*from ww w.j a va2 s .c o m*/ * @return padding whitespace */ public static String padding(int width) { return Strings.repeat(" ", width); }
From source file:com.chiorichan.ConsoleLogFormatter.java
@Override public String format(LogRecord record) { if (Loader.getConfig() != null && !formatConfigLoaded) { dateFormat = new SimpleDateFormat(Loader.getConfig().getString("console.dateFormat", "MM-dd")); timeFormat = new SimpleDateFormat(Loader.getConfig().getString("console.timeFormat", "HH:mm:ss.SSS")); formatConfigLoaded = true;/* w w w. j a va2 s .c om*/ } String style = (Loader.getConfig() == null) ? "&r&7%dt %tm [%lv&7]&f" : Loader.getConfig().getString("console.style", "&r&7[&d%ct&7] %dt %tm [%lv&7]&f"); Throwable ex = record.getThrown(); if (style.contains("%ct")) { String threadName = Thread.currentThread().getName(); if (threadName.length() > 10) threadName = threadName.substring(0, 2) + ".." + threadName.substring(threadName.length() - 6); else if (threadName.length() < 10) threadName = threadName + Strings.repeat(" ", 10 - threadName.length()); style = style.replaceAll("%ct", threadName); } style = style.replaceAll("%dt", dateFormat.format(record.getMillis())); style = style.replaceAll("%tm", timeFormat.format(record.getMillis())); int howDeep = debugModeHowDeep; if (debugMode) { StackTraceElement[] var1 = Thread.currentThread().getStackTrace(); for (StackTraceElement var2 : var1) { if (!var2.getClassName().toLowerCase().contains("java") && !var2.getClassName().toLowerCase().contains("sun") && !var2.getClassName().toLowerCase().contains("log") && !var2.getMethodName().equals("sendMessage") && !var2.getMethodName().equals("sendRawMessage")) { howDeep--; if (howDeep <= 0) { style += " " + var2.getClassName() + "$" + var2.getMethodName() + ":" + var2.getLineNumber(); break; } } } } if (style.contains("%lv")) style = style.replaceAll("%lv", getLevelColor(record.getLevel()) + record.getLevel().getLocalizedName().toUpperCase()); style += " " + formatMessage(record); if (!formatMessage(record).endsWith("\r")) style += "\n"; if (ex != null) { StringWriter writer = new StringWriter(); ex.printStackTrace(new PrintWriter(writer)); style += writer; } if (!Loader.getConsole().useColors || !useColor) return ConsoleColor.removeAltColors(style); else return ConsoleColor.transAltColors(style); }