List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:org.apache.aurora.common.thrift.Util.java
private static String tabs(int n) { return Strings.repeat(" ", n); }
From source file:org.nest.nestml._cocos.IllegalExpression.java
private void handleAssignment(ASTAssignment node) { //collect lhs information final String variableName = node.getLhsVarialbe().getName() + Strings.repeat("'", node.getLhsVarialbe().getDifferentialOrder().size()); final Optional<VariableSymbol> lhsVariable = node.getEnclosingScope().get().resolve(variableName, VariableSymbol.KIND);//from w w w . j a v a2 s. c o m final TypeSymbol variableType = lhsVariable.get().getType(); //collect rhs information final Either<TypeSymbol, String> expressionTypeEither = node.getExpr().getType(); if (expressionTypeEither.isValue()) { final TypeSymbol expressionType = expressionTypeEither.getValue(); if (!isCompatible(variableType, expressionType)) { final String msg = SplErrorStrings.messageAssignment(this, variableName, variableType.prettyPrint(), expressionType.prettyPrint()); if (isReal(variableType) && isUnit(expressionType)) { //TODO put in string class when I inevitably refactor it. final String castMsg = SplErrorStrings.messageCastToReal(this, expressionType.prettyPrint()); warn(castMsg, node.get_SourcePositionStart()); } else if (isUnit(variableType)) { //assignee is unit -> drop warning not error warn(msg, node.get_SourcePositionStart()); } else { error(msg, node.get_SourcePositionStart()); } } } }
From source file:nl.knaw.huygens.timbuctoo.tools.importer.DefaultConverter.java
/** * Displays a text in a formatted box.// w w w. j a va 2s . c o m */ protected void printBoxedText(String text) { String line = Strings.repeat("-", text.length() + 8); System.out.println(); System.out.println(line); System.out.print("-- "); System.out.print(text); System.out.println(" --"); System.out.println(line); }
From source file:by.dev.madhead.gbp.tasks.gdrive.GoogleDriveUploadTask.java
/** * Uploads {@link #setArchive(File) specified file} to Google Drive. *///from www .j ava2 s. com @TaskAction public void run() { try { Preconditions.checkNotNull(this.clientId, "Google Drive client ID must not be null"); Preconditions.checkNotNull(this.clientSecret, "Google Drive client secret must not be null"); Preconditions.checkNotNull(this.accessToken, "Google Drive access token must not be null"); Preconditions.checkNotNull(this.refreshToken, "Google Drive refresh token must not be null"); Preconditions.checkNotNull(this.archive, "Archive must not be null"); Preconditions.checkArgument(this.archive.exists(), "Archive must exist"); Preconditions.checkArgument(this.archive.isFile(), "Archive must be a file"); final Drive drive = constructDrive(); final com.google.api.services.drive.model.File parent = locateParent(drive); final com.google.api.services.drive.model.File descriptor = new com.google.api.services.drive.model.File(); final FileContent content = new FileContent(mimeType, archive); if (null != parent) { descriptor.setParents(Arrays.<ParentReference>asList(new ParentReference().setId(parent.getId()))); } descriptor.setMimeType(content.getType()); descriptor.setTitle(content.getFile().getName()); final Drive.Files.Insert insert = drive.files().insert(descriptor, content); final MediaHttpUploader uploader = insert.getMediaHttpUploader(); uploader.setChunkSize(1 * 1024 * 1024 /* bytes */); if (listenForUpload) { uploader.setProgressListener(new MediaHttpUploaderProgressListener() { @Override public void progressChanged(MediaHttpUploader u) throws IOException { final double progress = (double) u.getNumBytesUploaded() / content.getLength(); System.out.printf("\r[%-50.50s] %.2f%%", Strings.repeat("#", (int) (progress * 50)), progress * 100); System.out.flush(); } }); } insert.execute(); } catch (Exception e) { throw new TaskExecutionException(this, e); } }
From source file:org.openhab.binding.max.internal.message.H_Message.java
@Override public void debug(Logger logger) { logger.trace("=== H_Message === "); logger.trace("\tRAW: : {}", this.getPayload()); logger.trace("\tReading Time : {}", cal.getTime()); for (String key : properties.keySet()) { logger.trace("\t{}:{}{}", key, Strings.repeat(" ", 25 - key.length()), properties.get(key)); }/*from w ww . j av a2s .c o m*/ }
From source file:org.onosproject.cli.net.ResourcesCommand.java
private void printResource(Resource resource, int level) { // workaround to preserve the original behavior of ResourceService#getRegisteredResources Set<Resource> children; if (resource instanceof DiscreteResource) { children = resourceService.getRegisteredResources(((DiscreteResource) resource).id()); } else {/*from w w w . j a v a 2 s. c om*/ children = Collections.emptySet(); } if (resource.equals(Resource.ROOT)) { print("ROOT"); } else { String resourceName = resource.simpleTypeName(); if (resource instanceof ContinuousResource) { print("%s%s: %f", Strings.repeat(" ", level), resourceName, ((ContinuousResource) resource).value()); // Continuous resource is terminal node, stop here return; } else { String availability = ""; if (availablesOnly && !children.isEmpty()) { // intermediate nodes cannot be omitted, print availability if (resourceService.isAvailable(resource)) { availability = " "; } else { availability = " "; } } String toString = String.valueOf(resource.valueAs(Object.class).orElse("")); if (toString.startsWith(resourceName)) { print("%s%s%s", Strings.repeat(" ", level), toString, availability); } else { print("%s%s: %s%s", Strings.repeat(" ", level), resourceName, toString, availability); } } } // Classify children into aggregatable terminal resources and everything else Set<Class<?>> aggregatableTypes = ImmutableSet.<Class<?>>builder().add(VlanId.class).add(MplsLabel.class) .build(); // (last() resource name) -> { Resource } Multimap<String, Resource> aggregatables = ArrayListMultimap.create(); List<Resource> nonAggregatable = new ArrayList<>(); for (Resource r : children) { if (!isPrintTarget(r)) { continue; } if (r instanceof ContinuousResource) { // non-aggregatable terminal node nonAggregatable.add(r); } else if (Iterables.any(aggregatableTypes, r::isTypeOf)) { // aggregatable & terminal node String simpleName = r.simpleTypeName(); aggregatables.put(simpleName, r); } else { nonAggregatable.add(r); } } // print aggregated (terminal) aggregatables.asMap().entrySet().forEach(e -> { // for each type... String resourceName = e.getKey(); RangeSet<Long> rangeSet = TreeRangeSet.create(); // aggregate into RangeSet e.getValue().stream().map(res -> { if (res.isTypeOf(VlanId.class)) { return (long) res.valueAs(VlanId.class).get().toShort(); } else if (res.isTypeOf(MplsLabel.class)) { return (long) res.valueAs(MplsLabel.class).get().toInt(); } else if (res.isTypeOf(TributarySlot.class)) { return res.valueAs(TributarySlot.class).get().index(); } // TODO support Lambda (OchSignal types) return 0L; }).map(Range::singleton).map(range -> range.canonical(DiscreteDomain.longs())).forEach(rangeSet::add); print("%s%s: %s", Strings.repeat(" ", level + 1), resourceName, rangeSet); }); // print non-aggregatables (recurse) if (sort) { nonAggregatable.stream().sorted((o1, o2) -> String.valueOf(o1.id()).compareTo(String.valueOf(o2.id()))) .forEach(r -> printResource(r, level + 1)); } else { nonAggregatable.forEach(r -> printResource(r, level + 1)); } }
From source file:com.google.api.codegen.configgen.ConfigGenerator.java
private StringBuilder appendIndent(int indent) { return configBuilder.append(Strings.repeat(" ", indent)); }
From source file:org.kalypso.model.wspm.tuhh.core.profile.export.knauf.printer.KnaufSA14Printer.java
@Override public String getContent() { final StringBuilder builder = new StringBuilder(); /**/*www .j a va 2 s . c o m*/ * <pre> * char [3-4], type I2, Ausdruckparameter IA * 0 kein Datenausdruck * </pre> */ builder.append(String.format("%2d", 0)); //$NON-NLS-1$ /** * <pre> * char [5-6], type I2, Steuerparameter NHYD fr das Fliegesetzes * </pre> */ builder.append(String.format("%2d", getBean().getNHyd())); //$NON-NLS-1$ /** * <pre> * char [7-8], type I2, Steuerparameter fr Erweiterungsverluste<br> * abgeminderter Stoverlust nach BORDA-CARNOT * </pre> */ builder.append(String.format("%2d", 1)); //$NON-NLS-1$ /** * <pre> * char [9-12], type I4, Anzahl der Profile eines Berechnungsabschnittes IE * </pre> */ builder.append(String.format("%4d", getBean().getNumberOfProfiles())); //$NON-NLS-1$ /** * char [13-16], type I4, Steuerparameter IPR fr die Ausgabe von Zwischenergebnissen, */ builder.append(String.format("%4d", 0)); //$NON-NLS-1$ /** * char [17-20], type I4, Steuerparameter IPAU fr die Ausgabe von Zwischenergebnissen bei Verzweigungsberechnungen */ builder.append(String.format("%4d", 0)); //$NON-NLS-1$ /** * char [21], empty */ builder.append(" "); //$NON-NLS-1$ /** * <pre> * char [22], type I1, Wahl der Ergebnislisten * IFP = 0 Ausgabe LUA-NRW - DOS-Format * </pre> */ builder.append("0"); //$NON-NLS-1$ /** * <pre> * char [23], type I1, Stellung der berschrift (nur fr IFP = 0) * STATIONAERE WASSERSPIEGELLAGEN * IDR=0 Matrixdrucker, IDR=1 HP-Laserdrucker * </pre> */ builder.append("0"); //$NON-NLS-1$ /** * <pre> * char [24], type I1, Steuerparameter IDAT fr die Dateneingabe * IDAT=0 Kennung der Profile ber Stationierungsangaben * </pre> */ builder.append("0"); //$NON-NLS-1$ builder.append(Strings.repeat(" ", 3)); //$NON-NLS-1$ /** * <pre> * char [28], type I1,Steuerparameter IAUTO fr die automatische Umkehrung der Berechnungsrichtung * IAUTO=0 normale Berechnung ohne Umkehrung * </pre> */ builder.append("0"); //$NON-NLS-1$ builder.append(Strings.repeat(" ", 3)); //$NON-NLS-1$ /** * <pre> * char [32], type I1, Steuerparameter IPUNKT fr die Ergnzung fehlender Nullen bei * formatierter Dateneingabe (nur fr spezielle alte Datenstze) * Default : IPUNKT=0 * </pre> */ builder.append("0"); //$NON-NLS-1$ /** * <pre> * char [33-36], type I4, Steuerparameter IZMAX fr die maximale Zeilenanzahl im Resultatausdruck * Default : IZMAX = 67, bei HTML IZMAX = 88 * </pre> */ builder.append(String.format("%4d", 67)); //$NON-NLS-1$ builder.append(Strings.repeat(" ", 3)); //$NON-NLS-1$ /** * <pre> * char [40], type I1, Steuerparameter NPOSEY * Korrektur des benetzten Umfanges bei gegliederten Querschnitten (nur bei NHYD=1 - 4 ) * NPOSEY = 0 ohne Korrektur * </pre> */ builder.append("0"); //$NON-NLS-1$ builder.append(Strings.repeat(" ", 3)); //$NON-NLS-1$ /** * <pre> * char [44], type I1, Berechnung der magebenden Energiehhe * NBETA = 0 mit Geschwindigkeitsverteilungsbeiwerten ALPHA * </pre> */ builder.append("0"); //$NON-NLS-1$ builder.append(Strings.repeat(" ", 3)); //$NON-NLS-1$ /** * <pre> * char [48], type I1, Steuerparameter IFORM fr die Rechnung mit Formbeiwerten * IFORM= 0 keine Bercksichtigung von Formbeiwerten * </pre> */ builder.append("0"); //$NON-NLS-1$ builder.append(Strings.repeat(" ", 3)); //$NON-NLS-1$ /** * <pre> * char [52], type I1, Wahl der Bezugshhe * NN = 0 Hhenangaben in NN + m (Pegel Amsterdam) * </pre> */ builder.append("0"); //$NON-NLS-1$ /** * <pre> * char [53-54], type I2, IQPO < 0 Datei *.QPO wird nicht erstellt * </pre> */ builder.append(String.format("%2d", 0)); //$NON-NLS-1$ /** * <pre> * char [55-56], type I2, ILPO < 0 Datei *.LPO wird nicht erstellt * </pre> */ builder.append(String.format("%2d", 0)); //$NON-NLS-1$ /** * <pre> * char [57-58], type I2,IUFG 0 Datei *.UFG wird nicht erstellt * </pre> */ builder.append(String.format("%2d", 0)); //$NON-NLS-1$ /** * <pre> * char [59-60], type I2, ISMG 0 Datei *.SMG wird nicht erstellt * </pre> */ builder.append(String.format("%2d", 0)); //$NON-NLS-1$ /** * <pre> * char [61-62], type I2, IHTM < 0 Datei *.HTM wird nicht erstellt * </pre> */ builder.append(String.format("%2d", 0)); //$NON-NLS-1$ /** * <pre> * char [63-64], type I2, IE94 0 Datei *.E94 wird nicht erstellt * </pre> */ builder.append(String.format("%2d", 0)); //$NON-NLS-1$ /** * <pre> * char [65-66], type I2, IE97 < 0 Datei *.E97 wird nicht erstellt * </pre> */ builder.append(String.format("%2d", 0)); //$NON-NLS-1$ /** * <pre> * char [67-68], type I2, IKTAU = 2 alle Profile erhalten Kennzeichen "K" * (Ausgabe K-Tau-Tabellen fr alle Profile) * </pre> */ builder.append(String.format("%2d", 0)); //$NON-NLS-1$ builder.append(Strings.repeat(" ", 2)); //$NON-NLS-1$ /** * <pre> * char [71 - 76], type F6.0, Sinuositt von Manderabflssen SM * </pre> */ builder.append(String.format(Locale.US, "%6.0f", 0.0)); //$NON-NLS-1$ builder.append(" "); //$NON-NLS-1$ /** * <pre> * char [78], type I1, Steuerparameter NFROU zur Berechnung der Froude'schen Zahl * NFROU=0 Berechnung nach Gl. 2.5-9 * </pre> */ builder.append("0"); //$NON-NLS-1$ return builder.toString(); }
From source file:graph.features.shortestPath.ShortestPath.java
public void debug(final PathInterface<T>[][] array) { double max = 0; final int order = this.getGraph().getOrder(); for (int i = 0; i < order; ++i) for (int j = 0; j < order; ++j) if (i != j && array[i][j] != null && array[i][j].getWeight() > max) max = array[i][j].getWeight(); final int n = (int) Math.floor(Math.log10(Double.valueOf(max).intValue())) + 1; for (int i = 0; i < order; ++i) { for (int j = 0; j < order; ++j) { String string;//ww w . j a va 2 s . c o m if (i == j) string = Strings.repeat(".", n); else if (array[i][j] == null) string = Strings.repeat("X", n); else string = Strings.padStart(String.valueOf((int) array[i][j].getWeight()), n, '0'); System.out.print(string + " "); } System.out.println(); } System.out.println(); }
From source file:com.google.googlejavaformat.java.JavaCommentsHelper.java
private List<String> wrapLineComments(List<String> lines, int column0) { List<String> result = new ArrayList<>(); for (String line : lines) { // Add missing leading spaces to line comments: `//foo` -> `// foo`. Matcher matcher = LINE_COMMENT_MISSING_SPACE_PREFIX.matcher(line); if (matcher.find()) { int length = matcher.group(1).length(); line = Strings.repeat("/", length) + " " + line.substring(length); }// w ww . j ava 2 s . c om if (line.startsWith("// MOE:")) { // don't wrap comments for https://github.com/google/MOE result.add(line); continue; } while (line.length() + column0 > Formatter.MAX_LINE_LENGTH) { int idx = Formatter.MAX_LINE_LENGTH - column0; // only break on whitespace characters, and ignore the leading `// ` while (idx >= 2 && !CharMatcher.whitespace().matches(line.charAt(idx))) { idx--; } if (idx <= 2) { break; } result.add(line.substring(0, idx)); line = "//" + line.substring(idx); } result.add(line); } return result; }