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:org.efaps.esjp.accounting.report.AccountingDataSource_Base.java

/**
 * @see net.sf.jasperreports.engine.JRDataSource#getFieldValue(net.sf.jasperreports.engine.JRField)
 * @param _field JRField/* w w w.ja v a2  s .c o  m*/
 * @return value for the given field
 * @throws JRException on error
 */
@Override
public Object getFieldValue(final JRField _field) throws JRException {
    final int rootIndex = Integer.parseInt(_field.getName().split("_")[_field.getName().split("_").length - 1]);

    Object ret = null;
    final List<AbstractNode> nodes = this.values.get(rootIndex);
    if (this.current < nodes.size()) {
        final AbstractNode node = nodes.get(this.current);
        if (_field.getValueClass().equals(BigDecimal.class)) {
            if (!node.isTextOnly()) {
                ret = node.getSum();
            }
        } else if (_field.getValueClass().equals(Object.class)) {
            ret = node;
        } else {
            ret = StringUtils.repeat(" ", node.getLevel() * 2) + node.getLabel();
        }
    }
    return ret;
}

From source file:org.fcrepo.camel.FcrepoProducerTest.java

@Test
public void testStreamCaching() throws Exception {
    final URI uri = create(TestUtils.baseUrl);
    final int status = 200;
    final String rdfConcat = StringUtils.repeat(TestUtils.rdfXml, 10000);
    final ByteArrayInputStream body = new ByteArrayInputStream(rdfConcat.getBytes());
    final FcrepoResponse headResponse = new FcrepoResponse(uri, 200, emptyMap(), null);
    final FcrepoResponse getResponse = new FcrepoResponse(uri, status,
            singletonMap(CONTENT_TYPE, singletonList(TestUtils.RDF_XML)), body);

    init();/*w  ww . j a  v  a  2  s  .c o  m*/

    testExchange.getIn().setHeader(FCREPO_IDENTIFIER, "/foo");
    testExchange.setProperty(DISABLE_HTTP_STREAM_CACHE, false);

    testExchange.getContext().getStreamCachingStrategy().setSpoolThreshold(1024);
    testExchange.getContext().getStreamCachingStrategy().setBufferSize(256);
    testExchange.getContext().setStreamCaching(true);

    when(mockHeadBuilder.perform()).thenReturn(headResponse);
    when(mockGetBuilder.perform()).thenReturn(getResponse);

    testProducer.process(testExchange);

    assertEquals(true, testExchange.getContext().isStreamCaching());
    assertNotNull(testExchange.getIn().getBody(InputStreamCache.class));
    assertEquals(rdfConcat.length(), testExchange.getIn().getBody(InputStreamCache.class).length());
    assertEquals(rdfConcat.length(), testExchange.getIn().getBody(InputStreamCache.class).length());
    assertEquals(testExchange.getIn().getHeader(CONTENT_TYPE, String.class), TestUtils.RDF_XML);
    assertEquals(testExchange.getIn().getHeader(HTTP_RESPONSE_CODE), status);
}

From source file:org.finra.herd.service.activiti.HerdProcessEngineConfiguratorTest.java

/**
 * Activiti by default configures StringType and LongStringType VariableType in configuration.
 * This method tests the scenarios where no StringType and LongStringType is already configured in configuration.
 *//*from w  w  w .j  a  v a  2s.  co m*/
@Test
public void testNoStringAndLongStringType() throws Exception {
    SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();
    configuration.setVariableTypes(new DefaultVariableTypes());

    herdProcessEngineConfigurator.configure(configuration);
    VariableType type = configuration.getVariableTypes().findVariableType(StringUtils.repeat("a", 2000));
    assertEquals(StringType.class, type.getClass());

    type = configuration.getVariableTypes().findVariableType(StringUtils.repeat("a", 2001));
    assertEquals(LongStringType.class, type.getClass());
}

From source file:org.finra.herd.service.BusinessObjectFormatServiceTest.java

@Test
public void testCreateBusinessObjectFormatAllBlankSpaceDocumentSchemaAndDocumentSchemaUrl() {
    businessObjectFormatServiceTestHelper.createTestDatabaseEntitiesForBusinessObjectFormatTesting();

    // Create a first version of the format with blank space document schema.
    BusinessObjectFormatCreateRequest request = businessObjectFormatServiceTestHelper
            .createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE,
                    FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION, StringUtils.repeat(" ", 10),
                    StringUtils.repeat(" ", 10),
                    Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)),
                    businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(),
                    businessObjectFormatServiceTestHelper.getTestSchema());
    request.getSchema().setPartitionKeyGroup(PARTITION_KEY_GROUP);

    // Create an initial business object format version.
    BusinessObjectFormat businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(request);

    // Validate the returned object.
    businessObjectFormatServiceTestHelper.validateBusinessObjectFormat(null, NAMESPACE, BDEF_NAME,
            FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, LATEST_VERSION_FLAG_SET,
            PARTITION_KEY, FORMAT_DESCRIPTION, "", "",
            Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)),
            businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(),
            businessObjectFormatServiceTestHelper.getTestSchema(), businessObjectFormat);
}

From source file:org.gm4java.engine.support.AbstractGMConnectionTest.java

@Test
public void execute_canHandle_largeGMResult() throws Exception {
    String large = StringUtils.repeat('a', 10000);
    when(reader.readLine()).thenReturn(large, "OK");

    String result = sut().execute(gmCommand);

    assertThat(result, is(large));//from   w  w w.ja  v a2 s.c  om
}

From source file:org.gvnix.addon.geo.addon.GvNIXGeoConversionServiceMetadata.java

/**
 * Gets or creates a field based on parameters.<br>
 * First try to get a suitable field (by name and type). If not found create
 * a new one (adding a counter to name if it's needed)
 * /*from ww w  .  j av  a 2s  .  co  m*/
 * @param fielName
 * @param fieldType
 * @param initializer (String representation)
 * @param modifier See {@link Modifier}
 * @param annotations optional (can be null)
 * @return
 */
private FieldMetadata getOrCreateField(JavaSymbolName fielName, JavaType fieldType, String initializer,
        int modifier, List<AnnotationMetadataBuilder> annotations) {
    JavaSymbolName curName = fielName;

    // Check if field exist
    FieldMetadata currentField = governorTypeDetails.getDeclaredField(curName);
    if (currentField != null) {
        if (!currentField.getFieldType().equals(fieldType)) {
            // No compatible field: look for new name
            currentField = null;
            JavaSymbolName newName = curName;
            int i = 1;
            while (governorTypeDetails.getDeclaredField(newName) != null) {
                newName = new JavaSymbolName(curName.getSymbolName().concat(StringUtils.repeat('_', i)));
                i++;
            }
            curName = newName;
        }
    }
    if (currentField == null) {
        // create field
        if (annotations == null) {
            annotations = new ArrayList<AnnotationMetadataBuilder>(0);
        }
        // Using the FieldMetadataBuilder to create the field
        // definition.
        final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), modifier, annotations,
                curName, // Field
                fieldType); // Field type
        fieldBuilder.setFieldInitializer(initializer);
        currentField = fieldBuilder.build(); // Build and return a
        // FieldMetadata
        // instance
    }
    return currentField;

}

From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderLoginMetadata.java

/**
 * Gets or creates a field based on parameters.<br>
 * First try to get a suitable field (by name and type). If not found create
 * a new one (adding a counter to name if it's needed)
 * //from  w  w  w . j a  v a 2s  .co m
 * @param fielName
 * @param fieldType
 * @param initializer (String representation)
 * @param modifier See {@link Modifier}
 * @param annotations optional (can be null)
 * @return
 */
private FieldMetadata getOrCreateField(JavaSymbolName fielName, JavaType fieldType, int modifier,
        List<AnnotationMetadataBuilder> annotations) {
    JavaSymbolName curName = fielName;

    // Check if field exist
    FieldMetadata currentField = governorTypeDetails.getDeclaredField(curName);
    if (currentField != null) {
        if (!currentField.getFieldType().equals(fieldType)) {
            // No compatible field: look for new name
            currentField = null;
            JavaSymbolName newName = curName;
            int i = 1;
            while (governorTypeDetails.getDeclaredField(newName) != null) {
                newName = new JavaSymbolName(curName.getSymbolName().concat(StringUtils.repeat('_', i)));
                i++;
            }
            curName = newName;
        }
    }
    if (currentField == null) {
        // create field
        if (annotations == null) {
            annotations = new ArrayList<AnnotationMetadataBuilder>(0);
        }
        // Using the FieldMetadataBuilder to create the field
        // definition.
        final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), modifier, annotations,
                curName, // Field
                fieldType); // Field type
        currentField = fieldBuilder.build(); // Build and return a
        // FieldMetadata
        // instance
    }
    return currentField;

}

From source file:org.gvnix.addon.web.mvc.addon.batch.WebJpaBatchMetadata.java

/**
 * Create metadata for auto-wired jpa batch service field.
 * //  w  ww.  ja  v a  2  s.  c  o m
 * @return a FieldMetadata object
 */
public FieldMetadata getServiceField() {
    if (serviceFiled == null) {
        JavaSymbolName curName = BATCH_SERVICE_NAME;
        // Check if field exist
        FieldMetadata currentField = governorTypeDetails.getDeclaredField(curName);
        if (currentField != null) {
            if (currentField.getAnnotation(SpringJavaType.AUTOWIRED) == null
                    || !currentField.getFieldType().equals(service)) {
                // No compatible field: look for new name
                currentField = null;
                JavaSymbolName newName = curName;
                int i = 1;
                while (governorTypeDetails.getDeclaredField(newName) != null) {
                    newName = new JavaSymbolName(curName.getSymbolName().concat(StringUtils.repeat('_', i)));
                    i++;
                }
                curName = newName;
            }
        }
        if (currentField != null) {
            serviceFiled = currentField;
        } else {
            // create field
            List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(1);
            annotations.add(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
            // Using the FieldMetadataBuilder to create the field
            // definition.
            final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), Modifier.PUBLIC,
                    annotations, curName, // Field
                    service); // Field type
            serviceFiled = fieldBuilder.build(); // Build and return a
            // FieldMetadata
            // instance
        }
    }
    return serviceFiled;
}

From source file:org.gvnix.addon.web.mvc.addon.batch.WebJpaBatchMetadata.java

/**
 * Create metadata for logger static field.
 * /*  w ww. ja  va  2 s.c o m*/
 * @return a FieldMetadata object
 */
public FieldMetadata getLoggerField() {
    if (loggerFiled == null) {
        JavaSymbolName curName = new JavaSymbolName("LOGGER_BATCH");
        // Check if field exist
        FieldMetadata currentField = governorTypeDetails.getDeclaredField(curName);
        if (currentField != null) {
            if (!currentField.getFieldType().equals(LOGGER_TYPE)) {
                // No compatible field: look for new name
                currentField = null;
                JavaSymbolName newName = curName;
                int i = 1;
                while (governorTypeDetails.getDeclaredField(newName) != null) {
                    newName = new JavaSymbolName(curName.getSymbolName().concat(StringUtils.repeat('_', i)));
                    i++;
                }
                curName = newName;
            }
        }
        if (currentField != null) {
            loggerFiled = currentField;
        } else {
            // Prepare initialized
            // LoggerFactory.getLogger(PetController.class);
            String initializer = String.format("%s.getLogger(%s.class);",
                    helper.getFinalTypeName(LOGGER_FACTORY_TYPE),
                    helper.getFinalTypeName(governorPhysicalTypeMetadata.getType()));

            // Using the FieldMetadataBuilder to create the field
            // definition.
            final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(),
                    Modifier.PUBLIC + Modifier.STATIC, curName, // Field
                    LOGGER_TYPE, initializer); // Field type
            loggerFiled = fieldBuilder.build(); // Build and return a
                                                // FieldMetadata
                                                // instance
        }
    }
    return loggerFiled;
}

From source file:org.iti.structureGraph.StructureGraph.java

private String getPathString(List<IStructureElement> pathElements, boolean includeLastElement) {
    StringBuilder identifier = new StringBuilder();
    int closingBracketCount = pathElements.size() - 1 - ((includeLastElement) ? 0 : 1);

    for (int x = 0; x < pathElements.size(); x++) {
        boolean isLastElement = x == pathElements.size() - 1;
        boolean isNextToLastElement = x == pathElements.size() - 2;

        if (!isLastElement || includeLastElement) {
            boolean successorExists = x + 1 < pathElements.size();
            IStructureElement element1 = pathElements.get(x);
            IStructureElement element2 = (successorExists) ? pathElements.get(x + 1) : null;
            DefaultEdge edge = (successorExists) ? getEdge(element1, element2) : null;

            identifier.append(element1.getIdentifier());

            if (successorExists) {
                identifier.append("." + edge.getClass().getSimpleName());

                if (!isNextToLastElement || includeLastElement) {
                    identifier.append("(");
                }//w w w  .j  a  v  a2 s. c o  m
            }
        }
    }

    identifier.append(StringUtils.repeat(")", closingBracketCount));

    return identifier.toString();
}