List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:org.shaf.server.log.XesWriter.java
/** * Writes the end of the XES element./*from ww w . ja v a2s .com*/ * * @param tag * the element tag name. * @throws IOException * if an I/O error occurs during writing process. */ private final void writeEndElement() throws IOException { String tag = this.tags.pop(); this.raf.writeBytes(Strings.repeat(" ", this.tags.size())); this.raf.writeBytes("</" + tag + ">" + System.lineSeparator()); }
From source file:com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Data.Component.BaseTypeTableCellRenderer.java
private static void renderStruct(final TypeInstance instance, final StyledDocument document, final boolean renderData) { final Style structNameStyle = createDeclarationStyle(document); final Style structMemberStyle = document.addStyle("STRUCTMEMBERSTYLE", structNameStyle); StyleConstants.setForeground(structMemberStyle, Color.GRAY); final Style structContentStyle = document.addStyle("STRUCTCONTENTSTYLE", structNameStyle); StyleConstants.setForeground(structContentStyle, Color.BLUE); StyleConstants.setAlignment(structNameStyle, StyleConstants.ALIGN_RIGHT); final BaseType baseType = instance.getBaseType(); int maxMemberLength = 0; for (final TypeMember member : baseType) { if (member.getBaseType().getName().length() > maxMemberLength) { maxMemberLength = member.getBaseType().getName().length(); }//from w w w. j a v a2 s . com } int maxNameLength = 0; for (final TypeMember member : baseType) { if (member.getName().length() > maxNameLength) { maxNameLength = member.getName().length(); } } /* Renders type information for structures - construct a string such as: * * struct STRUCT_NAME { BASE_TYPE_NAME */ try { document.remove(0, document.getLength()); appendString(document, "struct " + baseType.getName() + " {\n", structNameStyle); long memberOffset = 0; for (final TypeMember member : baseType) { appendString(document, " " + member.getBaseType().getName(), structNameStyle); final String separator = Strings.repeat(" ", maxMemberLength - member.getBaseType().getName().length() + 1); appendString(document, separator + member.getName(), structMemberStyle); appendString(document, ";", structMemberStyle); if (renderData) { final String dataSeperator = Strings.repeat(".", maxNameLength - member.getName().length() + 1); appendString(document, dataSeperator, structNameStyle); appendString(document, renderInstanceData(member.getBaseType(), instance.getAddress().getOffset() + memberOffset, instance.getSection()), createDataStyle(document)); memberOffset += member.getBaseType().getByteSize(); } appendString(document, "\n", structMemberStyle); } appendString(document, "};", structNameStyle); } catch (final BadLocationException exception) { CUtilityFunctions.logException(exception); } }
From source file:ee.ria.xroad.opmonitordaemon.OperationalDataRecordsGenerator.java
private static Integer getDummyInteger(int length) { return Integer.parseInt(Strings.repeat("1", length)); }
From source file:org.geogit.cli.porcelain.Branch.java
private void listBranches(GeogitCLI cli) throws IOException { final ConsoleReader console = cli.getConsole(); final GeoGIT geogit = cli.getGeogit(); boolean local = all || !(remotes); boolean remote = all || remotes; ImmutableList<Ref> branches = geogit.command(BranchListOp.class).setLocal(local).setRemotes(remote).call(); final Ref currentHead = geogit.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 {//from www.ja va 2s .co m 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(geogit, branchRef); if (commit.isPresent()) { ansi.a(messageTitle(commit.get())); } } console.println(ansi.toString()); } }
From source file:org.eclipse.xtext.ui.testing.util.AnnotatedTextToString.java
@Override public String toString() { final String cnt = this.getContents(); final Function1<AnnotatedTextToString.CommentedRegion, Integer> _function = ( AnnotatedTextToString.CommentedRegion it) -> { return Integer.valueOf(it.start); };/*from w ww . j a v a 2 s. c o m*/ final Iterable<Pair<Integer, AnnotatedTextToString.CommentedRegion>> sorted = IterableExtensions.<AnnotatedTextToString.CommentedRegion>indexed( IterableExtensions.<AnnotatedTextToString.CommentedRegion, Integer>sortBy(this.regions, _function)); final Function1<Pair<Integer, AnnotatedTextToString.CommentedRegion>, List<Pair<Integer, String>>> _function_1 = ( Pair<Integer, AnnotatedTextToString.CommentedRegion> it) -> { Integer _key = it.getKey(); String _plus = ("<" + _key); String _plus_1 = (_plus + "<"); Pair<Integer, String> _mappedTo = Pair.<Integer, String>of(Integer.valueOf(it.getValue().start), _plus_1); Integer _key_1 = it.getKey(); String _plus_2 = (">" + _key_1); String _plus_3 = (_plus_2 + ">"); Pair<Integer, String> _mappedTo_1 = Pair.<Integer, String>of(Integer.valueOf(it.getValue().end), _plus_3); return Collections.<Pair<Integer, String>>unmodifiableList( CollectionLiterals.<Pair<Integer, String>>newArrayList(_mappedTo, _mappedTo_1)); }; final Function1<Pair<Integer, String>, Integer> _function_2 = (Pair<Integer, String> it) -> { return it.getKey(); }; final List<Pair<Integer, String>> locations = IterableExtensions .<Pair<Integer, String>, Integer>sortBy(Iterables.<Pair<Integer, String>>concat( IterableExtensions.<Pair<Integer, AnnotatedTextToString.CommentedRegion>, List<Pair<Integer, String>>>map( sorted, _function_1)), _function_2); final StringBuilder result = new StringBuilder(); int lastOffset = 0; for (int i = 0; (i < ((Object[]) Conversions.unwrapArray(locations, Object.class)).length); i++) { { final Pair<Integer, String> l = locations.get(i); final Integer offset = l.getKey(); final String comment = l.getValue(); result.append(cnt.substring(lastOffset, (offset).intValue())); result.append(comment); lastOffset = (offset).intValue(); } } result.append(cnt.substring(lastOffset, cnt.length())); final Function1<String, Integer> _function_3 = (String it) -> { return Integer.valueOf(it.length()); }; final Integer maxLineLenght = IterableExtensions.<Integer>max(ListExtensions.<String, Integer>map( ((List<String>) Conversions.doWrapArray(result.toString().replace("\t", " ").split("\r?\n"))), _function_3)); int _length = result.length(); int _minus = (_length - 1); String _substring = result.substring(_minus, result.length()); boolean _notEquals = (!Objects.equal(_substring, "\n")); if (_notEquals) { result.append("\n"); } result.append(Strings.repeat("-", (maxLineLenght).intValue())); boolean _isEmpty = IterableExtensions.isEmpty(sorted); if (_isEmpty) { for (final String c : this.emptyMessage) { { result.append("\n"); result.append(c); } } } else { for (final Pair<Integer, AnnotatedTextToString.CommentedRegion> c_1 : sorted) { { result.append("\n"); result.append(c_1.getKey()); result.append(": "); result.append(c_1.getValue().text); } } } return result.toString(); }
From source file:suneido.util.Dnum.java
/** * Default conversion to string.//from w w w .java 2 s .c o m * Should match cSuneido. */ @Override public String toString() { final int MAX_LEADING_ZEROS = 7; if (isZero()) return "0"; StringBuilder sb = new StringBuilder(20); if (sign < 0) sb.append('-'); if (isInf()) return sb.append("inf").toString(); char digits[] = new char[MAX_DIGITS]; int nd = digits(digits); int e = exp - nd; if (-MAX_LEADING_ZEROS <= exp && exp <= 0) { // decimal to the left sb.append('.').append(Strings.repeat("0", -e - nd)).append(digits, 0, nd); } else if (-nd < e && e <= -1) { // decimal within int d = nd + e; sb.append(digits, 0, d); if (nd > 1) sb.append('.').append(digits, d, nd - d); } else if (0 < exp && exp <= MAX_DIGITS) { // decimal to the right sb.append(digits, 0, nd).append(Strings.repeat("0", e)); } else { // use scientific notation sb.append(digits, 0, 1); if (nd > 1) sb.append('.').append(digits, 1, nd - 1); sb.append('e').append(exp - 1); } return sb.toString(); }
From source file:com.google.security.zynamics.zylib.gui.JStackView.JStackPanel.java
/** * Draws the stack values onto the screen. * /* w w w . j a va 2s . c o m*/ * @param g The graphics context to paint on. */ private void drawElements(final Graphics g) { if (isEnabled()) { // Choose the right color for the offset text g.setColor(m_fontColorValues); } else { g.setColor(m_disabledColor != m_bgColorOffset ? m_disabledColor : Color.WHITE); } final int x = (10 + m_offsetViewWidth) - (m_charWidth * m_firstColumn); int linesToDraw = getNumberOfVisibleRows(); if ((m_firstRow + linesToDraw) >= m_model.getNumberOfEntries()) { linesToDraw = m_model.getNumberOfEntries() - m_firstRow; // TODO: This can make linesToDraw // negative if (linesToDraw < 0) { // FIXME: This is a workaround for case 2337. The issue is real // but reproducing it can take hours. For this reason I am now // implementing this workaround, but in the future the underlying // cause of this behavior should be determined and fixed. return; } } if (m_model.getStartAddress() == -1) { return; } final long elementSize = getElementSize(); if (m_status == DefinitionStatus.DEFINED) { final long startAddress = m_model.getStartAddress() + (m_firstRow * elementSize); final long numberOfBytes = linesToDraw * elementSize; if (!m_model.hasData(startAddress, numberOfBytes)) { setDefinitionStatus(DefinitionStatus.UNDEFINED); setEnabled(false); if (m_updateTimer != null) { m_updateTimer.setRepeats(false); m_updateTimer.stop(); } m_updateTimer = new Timer(1000, new WaitingForDataAction(startAddress, numberOfBytes)); m_updateTimer.setRepeats(true); m_updateTimer.start(); return; } // Iterate over the data and print the offsets for (int i = 0; i < linesToDraw; i++) { final long elementAddress = startAddress + (i * elementSize); g.drawString(m_model.getElement(elementAddress), x, m_paddingTop + (i * m_rowHeight)); } } else { // Iterate over the data and print the offsets for (int i = 0; i < linesToDraw; i++) { g.drawString(Strings.repeat("?", 2 * getElementSize()), x, m_paddingTop + (i * m_rowHeight)); } } }
From source file:com.google.devtools.build.lib.syntax.BinaryOperatorExpression.java
/** * Implements Operator.MULT./*w ww.ja va2s . com*/ * * <p>Publicly accessible for reflection and compiled Skylark code. */ public static Object mult(Object lval, Object rval, Environment env, Location location) throws EvalException { Integer number = null; Object otherFactor = null; if (lval instanceof Integer) { number = (Integer) lval; otherFactor = rval; } else if (rval instanceof Integer) { number = (Integer) rval; otherFactor = lval; } if (number != null) { if (otherFactor instanceof Integer) { return number.intValue() * ((Integer) otherFactor).intValue(); } else if (otherFactor instanceof String) { // Similar to Python, a factor < 1 leads to an empty string. return Strings.repeat((String) otherFactor, Math.max(0, number.intValue())); } else if (otherFactor instanceof MutableList) { // Similar to Python, a factor < 1 leads to an empty string. return MutableList.duplicate((MutableList<?>) otherFactor, Math.max(0, number.intValue()), env); } } throw typeException(lval, rval, Operator.MULT, location); }
From source file:de.unioninvestment.eai.portal.portlet.crud.Settings.java
private void logConfigurationInfo() { StringBuilder builder = new StringBuilder("\n"); String minusLine = Strings.repeat("-", 80) + '\n'; builder.append(minusLine);//from w w w.j a va 2 s .c om builder.append("Crud2Go\n"); builder.append(minusLine); addSortedListOfConfigurationProperties(builder); builder.append(minusLine); LOGGER.info(builder.toString()); }
From source file:co.cask.cdap.cli.util.table.AltStyleTableRenderer.java
/** * Prints a divider./*from w w w. java2s.c o 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) { if (columnWidth != 0) { 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(); }