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

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

Introduction

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

Prototype

public static String repeat(String str, int repeat) 

Source Link

Document

Repeat a String repeat times to form a new String.

Usage

From source file:de.uniwue.info2.generator.TestcaseGenerator.java

/**
 * Get first blockcomment of generated unit-test-file.
 *
 * @return blockcomment with parser and dsl-information
 *//*from  w ww .  java2  s .c o m*/
private String getHeadComment() {
    StringBuffer comment = new StringBuffer();
    comment.append(this.lineComment_ + " " + StringUtils.repeat("*", 60) + "\n");
    comment.append(getSingleCommentTag("parser_description", DSL_PARSER_DESCRIPTION));
    comment.append(getSingleCommentTag("parser_authors", DSL_PARSER_AUTHORS));
    comment.append(getSingleCommentTag("parser_version", DSL_PARSER_VERSION));
    comment.append(this.lineComment_ + " " + StringUtils.repeat("*", 60) + "\n");
    comment.append(getSingleCommentTag("dsl_description", this.dslDescription_));
    comment.append(getSingleCommentTag("dsl_authors", this.dslAuthors_));
    comment.append(getSingleCommentTag("dsl_version", this.dslVersion_));
    comment.append(this.lineComment_ + " " + StringUtils.repeat("*", 60) + "\n");
    return comment.toString();
}

From source file:adalid.core.EntityAtlas.java

private String message(Class<?> type, String name, Object value, int depth, int round) {
    String s1 = StringUtils.repeat(" ", 0 + 4 * depth);
    String s2 = _declaringArtifact + "," + depth + "," + round;
    String s3 = type.getSimpleName() + " " + name + "=" + value;
    String s4 = s1 + s2 + " " + s3;
    return s4;/*from  ww w. ja v  a2s. com*/
}

From source file:de.codesourcery.jasm16.lexer.LexerTest.java

public void testLexerDoesNotChoke() {

    String line = "        ; Try some basic stuff\n"
            + "                      SET A, 0x30              ; 7c01 0030\n"
            + "                      SET [0x1000], 0x20       ; 7de1 1000 0020\n"
            + "                      SUB A, [0x1000]          ; 7803 1000\n"
            + "                      IFN A, 0x10              ; c00d \n"
            + "                         SET PC, crash         ; 7dc1 001a [*]\n" + "                      \n"
            + "        ; Do a loopy thing\n" + "                      SET I, 10                ; a861\n"
            + "                      SET A, 0x2000            ; 7c01 2000\n"
            + "        :loop         SET [0x2000+I], [A]      ; 2161 2000\n"
            + "                      SUB I, 1                 ; 8463\n"
            + "                      IFN I, 0                 ; 806d\n"
            + "                         SET PC, loop          ; 7dc1 000d [*]\n" + "        \n"
            + "        ; Call a subroutine\n" + "                      SET X, 0x4               ; 9031\n"
            + "                      JSR testsub              ; 7c10 0018 [*]\n"
            + "                      SET PC, crash            ; 7dc1 001a [*]\n" + "        \n"
            + "        :testsub      SHL X, 4                 ; 9037\n"
            + "                      SET PC, POP              ; 61c1\n" + "                        \n"
            + "        ; Hang forever. X should now be 0x40 if everything went right.\n"
            + "        :crash        SET PC, crash            ; 7dc1 001a [*]\n" + "        \n"
            + "        ; [*]: Note that these can be one word shorter and one cycle faster by using the short form (0x00-0x1f) of literals,\n"
            + "        ;      but my assembler doesn't support short form labels yet.  ";

    line = StringUtils.repeat(line, 200);

    final Lexer lexer = new Lexer(new Scanner(line));
    final StringBuilder builder = new StringBuilder();
    int lineCount = 0;
    long time = -System.currentTimeMillis();
    final List<IToken> tokens = new ArrayList<IToken>();
    while (!lexer.eof()) {
        final IToken token = lexer.read();
        tokens.add(token);/*from w  ww  .j  a va2s .  c  o  m*/
        if (token.hasType(TokenType.EOL)) {
            lineCount++;
        }
    }
    time += System.currentTimeMillis();

    for (IToken token : tokens) {
        //         System.out.println( token+" ( offset "+token.getParseStartOffset()+" )" );
        builder.append(token.getContents());
    }

    final double linesPerSecond = lineCount / (time / 1000.0);
    final double tokensPerSecond = tokens.size() / (time / 1000.0);

    System.out.println("Lines   : " + (lineCount + 1) + " ( " + linesPerSecond + " lines/s)");
    System.out.println("Tokens  : " + tokens.size() + " ( " + tokensPerSecond + " tokens/s)");

    assertEquals("Lexer failed to consume input completely ?", line, builder.toString());
}

From source file:au.org.ala.delta.key.Key.java

private void printTabularKey(TabularKey key, PrintFile printFile) {
    ItemFormatter itemFormatter = new ItemFormatter(false, CommentStrippingMode.STRIP_ALL,
            AngleBracketHandlingMode.REMOVE, true, false, false);

    // Do a first pass of the data structure to get the counts for the
    // number of times a taxon appears in the key, and to work out how wide
    // the cells need to be
    Map<Item, Integer> itemOccurrences = new HashMap<Item, Integer>();
    int cellWidth = 0;

    for (TabularKeyRow row : key.getRows()) {
        Item it = row.getItem();//from  w  w w .j a v a  2 s  . c  om

        if (itemOccurrences.containsKey(it)) {
            int currentItemCount = itemOccurrences.get(it);
            itemOccurrences.put(it, currentItemCount + 1);
        } else {
            itemOccurrences.put(it, 1);
        }

        // If TRUNCATE TABULAR KEY AT directive has been used, only
        // traverse up to the relevant column.
        int columnLimit = row.getNumberOfColumns();
        if (_context.getTruncateTabularKeyAtColumnNumber() != -1) {
            columnLimit = _context.getTruncateTabularKeyAtColumnNumber();
        }

        for (int i = 0; i < columnLimit; i++) {
            int columnNumber = i + 1;

            for (MultiStateAttribute attr : row.getAllAttributesForColumn(columnNumber)) {
                int characterNumber = attr.getCharacter().getCharacterId();
                int numberOfDigits = Integer.toString(characterNumber).length();

                // Cell width needs to be at least as wide as the number of
                // digits, plus one extra character for the state value
                // associated with the attribute
                if (cellWidth < numberOfDigits + 1) {
                    cellWidth = numberOfDigits + 1;
                }
            }
        }
    }

    // Highest number of item occurrences in the key
    int maxItemOccurrences = Collections.max(itemOccurrences.values());

    // Determine the maximum allowable length for a formatted taxon name in
    // the tabulated key. This will be the length
    // of the name cell, less the length of the largest number of item
    // occurrences (these are printed right-justified) in the cell, with a
    // space between the name and the item occurrence count.
    int maxFormattedItemNameLength = TABULATED_KEY_NAME_CELL_WIDTH
            - Integer.toString(maxItemOccurrences).length() - 1;

    StringBuilder builder = new StringBuilder();

    // Second pass - output the key
    for (int i = 0; i < key.getNumberOfRows(); i++) {
        TabularKeyRow row = key.getRowAt(i);
        Item it = row.getItem();

        List<MultiStateAttribute> rowAttributes;
        List<MultiStateAttribute> previousRowAttributes = null;

        // If TRUNCATE TABULAR KEY AT directive has been used, only
        // traverse up to the relevant column.
        int columnLimit = row.getNumberOfColumns();

        if (_context.getTruncateTabularKeyAtColumnNumber() == -1) {
            rowAttributes = row.getAllAttributes();
            if (i > 0) {
                previousRowAttributes = key.getRowAt(i - 1).getAllAttributes();
            }
        } else {
            columnLimit = _context.getTruncateTabularKeyAtColumnNumber();
            rowAttributes = row.getAllCharacterValuesUpToColumn(columnLimit);
            if (i > 0) {
                previousRowAttributes = key.getRowAt(i - 1).getAllCharacterValuesUpToColumn(columnLimit);
            }
        }

        // Output the dividing line between the previous row and the current
        // row
        builder.append("+---------------------------+");

        for (int j = 0; j < rowAttributes.size(); j++) {
            Attribute currentRowAttribute = rowAttributes.get(j);

            if (previousRowAttributes != null && previousRowAttributes.size() >= j + 1) {
                Attribute previousRowAttribute = previousRowAttributes.get(j);
                if (currentRowAttribute.equals(previousRowAttribute)) {
                    builder.append(StringUtils.repeat(" ", cellWidth));
                    builder.append("|");
                } else {
                    builder.append(StringUtils.repeat("-", cellWidth));
                    builder.append("+");
                }

            } else {
                builder.append(StringUtils.repeat("-", cellWidth));
                builder.append("+");
            }
        }

        if (previousRowAttributes != null) {
            int diffPrevRowAttributes = previousRowAttributes.size() - rowAttributes.size();
            for (int k = 0; k < diffPrevRowAttributes; k++) {
                builder.append(StringUtils.repeat("-", cellWidth));
                builder.append("+");
            }
        }

        builder.append("\n");

        // Output the item name and the number of occurences of the item in
        // the key, if it appears more than once
        builder.append("|");
        String formattedItemName = itemFormatter.formatItemDescription(it);
        formattedItemName = StringUtils.substring(formattedItemName, 0, maxFormattedItemNameLength);
        builder.append(formattedItemName);

        int numItemOccurrences = itemOccurrences.get(it);

        if (numItemOccurrences > 1) {
            builder.append(StringUtils.repeat(" ", TABULATED_KEY_NAME_CELL_WIDTH - formattedItemName.length()
                    - Integer.toString(numItemOccurrences).length()));
            builder.append(numItemOccurrences);
        } else {
            builder.append(StringUtils.repeat(" ", TABULATED_KEY_NAME_CELL_WIDTH - formattedItemName.length()));
        }

        builder.append("|");

        // Output the values character values used in the. Include values
        // for confirmatory characters if they are present
        for (int j = 0; j < columnLimit; j++) {
            int columnNumber = j + 1;
            List<MultiStateAttribute> cellCharacterValues = row.getAllAttributesForColumn(columnNumber);
            for (int k = 0; k < cellCharacterValues.size(); k++) {
                MultiStateAttribute cellCharacterValue = cellCharacterValues.get(k);
                int characterId = cellCharacterValue.getCharacter().getCharacterId();

                // Insert spaces to pad out the cell if the character id +
                // state
                // value are not as wide as the cell width
                builder.append(
                        StringUtils.repeat(" ", cellWidth - (Integer.toString(characterId).length() + 1)));

                builder.append(characterId);

                // Only 1 state will be ever set - the key generation
                // algorithm
                // only sets
                // Individual states for characters
                int stateNumber = cellCharacterValue.getPresentStates().iterator().next();
                // Convert state numbers to "A", "B", "C" etc
                builder.append((char) (64 + stateNumber));

                if (cellCharacterValues.size() > 1 && k < cellCharacterValues.size() - 1) {
                    builder.append(" ");
                }
            }

            builder.append("|");
        }

        builder.append("\n");

        // If this is the last row, need to print the bottom edge of the
        // table
        if (i == key.getNumberOfRows() - 1) {
            builder.append("+---------------------------+");
            for (int l = 0; l < rowAttributes.size(); l++) {
                builder.append(StringUtils.repeat("-", cellWidth));
                builder.append("+");
            }
        }
    }

    printPagedTabularKey(builder.toString(), cellWidth, printFile);
}

From source file:adalid.commons.util.StrUtils.java

public static String tabs(int n) {
    return StringUtils.repeat("\t", n);
}

From source file:de.uniwue.info2.generator.TestcaseGenerator.java

/**
 * Function to replace one PlaceHolder-String in current unit-test.
 *
 * @param original//from  w w w .  j ava 2  s  .c  o m
 *         original string, to replace PlaceHolder in.
 * @param placeholder
 *         PlaceHolder-string
 * @param insert
 *         new string to replace PlaceHolder with.
 * @return new modified string
 */
private String replacePlaceHolder(String original, String placeholder, String insert) {
    Pattern variable = Pattern.compile(
            "\\" + getID() + "(\\{[st]{1}_[0-9]*\\})?" + placeholder.replace(getID(), "") + "\\" + getID(),
            Pattern.CASE_INSENSITIVE);
    Matcher variableMatcher = variable.matcher(original);

    while (variableMatcher.find()) {
        String var = variableMatcher.group();

        Pattern spacePattern = Pattern.compile("\\{[st]{1}_[0-9]*\\}", Pattern.CASE_INSENSITIVE);
        Matcher spaceMatcher = spacePattern.matcher(var);

        if (spaceMatcher.find()) {
            String spaceIndicator = spaceMatcher.group();
            String spaceVar = spaceIndicator.replaceAll("[\\{\\}ts_]", "");
            String space = "";
            if (spaceIndicator.contains("{t_")) {
                space = StringUtils.repeat("\t", Short.valueOf(spaceVar));
            } else if (spaceIndicator.contains("{s_")) {
                space = StringUtils.repeat(" ", Short.valueOf(spaceVar));
            }
            insert = space + insert.replace("\n", "\n" + space);
            if (insert.endsWith(space)) {
                insert = insert.substring(0, insert.length() - space.length());
            }
        }
        original = original.replace(var, insert);
    }
    return original;
}

From source file:musite.ui.MusiteResultPanel.java

private Vector formatData(Collection<Protein> proteinsList, boolean displayScoreInSequence,
        boolean displayHeader) {
    if (proteinsList == null) {
        return null;
    }/*from  w w w  . j  a v  a 2s.  c  om*/

    PredictionModel model = selectedModel();

    Vector data = new Vector();

    for (Protein protein : proteinsList) {
        String acc = protein.getAccession();
        Map<Integer, Double> preds = result.getPredictedSites(model, acc);
        if (preds == null || preds.isEmpty())
            continue;

        if (displayHeader) {
            Vector vec = new Vector(1);
            vec.add('>' + protein.toString());
            data.add(vec);
        }

        String proteinSeq = protein.getSequence();
        int len = proteinSeq.length();

        for (Map.Entry<Integer, Double> entry : preds.entrySet()) {
            int site = entry.getKey();

            char aa = proteinSeq.charAt(site);

            double score = preds.get(site);

            String seq;
            if (site < offset) {
                seq = StringUtils.repeat("*", offset - site) + proteinSeq.substring(0, site);
            } else {
                seq = proteinSeq.substring(site - offset, site);
            }

            if (displayScoreInSequence)
                seq += "[" + score + aa + "]";
            else
                seq += aa + "#";

            int end = site + offset + 1;
            if (end > len) {
                seq += proteinSeq.substring(site + 1, len) + StringUtils.repeat("*", end - len);
            } else {
                seq += proteinSeq.substring(site + 1, end);
            }

            Vector vec = new Vector(header.size());
            vec.add(site + 1);
            vec.add(aa);
            vec.add(seq);

            vec.add(String.format("%.2f", score));

            SpecificityEstimator est = selectedModel().getSpecEstimator();
            String strSpec;
            if (est != null) {
                double spec = est.specificity(score);
                strSpec = String.format("%.2f%%", 100 * spec);
            } else {
                strSpec = "";
            }
            vec.add(strSpec);
            //                vec.add(String.format("%.2f%%", 100*sens));
            data.add(vec);
        }
    }

    return data;
}

From source file:adalid.core.Project.java

@Override
protected String fieldsToString(int n, String key, boolean verbose, boolean fields, boolean maps) {
    String tab = verbose ? StringUtils.repeat(" ", 4) : "";
    String fee = verbose ? StringUtils.repeat(tab, n) : "";
    String faa = " = ";
    String foo = verbose ? EOL : ", ";
    String string = super.fieldsToString(n, key, verbose, fields, maps);
    if (fields || verbose) {
        string += fee + tab + "entities" + faa + _entityReferences.size() + foo;
        string += fee + tab + "projects" + faa + _projectReferences.size() + foo;
    }// ww  w  .  j av a 2  s.  c  om
    return string;
}

From source file:au.org.ala.delta.key.Key.java

private void printPagedTabularKey(String tabularKey, int cellWidth, PrintFile printFile) {
    int pageWidth = _context.getOutputFileManager().getOutputWidth();
    pageWidth = pageWidth == 0 ? PrintFile.DEFAULT_PRINT_WIDTH : pageWidth;

    // add 2 dividers to width of name.
    int endTaxonNamesColumn = TABULATED_KEY_NAME_CELL_WIDTH + 2;

    // add 1 divider for each attribute column cell.
    int maxAttrValuesPerPage = (pageWidth - (endTaxonNamesColumn)) / (cellWidth + 1);

    List<String> taxonNameColumnPieces = new ArrayList<String>();
    List<List<String>> allAttributeColumnsPieces = new ArrayList<List<String>>();
    int maxNumberOfAttrColumnsPieces = 0;

    List<String> tabularKeyLines = Arrays.asList(StringUtils.split(tabularKey, '\n'));

    for (String line : tabularKeyLines) {
        taxonNameColumnPieces.add(line.substring(0, endTaxonNamesColumn));

        List<String> lineAttributeColumnsPieces = new ArrayList<String>();

        int pieceStartIndex = endTaxonNamesColumn;
        int pieceEndIndex = Math.min(endTaxonNamesColumn + ((cellWidth + 1) * maxAttrValuesPerPage),
                line.length());//from  w ww. j av a  2 s.c  o m

        while (pieceStartIndex < line.length()) {
            String piece = line.substring(pieceStartIndex, pieceEndIndex);
            lineAttributeColumnsPieces.add(piece);

            pieceStartIndex = pieceEndIndex;
            pieceEndIndex = Math.min(pieceEndIndex + ((cellWidth + 1) * maxAttrValuesPerPage), line.length());
        }

        allAttributeColumnsPieces.add(lineAttributeColumnsPieces);
        maxNumberOfAttrColumnsPieces = Math.max(maxNumberOfAttrColumnsPieces,
                lineAttributeColumnsPieces.size());
    }

    for (int i = 0; i < maxNumberOfAttrColumnsPieces; i++) {
        if (i > 0) {
            printFile.writeBlankLines(1, 0);
            printFile.outputLine(_context.getHeading(HeadingType.HEADING));
            printFile.outputLine(StringUtils.repeat("*", _context.getOutputFileSelector().getOutputWidth()));
            printFile.writeBlankLines(1, 0);
        }

        for (int j = 0; j < taxonNameColumnPieces.size(); j++) {
            List<String> lineAttributeColumnsPieces = allAttributeColumnsPieces.get(j);

            if (lineAttributeColumnsPieces.size() >= i + 1) {
                printFile.outputLine(taxonNameColumnPieces.get(j) + lineAttributeColumnsPieces.get(i));
            } else {
                printFile.outputLine(taxonNameColumnPieces.get(j));
            }
        }
    }
}

From source file:adalid.core.AbstractPersistentEntity.java

@Override
protected String fieldsToString(int n, String key, boolean verbose, boolean fields, boolean maps) {
    String tab = verbose ? StringUtils.repeat(" ", 4) : "";
    String fee = verbose ? StringUtils.repeat(tab, n) : "";
    String faa = " = ";
    String foo = verbose ? EOL : ", ";
    String string = super.fieldsToString(n, key, verbose, fields, maps);
    if (fields || verbose) {
        if (verbose) {
            if (isEntityReference()) {
                string += fee + tab + "foreignKey" + faa + isForeignKey() + foo;
                string += fee + tab + "onDeleteAction" + faa + _onDeleteAction + foo;
                string += fee + tab + "onUpdateAction" + faa + _onUpdateAction + foo;
            } else {
                string += fee + tab + "baseTableClass" + faa + _baseTableClass + foo;
                string += fee + tab + "inheritanceMappingStrategy" + faa + _inheritanceMappingStrategy + foo;
                if (InheritanceMappingStrategy.UNSPECIFIED.equals(_inheritanceMappingStrategy)) {
                } else {
                    //                      string += fee + tab + "discriminatorFieldName" + faa + _discriminatorFieldName + foo;
                    //                      string += fee + tab + "discriminatorField" + faa + _discriminatorField + foo;
                    string += fee + tab + "discriminatorProperty" + faa + _discriminatorProperty + foo;
                    string += fee + tab + "discriminatorValue" + faa + _discriminatorValue + foo;
                }//from   w w w  .ja  va2s .c o  m
                string += fee + tab + "triggerBeforeValueEnabled" + faa + _triggerBeforeValueEnabled + foo;
                string += fee + tab + "triggerAfterValueEnabled" + faa + _triggerAfterValueEnabled + foo;
                string += fee + tab + "triggerBeforeCheckEnabled" + faa + _triggerBeforeCheckEnabled + foo;
                string += fee + tab + "triggerAfterCheckEnabled" + faa + _triggerAfterCheckEnabled + foo;
            }
        }
    }
    return string;
}