Example usage for org.apache.commons.lang3 StringUtils repeat

List of usage examples for org.apache.commons.lang3 StringUtils repeat

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils repeat.

Prototype

public static String repeat(final char ch, final int repeat) 

Source Link

Document

<p>Returns padding using the specified delimiter repeated to a given length.</p> <pre> StringUtils.repeat('e', 0) = "" StringUtils.repeat('e', 3) = "eee" StringUtils.repeat('e', -2) = "" </pre> <p>Note: this method doesn't not support padding with <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a> as they require a pair of char s to be represented.

Usage

From source file:com.stratio.crossdata.sh.utils.ConsoleUtils.java

/**
 * Convert QueryResult {@link com.stratio.crossdata.common.result.QueryResult} structure to String.
 *
 * @param queryResult {@link com.stratio.crossdata.common.result.QueryResult} from execution.
 * @return String representing the result.
 *///from  w ww . j a  v a2s . co  m

private static String stringQueryResult(QueryResult queryResult) {
    if ((queryResult.getResultSet() == null) || queryResult.getResultSet().isEmpty()) {
        return System.lineSeparator() + "0 results returned";
    }

    ResultSet resultSet = queryResult.getResultSet();

    Map<String, Integer> colWidths = calculateColWidths(resultSet);

    String bar = StringUtils.repeat('-', getTotalWidth(colWidths) + (colWidths.values().size() * 3) + 1);

    StringBuilder sb = new StringBuilder(System.lineSeparator());
    sb.append("Partial result: ");
    sb.append(!queryResult.isLastResultSet());
    sb.append(System.lineSeparator());
    sb.append(bar).append(System.lineSeparator());
    sb.append("| ");
    List<String> columnNames = new ArrayList<>();
    for (ColumnMetadata columnMetadata : resultSet.getColumnMetadata()) {
        sb.append(StringUtils.rightPad(columnMetadata.getName().getColumnNameToShow(),
                colWidths.get(columnMetadata.getName().getColumnNameToShow()) + 1)).append("| ");
        columnNames.add(columnMetadata.getName().getColumnNameToShow());
    }

    sb.append(System.lineSeparator());
    sb.append(bar);
    sb.append(System.lineSeparator());

    for (Row row : resultSet) {
        sb.append("| ");
        for (String columnName : columnNames) {
            String str = String.valueOf(row.getCell(columnName.toLowerCase()).getValue());
            sb.append(StringUtils.rightPad(str, colWidths.get(columnName.toLowerCase())));
            sb.append(" | ");
        }
        sb.append(System.lineSeparator());
    }
    sb.append(bar).append(System.lineSeparator());
    return sb.toString();
}

From source file:mase.me.MEFinalRepertoireTextStat.java

protected String toString2D(MESubpopulation sub) {
    StringBuilder sb = new StringBuilder();

    // find the bounds of the repertoire
    Collection<int[]> values = new ArrayList<>(sub.inverseHash.values());
    int min0 = Integer.MAX_VALUE, min1 = Integer.MAX_VALUE, max0 = Integer.MIN_VALUE, max1 = Integer.MIN_VALUE;
    for (int[] v : values) {
        min0 = Math.min(min0, v[0]);
        max0 = Math.max(max0, v[0]);
        min1 = Math.min(min1, v[1]);
        max1 = Math.max(max1, v[1]);
    }// w  w  w  .  j a  va  2 s. c  o m

    // print repertoire
    int pad = Math.max(Integer.toString(min1).length(), Integer.toString(max1).length());
    sb.append(StringUtils.repeat(' ', pad)).append("y\n");
    for (int i1 = max1; i1 >= min1; i1--) {
        sb.append(StringUtils.leftPad(i1 + "", pad)).append("|");
        for (int i0 = min0; i0 <= max0; i0++) {
            int h = sub.hash(new int[] { i0, i1 });
            if (sub.map.containsKey(h)) {
                sb.append("[]");
            } else {
                sb.append("  ");
            }
        }
        sb.append("\n");
    }

    // x-axis lines
    sb.append(StringUtils.repeat(' ', pad)).append('-');
    for (int i0 = min0; i0 <= max0; i0++) {
        sb.append("--");
    }
    sb.append(" x\n");

    // x-axis numbers
    sb.append(StringUtils.repeat(' ', pad + 1));
    int longest = Math.max(Integer.toString(min0).length(), Integer.toString(max0).length());
    int space = (longest + 2) / 2 * 2;
    int order = 0;
    for (int i0 = min0; i0 <= max0; i0++) {
        String s = Integer.toString(i0);
        if (order % (space / 2) == 0) {
            sb.append(StringUtils.rightPad(s, space));
        }
        order++;
    }
    sb.append('\n');
    return sb.toString();
}

From source file:io.github.swagger2markup.markup.builder.internal.AbstractMarkupDocBuilder.java

protected void sectionTitleWithAnchorLevel(Markup markup, int level, String title, String anchor) {
    Validate.notBlank(title, "title must not be blank");
    Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
    documentBuilder.append(newLine);//from www  . j  a  v  a2  s.com
    if (anchor == null)
        anchor = title;
    anchor(replaceNewLinesWithWhiteSpace(anchor)).newLine();
    documentBuilder.append(StringUtils.repeat(markup.toString(), level + 1)).append(" ")
            .append(replaceNewLinesWithWhiteSpace(title)).append(newLine);
}

From source file:com.gmarciani.gmparser.commons.TestNonDeterministicFunction.java

@Test
public void createCompleteAndRemoveAllY() {
    System.out.println("#createCompleteAndRemoveAllY");
    GSet<Character> domainX = new GSet<Character>();
    domainX.add('a');
    domainX.add('b');
    domainX.add('c');
    GSet<Integer> domainY = new GSet<Integer>();
    domainY.add(1);/*  w  w w. j ava2  s.  com*/
    domainY.add(2);
    domainY.add(3);
    GSet<String> domainZ = new GSet<String>();

    for (Character c : domainX) {
        for (Integer n : domainY) {
            for (int i = 1; i <= n; i++)
                domainZ.add(StringUtils.repeat(c, i));
        }
    }

    Function<Character, Integer, String> function = new NonDeterministicFunction<Character, Integer, String>(
            domainX, domainY, domainZ);

    for (Character c : domainX) {
        for (Integer n : domainY) {
            for (int i = 1; i <= n; i++)
                function.add(c, n, StringUtils.repeat(c, i));
        }
    }

    function.removeAllForY(2);

    System.out.println(function);
    System.out.println(function.toFormattedFunction());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlSerializerTest.java

/**
 * Test {@link HtmlSerializer#cleanup(String)}.
 *//*from w  w w .  ja  v  a 2s.c o  m*/
@Test
public void cleanUpPerformanceManyReplaces() {
    final HtmlSerializer serializer = new HtmlSerializer();

    final String text = StringUtils.repeat(" x " + HtmlSerializer.AS_TEXT_BLOCK_SEPARATOR, 20_000);

    final long time = System.currentTimeMillis();
    serializer.cleanUp(text);

    final long runTime = System.currentTimeMillis() - time;
    assertTrue("cleanUp() took too much time", runTime < 1_000);
}

From source file:com.baidu.oped.apm.common.buffer.FixedBufferTest.java

@Test
public void testPadString() throws Exception {
    int TOTAL_LENGTH = 20;
    int TEST_SIZE = 10;
    int PAD_SIZE = TOTAL_LENGTH - TEST_SIZE;
    Buffer buffer = new FixedBuffer(32);
    String test = StringUtils.repeat('a', TEST_SIZE);

    buffer.putPadString(test, TOTAL_LENGTH);

    byte[] result = buffer.getBuffer();
    String decodedString = new String(result);
    String trimString = decodedString.trim();
    Assert.assertEquals(result.length, TOTAL_LENGTH);

    Assert.assertEquals("check data", test, trimString);

    String padString = new String(result, TOTAL_LENGTH - TEST_SIZE, PAD_SIZE, "UTF-8");
    byte[] padBytes = new byte[TOTAL_LENGTH - TEST_SIZE];
    Assert.assertEquals("check pad", padString, new String(padBytes, Charset.forName("UTF-8")));

}

From source file:net.malisis.doors.gui.Digicode.java

@Override
public void drawForeground(GuiRenderer renderer, int mouseX, int mouseY, float partialTick) {
    super.drawForeground(renderer, mouseX, mouseY, partialTick);

    renderer.currentComponent = this;

    renderer.drawRectangle(0, 0, 0, getWidth(), 15, 0x191919, 255);

    MalisisFont font = MalisisDoors.digitalFont;
    FontRenderOptions fro = new FontRenderOptions();
    fro.fontScale = 2F;/*from   w w w.jav  a  2s .co m*/

    fro.color = 0x003300;
    renderer.drawText(font, "888888", fro);

    String code = enteredCode.length() < 6 ? StringUtils.repeat(' ', 6 - enteredCode.length()) + enteredCode
            : enteredCode;

    fro.color = 0x00CC00;
    fro.saveDefault();
    renderer.drawText(font, code, fro);
}

From source file:com.streamsets.datacollector.lineage.LineageEventImpl.java

public LineageEventImpl(LineageEventType type, String name, String user, long startTime, String id, String dcId,
        String permalink, String stageName, String description, String version, Map<String, Object> metadata,
        Map<String, Object> parameters) {
    generalAttributes = new HashMap<>();
    specificAttributes = new HashMap<>();

    generalAttributes.put(LineageGeneralAttribute.EVENT_TYPE, type.toString());
    generalAttributes.put(LineageGeneralAttribute.PIPELINE_TITLE, name);
    generalAttributes.put(LineageGeneralAttribute.PIPELINE_USER, user);
    generalAttributes.put(LineageGeneralAttribute.PIPELINE_START_TIME, Long.toString(startTime));
    generalAttributes.put(LineageGeneralAttribute.SDC_ID, dcId);
    generalAttributes.put(LineageGeneralAttribute.PERMALINK, permalink);
    generalAttributes.put(LineageGeneralAttribute.STAGE_NAME, stageName);
    generalAttributes.put(LineageGeneralAttribute.TIME_STAMP, Long.toString(System.currentTimeMillis()));

    // Need to set description to specificAttributes for START and STOP events so that
    // it will be displayed in Description box. Other events(ENTITY_READ/WRITE) has stage name automatically set
    if (type == LineageEventType.START || type == LineageEventType.STOP) {
        specificAttributes.put(LineageSpecificAttribute.DESCRIPTION, description);
    }//from  w  ww  .j  ava  2  s.com

    // Use Pipeline ID and version if pipeline is generated by SCH, otherwise use SDC generated ones
    if (metadata != null && metadata.containsKey(DPM_PIPELINE_ID)) {
        generalAttributes.put(LineageGeneralAttribute.PIPELINE_ID, (String) metadata.get(DPM_PIPELINE_ID));
        properties.put(LineageGeneralAttribute.PIPELINE_VERSION.getLabel(),
                (String) metadata.get(DPM_PIPELINE_VERSION));
    } else {
        generalAttributes.put(LineageGeneralAttribute.PIPELINE_ID, id);
        properties.put(LineageGeneralAttribute.PIPELINE_VERSION.getLabel(), version);
    }
    // Pipeline labels are stored in metadata if configured
    if (metadata != null && metadata.containsKey(LineageGeneralAttribute.PIPELINE_LABELS.getLabel())) {
        tags = (List) metadata.get(LineageGeneralAttribute.PIPELINE_LABELS.getLabel());
    } else {
        tags = new ArrayList<>();
    }
    // Save Pipeline parameters into properties
    if (parameters != null) {
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            if (sensitiveProperties.matcher(entry.getKey()).matches()) {
                properties.put(entry.getKey(), StringUtils.repeat("*", ((String) entry.getValue()).length()));
            } else {
                properties.put(entry.getKey(), String.valueOf(entry.getValue()));
            }
        }
    }
}

From source file:com.croer.javaorange.diviner.SimpleOrangeTextPane.java

protected void colorStyledDocument(final DefaultStyledDocument document) {
    EventQueue.invokeLater(new Runnable() {

        @Override//w w  w . j  a va2  s.c  o m
        public void run() {
            String input = "";
            try {
                input = document.getText(0, document.getLength());
            } catch (BadLocationException ex) {
                Logger.getLogger(SimpleOrangeTextPane.class.getName()).log(Level.SEVERE, null, ex);
            }

            StringBuilder inputMut = new StringBuilder(input);
            String[] split = StringUtils.split(inputMut.toString());
            int i = 0;
            for (String string : split) {
                int start = inputMut.indexOf(string);
                int end = start + string.length();
                inputMut.replace(start, end, StringUtils.repeat(" ", string.length()));
                document.setCharacterAttributes(start, string.length(), styles[i++ % styles.length], true);
            }
        }
    });
}

From source file:com.epam.ta.reportportal.core.jasper.JasperDataProvider.java

/**
 * Add right shifting for child items depends on depth level
 *
 * @param input/*from   www  .  j  ava  2 s. com*/
 *            - target {@see TestItem}
 * @return TestItem - updated test item with shifted name
 */
private static TestItem adjustName(TestItem input) {
    /* Sync buffer instead builder! */
    StringBuilder sb = new StringBuilder(StringUtils.repeat(PREFIX, input.getPath().size()));
    input.setName(sb.append(input.getName()).toString());
    return input;
}