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:org.eclipse.skalli.core.extension.ProjectDescriptionValidatorTest.java

@Test
public void testIssuesINFO() throws Exception {
    assertDescriptionInvalid(StringUtils.repeat("a", 1), Project.FORMAT_HTML, Severity.INFO, Severity.INFO);
    assertDescriptionInvalid(StringUtils.repeat("a", 10), Project.FORMAT_HTML, Severity.INFO, Severity.INFO);
    assertDescriptionInvalid(StringUtils.repeat("a", 24), Project.FORMAT_HTML, Severity.INFO, Severity.INFO);

    assertDescriptionValid(StringUtils.repeat("a", 1), Project.FORMAT_HTML, Severity.WARNING);
    assertDescriptionValid(StringUtils.repeat("a", 10), Project.FORMAT_HTML, Severity.WARNING);
    assertDescriptionValid(StringUtils.repeat("a", 24), Project.FORMAT_HTML, Severity.WARNING);
}

From source file:org.eclipse.skalli.core.extension.ProjectDescriptionValidatorTest.java

@Test
public void testNoIssues() throws Exception {
    assertDescriptionValid(StringUtils.repeat("a", ProjectDescriptionValidator.DESCRIPTION_RECOMMENDED_LENGHT),
            Project.FORMAT_HTML, Severity.INFO);
    assertDescriptionValid(/*from   w  w w .ja  v  a  2  s. c o  m*/
            StringUtils.repeat("a", ProjectDescriptionValidator.DESCRIPTION_RECOMMENDED_LENGHT + 1),
            Project.FORMAT_HTML, Severity.INFO);
    assertDescriptionValid(
            StringUtils.repeat("a", ProjectDescriptionValidator.DESCRIPTION_RECOMMENDED_LENGHT + 4711),
            Project.FORMAT_HTML, Severity.INFO);

    assertDescriptionValid(null, Project.FORMAT_HTML, Severity.FATAL);
    assertDescriptionValid(null, Project.FORMAT_HTML, Severity.ERROR);
    assertDescriptionValid("", Project.FORMAT_HTML, Severity.FATAL);
    assertDescriptionValid("", Project.FORMAT_HTML, Severity.ERROR);
    assertDescriptionValid("    ", Project.FORMAT_HTML, Severity.FATAL);
    assertDescriptionValid("    ", Project.FORMAT_HTML, Severity.ERROR);
}

From source file:org.eclipse.smila.binarystorage.persistence.io.test.TestBinaryPersistence.java

public void testSpecialKeys() throws Exception {
    BinaryStorageService bss = super.getService(BinaryStorageService.class);

    // short key//from   w w w  .j  a  va2s .  co m
    bssCrud(bss, "a");

    // special char keys
    String[] forbiddenIds = { "\\", "/", ":", ";", "", "  ", null };
    for (String id : forbiddenIds) {
        try {
            bssCrud(bss, id);
            bss.store(id, CONTENT_BYTES); // this is just to see if the file realy exists in storage
            fail("expected exception @ id: [" + id + "]");
        } catch (BinaryStorageException e) {
        }

    }

    // very long keys
    try {
        bssCrud(bss, StringUtils.repeat("a", 1024));
        fail();
    } catch (Exception e) {
    }

}

From source file:org.eclipse.wb.internal.core.editor.ObjectPathHelper.java

/**
 * @return the text dump of given {@link ObjectInfo} and its children.
 *///  w w  w.j ava 2  s. c  o m
public static String getObjectsDump(ObjectInfo objectInfo, int level) {
    StringBuilder result = new StringBuilder();
    result.append(StringUtils.repeat(" ", level));
    // add this object
    result.append(objectInfo.getClass().getName());
    result.append("\n");
    // add children
    for (ObjectInfo child : objectInfo.getChildren()) {
        result.append(getObjectsDump(child, level + 1));
    }
    //
    return result.toString();
}

From source file:org.eclipse.wb.internal.core.model.generation.preview.GenerationPreview.java

/**
 * @return the {@link String} for joined given {@link String}'s using "\n".
 *///w w w  .  j a  va 2 s. co  m
protected static String getSource(String[][] lines2) {
    StringBuffer buffer = new StringBuffer();
    for (String[] lines : lines2) {
        if (lines == null) {
            continue;
        }
        //
        for (String line : lines) {
            // prepare count of leading spaces
            int spaceCount = 0;
            for (char c : line.toCharArray()) {
                if (c != ' ') {
                    break;
                }
                spaceCount++;
            }
            // replace each two leading spaces with one \t
            Assert.isTrue(spaceCount % 2 == 0);
            line = StringUtils.repeat("\t", spaceCount / 2) + line.substring(spaceCount);
            // append line
            buffer.append(line);
            buffer.append("\n");
        }
    }
    return buffer.toString();
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstCodeGeneration.java

/**
 * Return the string of characters that is to be used to indent code the given number of levels.
 * // ww  w.  ja v a2s  .co  m
 * @param levels
 *          the number of levels of indentation to be returned
 * 
 * @return the string of characters that is to be used to indent code
 */
public String getIndentation(int levels) {
    Assert.isTrue(levels >= 0);
    if (levels == 0) {
        return "";
    }
    // prepare indentation character and count of them for single level
    String indentationChar;
    int count;
    {
        String tabChar = getTabChar();
        if (tabChar != null && tabChar.toLowerCase().equals("space")) {
            indentationChar = " ";
            count = 4;
            try {
                String tabSize = getTabSize();
                count = Integer.parseInt(tabSize);
            } catch (Throwable e) {
            }
        } else {
            indentationChar = "\t";
            count = 1;
        }
    }
    // return result
    return StringUtils.repeat(indentationChar, count * levels);
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java

/**
 * @return single source {@link String} for given lines of source.
 * //from   w  w w.  j  ava2s .  c  om
 * @param lines
 *          the lines of source
 * @param indent
 *          the "base" indentation
 * @param singleIndent
 *          the indentation that to replace each leading "\t"
 * @param eol
 *          the EOL string
 */
private static String getIndentedSource(List<String> lines, String indent, String singleIndent, String eol) {
    StringBuffer buffer = new StringBuffer();
    for (String line : lines) {
        // EOL
        if (buffer.length() != 0) {
            buffer.append(eol);
        }
        // indentation
        buffer.append(indent);
        // line
        if (line.length() != 0) {
            int tabsCount = StringUtils.indexOfAnyBut(line, "\t");
            if (tabsCount != -1) {
                buffer.append(StringUtils.repeat(singleIndent, tabsCount));
                buffer.append(line.substring(tabsCount));
            } else {
                buffer.append(StringUtils.repeat(singleIndent, line.length()));
            }
        }
    }
    return buffer.toString();
}

From source file:org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils.java

/**
 * Replaces in given Java source hidden parts of code with spaces.
 * //from  www . j  a v a 2s .c o  m
 * @return the cleared Java source.
 */
private static String clearHiddenCode(String source) throws Exception {
    // remove hidden code blocks
    {
        String beginTag = clearHiddenCode_getTag(IPreferenceConstants.P_CODE_HIDE_BEGIN);
        String endTag = clearHiddenCode_getTag(IPreferenceConstants.P_CODE_HIDE_END);
        while (true) {
            int beginIndex = source.indexOf(beginTag);
            int endIndex = source.indexOf(endTag);
            // validate begin/end indexes
            if (beginIndex == -1 && endIndex == -1) {
                break;
            }
            if (beginIndex == -1 && endIndex != -1) {
                throw new IllegalStateException("Unexpected state - no hide start and hide stop found.");
            }
            if (beginIndex != -1 && endIndex == -1) {
                throw new IllegalStateException("Unexpected state - no hide stop and hide start found.");
            }
            if (beginIndex >= endIndex) {
                throw new IllegalStateException("Unexpected state - hide start after hide stop.");
            }
            // do replace, line by line
            {
                Document document = new Document(source);
                int beginLine = document.getLineOfOffset(beginIndex);
                int endLine = document.getLineOfOffset(endIndex);
                for (int line = beginLine; line <= endLine; line++) {
                    IRegion info = document.getLineInformation(line);
                    int beginOffset = line == beginLine ? beginIndex : info.getOffset();
                    //int endOffset = line == endLine ? endIndex : info.getOffset() + info.getLength();
                    int endOffset = info.getOffset() + info.getLength();
                    // replace inside of single line
                    int length = endOffset - beginOffset;
                    document.replace(beginOffset, length, StringUtils.repeat(" ", length));
                }
                // get updated source
                source = document.get();
            }
        }
    }
    // remove single line hidden code
    {
        String lineTag = clearHiddenCode_getTag(IPreferenceConstants.P_CODE_HIDE_LINE);
        while (true) {
            // find hide comment
            int hideIndex = source.indexOf(lineTag);
            if (hideIndex == -1) {
                break;
            }
            // replace with whitespace using Document
            Document document = new Document(source);
            IRegion lineInformation = document.getLineInformationOfOffset(hideIndex);
            document.replace(lineInformation.getOffset(), lineInformation.getLength(),
                    StringUtils.repeat(" ", lineInformation.getLength()));
            // get updated source
            source = document.get();
        }
    }
    return source;
}

From source file:org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils.java

/**
 * Resolves the given type name within the context of given {@link IType} (depending on the type
 * hierarchy and its imports).//from ww  w. j  a va  2 s  . co m
 */
public static String getResolvedTypeName(IType context, String typeSignature) throws JavaModelException {
    // remove generic
    if (typeSignature.indexOf(Signature.C_GENERIC_START) != -1) {
        typeSignature = Signature.getTypeErasure(typeSignature);
    }
    //
    int arrayCount = Signature.getArrayCount(typeSignature);
    char type = typeSignature.charAt(arrayCount);
    if (type == Signature.C_UNRESOLVED || type == Signature.C_TYPE_VARIABLE) {
        int semi = typeSignature.indexOf(Signature.C_SEMICOLON, arrayCount + 1);
        String name = typeSignature.substring(arrayCount + 1, semi);
        name = getResolvedTypeName_resolveTypeVariable(context, name);
        // resolve type
        String[][] resolvedNames = context.resolveType(name);
        if (resolvedNames != null && resolvedNames.length > 0) {
            return concatenateName(resolvedNames[0][0], resolvedNames[0][1])
                    + StringUtils.repeat("[]", arrayCount);
        }
        // can not resolve
        return null;
    }
    // resolved
    {
        String name = Signature.toString(typeSignature);
        name = getResolvedTypeName_resolveTypeVariable(context, name);
        // done
        return name;
    }
}

From source file:org.eclipse.wb.internal.core.utils.XmlWriter.java

/**
 * Open tag with given <code>tagName</code> for further adding tag attribute. Ex. calling
 * beginTag("tag1") will results writing "&lt;tag1" into underlying {@link PrintWriter}. After
 * calling this method only adding attributes and ending tag operations are possible.
 * /*from w w  w  .jav  a 2  s .  co  m*/
 * @param tagName
 *          the tag name with which tag would be made.
 */
public void beginTag(String tagName) {
    checkOpen();
    Assert.isLegal(!StringUtils.isEmpty(tagName), "Can't add tag with empty name.");
    if (!m_tagStack.empty()) {
        TagInfo currentTag = m_tagStack.peek();
        if (isState(currentTag, TAG_STATE_BEGIN_NOT_ENDED)) {
            throw new IllegalStateException("Another tag already began for attribute adding.");
        }
        addState(currentTag, TAG_STATE_HAS_CHILDRED);
    }
    m_tagStack.push(new TagInfo(tagName, TAG_STATE_BEGIN_NOT_ENDED));
    if (!m_isShortTagClosed) {
        // don't put line separator between "short" tags (<tag attr="attr"/>)
        m_printWriter.println();
    }
    m_isShortTagClosed = false;
    m_printWriter.print(StringUtils.repeat(getIndent(), m_tagStack.size() - 1));
    m_printWriter.print("<" + tagName);
}