List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:com.yfiton.core.Yfiton.java
private void logReceivedParameters(Parameters receivedParameters) { for (Map.Entry<String, ParameterValue> entry : receivedParameters) { String toStringValue = entry.getValue().toString(); String value = toStringValue; if (entry.getValue().isHidden()) { value = Strings.repeat("*", toStringValue.length()); }/*from w ww .java2 s. c o m*/ log.debug("Using parameter '" + entry.getKey() + "' with value '" + value + "'"); } }
From source file:es.usc.citius.hipster.util.examples.maze.Maze2D.java
/** * Creates a new 2D ASCII Maze from a array of Strings. * * @param maze2D Array of strings representing the maze. Use symbols from {@code Symbol} *//*from w w w . j a va2 s . c o m*/ public Maze2D(String[] maze2D) throws IllegalFormatException { // Initialize maze this.rows = maze2D.length; // y axis (rows) this.columns = findMaxRowLength(maze2D); // x axis (columns) maze = new char[rows][columns]; // Define valid cells for (int row = 0; row < this.rows; row++) { // if the current row has less than 'columns' characters, fill with empty tiles if (maze2D[row].length() < this.columns) { maze2D[row] = maze2D[row].concat( Strings.repeat(String.valueOf(Symbol.EMPTY.value()), this.columns - maze2D[row].length())); } for (int column = 0; column < this.columns; column++) { char charPoint = maze2D[row].charAt(column); // Parse character maze[row][column] = charPoint; // Note that point(x=2,y=1) is located in maze[1][2] if (maze[row][column] == Symbol.GOAL.value()) { this.goalLoc = new Point(column, row); } else if (maze[row][column] == Symbol.START.value()) { this.initialLoc = new Point(column, row); } } } if (this.getInitialLoc() == null) { throw new IllegalArgumentException("No initial location. Use the symbol S"); } if (this.getGoalLoc() == null) { throw new IllegalArgumentException("No goal location. Use the symbol G"); } }
From source file:org.apache.parquet.tools.command.MetadataUtils.java
private static void showDetails(PrettyPrintWriter out, GroupType type, int depth, MessageType container, List<String> cpath, boolean showOriginalTypes) { String name = Strings.repeat(".", depth) + type.getName(); Repetition rep = type.getRepetition(); int fcount = type.getFieldCount(); out.format("%s: %s F:%d%n", name, rep, fcount); cpath.add(type.getName());/* w w w . ja v a 2 s .c o m*/ for (Type ftype : type.getFields()) { showDetails(out, ftype, depth + 1, container, cpath, showOriginalTypes); } cpath.remove(cpath.size() - 1); }
From source file:org.onosproject.cli.MetricsListCommand.java
/** * Print metric object./* w w w. ja va 2 s .c om*/ * * @param name metric name * @param metric metric object */ private void printMetric(String name, Metric metric) { final String heading; if (metric instanceof Counter) { heading = format("-- %s : [%s] --", name, "Counter"); print(heading); Counter counter = (Counter) metric; print(" count = %d", counter.getCount()); } else if (metric instanceof Gauge) { heading = format("-- %s : [%s] --", name, "Gauge"); print(heading); @SuppressWarnings("rawtypes") Gauge gauge = (Gauge) metric; final Object value = gauge.getValue(); if (name.endsWith("EpochMs") && value instanceof Long) { print(" value = %s (%s)", value, new LocalDateTime(value)); } else { print(" value = %s", value); } } else if (metric instanceof Histogram) { heading = format("-- %s : [%s] --", name, "Histogram"); print(heading); final Histogram histogram = (Histogram) metric; final Snapshot snapshot = histogram.getSnapshot(); print(" count = %d", histogram.getCount()); print(" min = %d", snapshot.getMin()); print(" max = %d", snapshot.getMax()); print(" mean = %f", snapshot.getMean()); print(" stddev = %f", snapshot.getStdDev()); } else if (metric instanceof Meter) { heading = format("-- %s : [%s] --", name, "Meter"); print(heading); final Meter meter = (Meter) metric; print(" count = %d", meter.getCount()); print(" mean rate = %f", meter.getMeanRate()); print(" 1-minute rate = %f", meter.getOneMinuteRate()); print(" 5-minute rate = %f", meter.getFiveMinuteRate()); print(" 15-minute rate = %f", meter.getFifteenMinuteRate()); } else if (metric instanceof Timer) { heading = format("-- %s : [%s] --", name, "Timer"); print(heading); final Timer timer = (Timer) metric; final Snapshot snapshot = timer.getSnapshot(); print(" count = %d", timer.getCount()); print(" mean rate = %f per second", timer.getMeanRate()); print(" 1-minute rate = %f per second", timer.getOneMinuteRate()); print(" 5-minute rate = %f per second", timer.getFiveMinuteRate()); print(" 15-minute rate = %f per second", timer.getFifteenMinuteRate()); print(" min = %f ms", nanoToMs(snapshot.getMin())); print(" max = %f ms", nanoToMs(snapshot.getMax())); print(" mean = %f ms", nanoToMs(snapshot.getMean())); print(" stddev = %f ms", nanoToMs(snapshot.getStdDev())); } else { heading = format("-- %s : [%s] --", name, metric.getClass().getCanonicalName()); print(heading); print("Unknown Metric type:{}", metric.getClass().getCanonicalName()); } print(Strings.repeat("-", heading.length())); }
From source file:org.opendaylight.infrautils.utils.TablePrinter.java
private static void printRow(String separator, int[] maxWidths, StringBuilder sb, String[] row) { for (int i = 0; i < row.length; i++) { printSeparator(separator, sb, i); sb.append(row[i]);//from w w w . j a v a 2 s .c o m sb.append(Strings.repeat(" ", maxWidths[i] - row[i].length())); } sb.append("\n"); }
From source file:abstractions.cell.CellManager.java
@Override // TODO simplifier public String toString() { final int maximalNumberOfCellsByRow = Collections.max(this.data.values()).getColumn(); final StringBuilder consoleBoardView = new StringBuilder(); final Iterator<ManagedCellInterface> it = this.iterator(); ManagedCellInterface previousCell = it.next(); while (it.hasNext()) { final ManagedCellInterface cell = it.next(); if (previousCell.getRow() != cell.getRow()) { consoleBoardView.append("\n" + Strings.repeat("----", maximalNumberOfCellsByRow) + "-" + "\n"); consoleBoardView.append("|"); }/*from w ww . j a v a2 s .c o m*/ consoleBoardView.append(cell.render()); previousCell = cell; } consoleBoardView.append("\n" + Strings.repeat("----", maximalNumberOfCellsByRow) + "-" + "\n"); return consoleBoardView.toString(); }
From source file:co.cask.cdap.shell.util.AsciiTable.java
/** * Prints a divider./*from w ww. j a va 2 s . co m*/ * * @param output The {@link PrintStream} to output to * @param columnWidths Columns widths for each column * @param lineChar Character to use for printing the divider line * @param edgeChar Character to use for the left and right edge character */ private void outputDivider(PrintStream output, int[] columnWidths, char lineChar, char edgeChar) { output.print(edgeChar); for (int columnWidth : columnWidths) { output.print(Strings.repeat(Character.toString(lineChar), columnWidth + 2)); } // one for each divider output.print(Strings.repeat(Character.toString(lineChar), columnWidths.length - 1)); output.print(edgeChar); output.println(); }
From source file:com.google.api.codegen.transformer.php.PhpGapicSamplesTransformer.java
private List<ViewModel> generateSamples(GapicInterfaceContext context) { ImmutableList.Builder<ViewModel> viewModels = new ImmutableList.Builder<>(); SurfaceNamer namer = context.getNamer(); SampleFileRegistry generatedSamples = new SampleFileRegistry(); List<OptionalArrayMethodView> allmethods = methodGenerator.generateApiMethods(context); DynamicLangSampleView.Builder sampleClassBuilder = DynamicLangSampleView.newBuilder(); for (OptionalArrayMethodView method : allmethods) { String subPath = pathMapper.getSamplesOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig(), method.name()); for (MethodSampleView methodSample : method.samples()) { String callingForm = methodSample.callingForm().toLowerCamel(); String valueSet = methodSample.valueSet().id(); String className = namer.getApiSampleClassName( CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, method.name()), callingForm, valueSet);//from ww w . j a v a2 s .c om String sampleOutputPath = subPath + File.separator + namer.getApiSampleFileName(className); String autoloadPath = "__DIR__ . '" + Strings.repeat("/..", (int) sampleOutputPath.chars().filter(c -> c == File.separatorChar).count()) + "/vendor/autoload.php'"; generatedSamples.addFile(sampleOutputPath, method.name(), callingForm, valueSet, methodSample.regionTag()); viewModels.add(sampleClassBuilder.templateFileName(STANDALONE_SAMPLE_TEMPLATE_FILENAME) .fileHeader(fileHeaderTransformer.generateFileHeader(context)).outputPath(sampleOutputPath) .className(className) .libraryMethod(method.toBuilder().samples(Collections.singletonList(methodSample)).build()) .gapicPackageName(namer.getGapicPackageName(packageConfig.packageName())) .extraInfo(PhpSampleExtraInfo.newBuilder().autoloadPath(autoloadPath) .hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes()) .hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress()) .build()) .build()); } } return viewModels.build(); }
From source file:org.opendaylight.infrautils.utils.TablePrinter.java
private void printHeader(String separator, int[] maxWidths, StringBuilder sb) { if (header != null) { if (title != null) { sb.append(Strings.repeat(" ", SPACE_BEFORE_TABLES_WITH_TITLE)); }//from ww w. j a v a2 s .c o m printRow(separator, maxWidths, sb, header); if (title != null) { sb.append(Strings.repeat(" ", SPACE_BEFORE_TABLES_WITH_TITLE)); } // Header underline int rowLength = SPACE_BETWEEN_COLUMNS + separator.length() * (header.length - 1) + sum(maxWidths); sb.append(Strings.repeat("-", rowLength)); sb.append("\n"); } }
From source file:google.registry.tools.GetSchemaTreeCommand.java
private void printTree(Class<?> parent, int indent) { for (Class<?> clazz : hierarchy.get(parent)) { System.out.println(new StringBuilder(Strings.repeat(" ", indent)).append(indent == 0 ? "" : " ") .append(getPrintableName(clazz)).append(isAbstract(clazz.getModifiers()) ? " (abstract)" : "") .append(clazz.isAnnotationPresent(VirtualEntity.class) ? " (virtual)" : "") .append(clazz.isAnnotationPresent(NotBackedUp.class) ? " (not backed up)" : "") .append(BackupGroupRoot.class.isAssignableFrom(clazz) ? " (bgr)" : "")); printSubclasses(clazz, indent + 2); printTree(clazz, indent + 2);//from w ww .java2s . c o m if (indent == 0) { System.out.println(); // Separate the entity groups with a line. } } }