List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:com.google.api.explorer.client.parameter.schema.ObjectSchemaEditor.java
@Override public void prettyPrint(StringBuilder resultSoFar, int indentation) { if (resultSoFar.length() > 0) { resultSoFar.append("\n"); }/*w w w .j a v a2 s .c o m*/ resultSoFar.append(Strings.repeat(INDENTATION, indentation)).append("{"); boolean first = true; // Add the properties with fixed keys. for (Map.Entry<String, SchemaEditor> entry : allEditors()) { if (!first) { resultSoFar.append(","); } first = false; resultSoFar.append("\n").append(Strings.repeat(INDENTATION, indentation + 1)).append("\"") .append(entry.getKey()).append("\": "); entry.getValue().prettyPrint(resultSoFar, indentation + 1); } resultSoFar.append("\n").append(Strings.repeat(INDENTATION, indentation)).append("}"); }
From source file:co.cask.cdap.cli.command.system.HelpCommand.java
/** * Prints the given string with text wrapping at the given column width. * * @param str the string to print//ww w . j a va 2 s .c om * @param output the {@link PrintStream} to write to * @param colWidth width of the column * @param prefixSpaces number of spaces as the prefix for each line printed */ private void wrappedPrint(String str, PrintStream output, int colWidth, int prefixSpaces) { String prefix = Strings.repeat(" ", prefixSpaces); colWidth -= prefixSpaces; if (str.length() <= colWidth) { output.printf("%s%s", prefix, str); output.println(); return; } int beginIdx = 0; while (beginIdx < str.length()) { int idx; if (beginIdx + colWidth >= str.length()) { idx = str.length(); } else { idx = str.lastIndexOf(' ', beginIdx + colWidth); } // Cannot break line if no space found between beginIdx and (beginIdx + colWidth) // The best we can do is to look forward. // The line will be longer than colWidth though. if (idx < 0 || idx < beginIdx) { idx = str.indexOf(' ', beginIdx + colWidth); if (idx < 0) { idx = str.length(); } } output.printf("%s%s", prefix, str.substring(beginIdx, idx)); beginIdx = idx + 1; output.println(); } }
From source file:emily.util.Misc.java
/** * helper function for makeAsciiTable/*from w ww . ja va 2s.c o m*/ * * @param left character on the left * @param middle character in the middle * @param right character on the right * @param padding controllers cell padding * @param sizes width of each cell * @return a filler row for the controllers */ private static String appendSeparatorLine(String left, String middle, String right, int padding, int... sizes) { boolean first = true; StringBuilder ret = new StringBuilder(); for (int size : sizes) { if (first) { first = false; ret.append(left).append(Strings.repeat("-", size + padding * 2)); } else { ret.append(middle).append(Strings.repeat("-", size + padding * 2)); } } return ret.append(right).append("\n").toString(); }
From source file:com.android.tools.idea.logcat.AndroidLogcatFormatter.java
@Override public String formatMessage(String msg) { String continuation = tryParseContinuation(msg); if (continuation != null) { return Strings.repeat(" ", myLastHeaderLength) + continuation; } else {//from w w w . j a v a2 s. co m LogCatMessage message = tryParseMessage(msg); if (message != null) { String formatted = formatMessage(myPreferences.LOGCAT_FORMAT_STRING, msg); myLastHeaderLength = formatted.indexOf(message.getMessage()); return formatted; } } return msg; // Unknown message format, return as is }
From source file:org.locationtech.geogig.cli.porcelain.Branch.java
private void listBranches(GeogigCLI cli) throws IOException { final ConsoleReader console = cli.getConsole(); final GeoGIG geogig = cli.getGeogig(); boolean local = all || !(remotes); boolean remote = all || remotes; ImmutableList<Ref> branches = geogig.command(BranchListOp.class).setLocal(local).setRemotes(remote).call(); final Ref currentHead = geogig.command(RefParse.class).setName(Ref.HEAD).call().get(); final int largest = verbose ? largestLenght(branches) : 0; for (Ref branchRef : branches) { final String branchRefName = branchRef.getName(); Ansi ansi = newAnsi(console.getTerminal()); if ((currentHead instanceof SymRef) && ((SymRef) currentHead).getTarget().equals(branchRefName)) { ansi.a("* ").fg(Color.GREEN); } else {/*w ww. j ava 2s . c om*/ ansi.a(" "); } // print unqualified names for local branches String branchName = refDisplayString(branchRef); ansi.a(branchName); ansi.reset(); if (verbose) { ansi.a(Strings.repeat(" ", 1 + (largest - branchName.length()))); ansi.a(branchRef.getObjectId().toString().substring(0, 7)).a(" "); Optional<RevCommit> commit = findCommit(geogig, branchRef); if (commit.isPresent()) { ansi.a(messageTitle(commit.get())); } } console.println(ansi.toString()); } }
From source file:org.openhab.binding.max.internal.message.C_Message.java
@Override public void debug(Logger logger) { logger.trace("=== C_Message === "); logger.trace("\tRAW: {}", this.getPayload()); logger.trace("DeviceType: {}", deviceType.toString()); logger.trace("SerialNumber: {}", serialNumber); logger.trace("RFAddress: {}", rfAddress); for (String key : properties.keySet()) { logger.trace("{}:{}{}", key, Strings.repeat(" ", 25 - key.length()), properties.get(key)); }/* w w w .j a v a 2 s . c o m*/ logger.trace("ProgramData: {}", programData); }
From source file:org.apache.james.mailrepository.MailRepositoryContract.java
@Test default void retrieveBigMailShouldHaveSameHash() throws Exception { MailRepository testee = retrieveRepository(); String bigString = Strings.repeat("my mail is big ?", 1_000_000); Mail mail = createMail(MAIL_1, bigString); testee.store(mail);// w w w .j a v a 2 s . c o m Mail actual = testee.retrieve(MAIL_1); assertThat(Hashing.sha256().hashString((String) actual.getMessage().getContent(), StandardCharsets.UTF_8)) .isEqualTo(Hashing.sha256().hashString(bigString, StandardCharsets.UTF_8)); }
From source file:com.technophobia.substeps.runner.JunitFeatureRunner.java
private static String printDescription(final Description desc, final int depth) { final StringBuilder buf = new StringBuilder(); buf.append(Strings.repeat("\t", depth)); buf.append(desc.getDisplayName()).append("\n"); if (desc.getChildren() != null && !desc.getChildren().isEmpty()) { for (final Description d : desc.getChildren()) { buf.append(printDescription(d, depth + 1)); }/*from ww w.ja va2 s . c o m*/ } return buf.toString(); }
From source file:com.google.devtools.build.lib.rules.cpp.LibrariesToLinkCollector.java
/** * When linking a shared library fully or mostly static then we need to link in *all* dependent * files, not just what the shared library needs for its own code. This is done by wrapping all * objects/libraries with -Wl,-whole-archive and -Wl,-no-whole-archive. For this case the * globalNeedWholeArchive parameter must be set to true. Otherwise only library objects (.lo) need * to be wrapped with -Wl,-whole-archive and -Wl,-no-whole-archive. * * <p>TODO: Factor out of the bazel binary into build variables for crosstool action_configs. */// w ww . j a v a 2 s .c o m public CollectedLibrariesToLink collectLibrariesToLink() { ImmutableSet.Builder<String> librarySearchDirectories = ImmutableSet.builder(); ImmutableSet.Builder<String> runtimeLibrarySearchDirectories = ImmutableSet.builder(); ImmutableSet.Builder<String> rpathRootsForExplicitSoDeps = ImmutableSet.builder(); ImmutableSet.Builder<LinkerInput> expandedLinkerInputsBuilder = ImmutableSet.builder(); // List of command line parameters that need to be placed *outside* of // --whole-archive ... --no-whole-archive. SequenceBuilder librariesToLink = new SequenceBuilder(); String toolchainLibrariesSolibName = toolchainLibrariesSolibDir != null ? toolchainLibrariesSolibDir.getBaseName() : null; if (isNativeDeps && cppConfiguration.shareNativeDeps()) { if (needToolchainLibrariesRpath) { runtimeLibrarySearchDirectories.add("../" + toolchainLibrariesSolibName + "/"); } } else { // For all other links, calculate the relative path from the output file to _solib_[arch] // (the directory where all shared libraries are stored, which resides under the blaze-bin // directory. In other words, given blaze-bin/my/package/binary, rpathRoot would be // "../../_solib_[arch]". if (needToolchainLibrariesRpath) { runtimeLibrarySearchDirectories .add(Strings.repeat("../", outputArtifact.getRootRelativePath().segmentCount() - 1) + toolchainLibrariesSolibName + "/"); } if (isNativeDeps) { // We also retain the $ORIGIN/ path to solibs that are in _solib_<arch>, as opposed to // the package directory) if (needToolchainLibrariesRpath) { runtimeLibrarySearchDirectories.add("../" + toolchainLibrariesSolibName + "/"); } } } if (needToolchainLibrariesRpath) { if (isNativeDeps) { runtimeLibrarySearchDirectories.add("."); } runtimeLibrarySearchDirectories.add(toolchainLibrariesSolibName + "/"); } Pair<Boolean, Boolean> includeSolibsPair = addLinkerInputs(librarySearchDirectories, rpathRootsForExplicitSoDeps, librariesToLink, expandedLinkerInputsBuilder); boolean includeSolibDir = includeSolibsPair.first; boolean includeToolchainLibrariesSolibDir = includeSolibsPair.second; Preconditions.checkState(ltoMap == null || ltoMap.isEmpty(), "Still have LTO objects left: %s", ltoMap); ImmutableSet.Builder<String> allRuntimeLibrarySearchDirectories = ImmutableSet.builder(); // rpath ordering matters for performance; first add the one where most libraries are found. if (includeSolibDir) { allRuntimeLibrarySearchDirectories.add(rpathRoot); } allRuntimeLibrarySearchDirectories.addAll(rpathRootsForExplicitSoDeps.build()); if (includeToolchainLibrariesSolibDir) { allRuntimeLibrarySearchDirectories.addAll(runtimeLibrarySearchDirectories.build()); } return new CollectedLibrariesToLink(librariesToLink, expandedLinkerInputsBuilder.build(), librarySearchDirectories.build(), allRuntimeLibrarySearchDirectories.build()); }
From source file:org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.table.TableContentMergeViewer.java
/** * {@inheritDoc}/*from w w w . j av a 2s . c o m*/ * * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#createMergeViewer(org.eclipse.swt.widgets.Composite, * org.eclipse.emf.compare.rcp.ui.mergeviewer.IMergeViewer.MergeViewerSide) */ @Override protected AbstractMergeViewer createMergeViewer(Composite parent, final MergeViewerSide side) { TableMergeViewer ret = new TableMergeViewer(parent, side, this, getCompareConfiguration()); ret.getStructuredViewer().getTable().getVerticalBar().setVisible(false); ret.setContentProvider(new ArrayContentProvider() { /** * {@inheritDoc} * * @see org.eclipse.jface.viewers.ArrayContentProvider#getElements(java.lang.Object) */ @Override public Object[] getElements(Object inputElement) { if (inputElement instanceof ICompareAccessor) { return super.getElements(((ICompareAccessor) inputElement).getItems()); } return super.getElements(inputElement); } }); ret.setLabelProvider( new AdapterFactoryLabelProvider.FontAndColorProvider(fAdapterFactory, ret.getStructuredViewer()) { /** * {@inheritDoc} * * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider#getFont(java.lang.Object, * int) */ @Override public Font getFont(Object object, int columnIndex) { if (object instanceof IMergeViewerItem) { final Object value = ((IMergeViewerItem) object).getSideValue(side); if (value instanceof EObject && ((EObject) value).eIsProxy()) { return getFontFromObject(IItemFontProvider.ITALIC_FONT); } } return super.getFont(object, columnIndex); } /** * {@inheritDoc} * * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider#getColumnText(java.lang.Object, * int) */ @Override public String getColumnText(Object object, int columnIndex) { if (object instanceof IMergeViewerItem) { final String text; IMergeViewerItem mergeViewerItem = (IMergeViewerItem) object; final Object value = mergeViewerItem.getSideValue(side); if (value instanceof EObject && ((EObject) value).eIsProxy()) { text = "proxy : " + ((InternalEObject) value).eProxyURI().toString(); //$NON-NLS-1$ } else if (mergeViewerItem.isInsertionPoint()) { // workaround for 406513: Windows specific issue. Only labels of (Tree/Table)Item are // selectable on Windows platform. The labels of placeholders in (Tree/Table)Viewer // are one whitespace. Placeholder are then selectable at the very left of itself. // Add a 42 whitespaces label to workaround. text = Strings.repeat(" ", 42); //$NON-NLS-1$ } else { text = super.getColumnText(value, columnIndex); } return text; } return super.getColumnText(object, columnIndex); } /** * {@inheritDoc} * * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider#getColumnImage(java.lang.Object, * int) */ @Override public Image getColumnImage(Object object, int columnIndex) { if (object instanceof IMergeViewerItem) { IMergeViewerItem mergeViewerItem = (IMergeViewerItem) object; if (((IMergeViewerItem) object).isInsertionPoint()) { return null; } else { Object sideValue = mergeViewerItem.getSideValue(side); Image superImage = super.getColumnImage(sideValue, columnIndex); if (superImage == null) { return getDefaultImage(sideValue); } else { return superImage; } } } return super.getColumnImage(object, columnIndex); } }); ret.getStructuredViewer().getTable().getVerticalBar().addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { redrawCenterControl(); } }); ret.getStructuredViewer().getTable().addMouseWheelListener(new MouseWheelListener() { public void mouseScrolled(MouseEvent e) { redrawCenterControl(); } }); ret.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { redrawCenterControl(); } }); return ret; }