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

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

Introduction

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

Prototype

public static String leftPad(final String str, final int size, String padStr) 

Source Link

Document

Left pad a String with a specified String.

Pad to a size of size .

 StringUtils.leftPad(null, *, *)      = null StringUtils.leftPad("", 3, "z")      = "zzz" StringUtils.leftPad("bat", 3, "yz")  = "bat" StringUtils.leftPad("bat", 5, "yz")  = "yzbat" StringUtils.leftPad("bat", 8, "yz")  = "yzyzybat" StringUtils.leftPad("bat", 1, "yz")  = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null)  = "  bat" StringUtils.leftPad("bat", 5, "")    = "  bat" 

Usage

From source file:org.evosuite.junit.naming.methods.NumberedTestNameGenerationStrategy.java

private void generateNames(List<TestCase> testCases) {
    int totalNumberOfTests = testCases.size();
    String totalNumberOfTestsString = String.valueOf(totalNumberOfTests - 1);

    int num = 0;/*  www .j  a v a2s . com*/
    for (TestCase test : testCases) {
        String testNumber = StringUtils.leftPad(String.valueOf(num), totalNumberOfTestsString.length(), "0");
        String testName = "test" + testNumber;
        testToName.put(test, testName);
        num++;
    }
}

From source file:org.evosuite.junit.TestSuiteWriter.java

public static String getNameOfTest(List<TestCase> tests, int position) {

    if (Properties.ASSERTION_STRATEGY == AssertionStrategy.STRUCTURED) {
        throw new IllegalStateException("For the moment, structured tests are not supported");
    }//  w w  w.  ja  v a2s  .  co  m

    int totalNumberOfTests = tests.size();
    String totalNumberOfTestsString = String.valueOf(totalNumberOfTests - 1);
    String testNumber = StringUtils.leftPad(String.valueOf(position), totalNumberOfTestsString.length(), "0");
    String testName = "test" + testNumber;
    return testName;
}

From source file:org.evosuite.junit.writer.TestSuiteWriterUtils.java

public static String getNameOfTest(List<TestCase> tests, int position) {

    TestCase test = tests.get(position);
    String testName = null;/*w  w  w . jav  a2  s . com*/
    if (test instanceof CarvedTestCase) {
        testName = ((CarvedTestCase) test).getName();
    } else {
        int totalNumberOfTests = tests.size();
        String totalNumberOfTestsString = String.valueOf(totalNumberOfTests - 1);
        String testNumber = StringUtils.leftPad(String.valueOf(position), totalNumberOfTestsString.length(),
                "0");
        testName = "test" + testNumber;
    }
    return testName;
}

From source file:org.finra.dm.tools.uploader.UploaderManifestReaderTest.java

@Test
public void testReadJsonManifestMaxAttributeNameLength() throws IOException {
    UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto();
    HashMap<String, String> attributes = new HashMap<>();
    uploaderInputManifestDto.setAttributes(attributes);
    String attributeKey = StringUtils.leftPad("key", UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH, '*'); // Returns "*...*key"
    assertTrue(attributeKey.length() == UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH);
    attributes.put(attributeKey, ATTRIBUTE_VALUE_1);
    UploaderInputManifestDto resultManifest = uploaderManifestReader
            .readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));

    // Validate the results.
    assertUploaderManifest(uploaderInputManifestDto, resultManifest);
}

From source file:org.finra.dm.tools.uploader.UploaderManifestReaderTest.java

@Test
public void testReadJsonManifestAttributeNameTooLong() throws IOException {
    // Try to create and read the uploader input manifest that contains an attribute name which is too long.
    UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto();
    HashMap<String, String> attributes = new HashMap<>();
    uploaderInputManifestDto.setAttributes(attributes);
    String attributeKey = StringUtils.leftPad("value", UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH + 1,
            '*'); // Returns "*...*key"
    assertTrue(attributeKey.length() == UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH + 1);
    attributes.put(attributeKey, ATTRIBUTE_VALUE_1);
    try {/*from   www  .ja  va  2s  .c  o  m*/
        uploaderManifestReader.readJsonManifest(
                createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when an attribute name is too long.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Manifest attribute name is longer than %d characters.",
                UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH), e.getMessage());
    }
}

From source file:org.finra.dm.tools.uploader.UploaderManifestReaderTest.java

@Test
public void testReadJsonManifestMaxAttributeValueLength() throws IOException {
    UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto();
    HashMap<String, String> attributes = new HashMap<>();
    uploaderInputManifestDto.setAttributes(attributes);
    String attributeKey = ATTRIBUTE_NAME_1_MIXED_CASE;
    String attributeValue = StringUtils.leftPad("value", UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH,
            '*'); // Returns "*...*value"
    assertTrue(attributeValue.length() == UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH);
    attributes.put(attributeKey, attributeValue);
    UploaderInputManifestDto resultManifest = uploaderManifestReader
            .readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));

    // Validate the results.
    assertUploaderManifest(uploaderInputManifestDto, resultManifest);
}

From source file:org.finra.dm.tools.uploader.UploaderManifestReaderTest.java

@Test
public void testReadJsonManifestAttributeValueTooLong() throws IOException {
    // Try to create and read the uploader input manifest that contains an attribute value which is too long.
    UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto();
    HashMap<String, String> attributes = new HashMap<>();
    uploaderInputManifestDto.setAttributes(attributes);
    String attributeValue = StringUtils.leftPad("value", UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH + 1,
            '*'); // Returns "*...*value"
    assertTrue(attributeValue.length() == UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH + 1);
    attributes.put(ATTRIBUTE_NAME_1_MIXED_CASE, attributeValue);
    try {//from  w  ww  . j  a v a2  s . c  o  m
        uploaderManifestReader.readJsonManifest(
                createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when an attribute value is too long.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Manifest attribute value is longer than %s characters.",
                UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH), e.getMessage());
    }
}

From source file:org.finra.herd.dao.StorageFileDaoTestHelper.java

/**
 * Creates and persists storage file entities per specified parameters.
 *
 * @param storageUnitEntity the storage unit entity
 * @param s3KeyPrefix the S3 key prefix//from   w  ww .j av  a 2s.  c o m
 * @param partitionColumns the list of partition columns
 * @param subPartitionValues the list of sub-partition values
 * @param replaceUnderscoresWithHyphens specifies to replace UnderscoresWithHyphens when buidling a path
 */
public void createStorageFileEntities(StorageUnitEntity storageUnitEntity, String s3KeyPrefix,
        List<SchemaColumn> partitionColumns, List<String> subPartitionValues,
        boolean replaceUnderscoresWithHyphens) {
    int discoverableSubPartitionsCount = partitionColumns != null
            ? partitionColumns.size() - subPartitionValues.size() - 1
            : 0;
    int storageFilesCount = (int) Math.pow(2, discoverableSubPartitionsCount);

    for (int i = 0; i < storageFilesCount; i++) {
        // Build a relative sub-directory path.
        StringBuilder subDirectory = new StringBuilder();
        String binaryString = StringUtils.leftPad(Integer.toBinaryString(i), discoverableSubPartitionsCount,
                "0");
        for (int j = 0; j < discoverableSubPartitionsCount; j++) {
            String subpartitionKey = partitionColumns.get(j + subPartitionValues.size() + 1).getName()
                    .toLowerCase();
            if (replaceUnderscoresWithHyphens) {
                subpartitionKey = subpartitionKey.replace("_", "-");
            }
            subDirectory.append(String.format("/%s=%s", subpartitionKey, binaryString.substring(j, j + 1)));
        }
        // Create a storage file entity.
        createStorageFileEntity(storageUnitEntity,
                String.format("%s%s/data.dat", s3KeyPrefix, subDirectory.toString()),
                AbstractDaoTest.FILE_SIZE_1_KB, AbstractDaoTest.ROW_COUNT_1000);
    }
}

From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.planning.queryplan.QueryPlan.java

/**
 * Recursively prints the sub tree of the given node in pre-order.
 *
 * @param node root plan node//  w  w w.  ja  v  a2 s.  c om
 * @param level level of the whole query tree
 * @param sb string builder to append
 */
private void printPlanNode(PlanNode node, int level, StringBuilder sb) {
    sb.append(String.format("%s|-%s%n", StringUtils.leftPad("", level * 2, PAD_STRING), node));
    level++;
    if (node instanceof UnaryNode) {
        printPlanNode(((UnaryNode) node).getChildNode(), level, sb);
    } else if (node instanceof BinaryNode) {
        printPlanNode(((BinaryNode) node).getLeftChild(), level, sb);
        printPlanNode(((BinaryNode) node).getRightChild(), level, sb);
    }
}

From source file:org.javabeanstack.util.Strings.java

public static String leftPad(String str, int size, String padStr) {
    return StringUtils.leftPad(str, size, padStr);
}