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

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

Introduction

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

Prototype

public static String lowerCase(final String str) 

Source Link

Document

Converts a String to lower case as per String#toLowerCase() .

A null input String returns null .

 StringUtils.lowerCase(null)  = null StringUtils.lowerCase("")    = "" StringUtils.lowerCase("aBc") = "abc" 

Note: As described in the documentation for String#toLowerCase() , the result of this method is affected by the current locale.

Usage

From source file:fr.landel.utils.assertor.predicate.PredicateAssertorArrayTest.java

/**
 * Check {@link AssertorArray#anyMatch}//from ww  w.j  a  v a2s .com
 */
@Test
public void testAnyMatch() {
    String[] arraytu = { "t", "u" };
    String[] arrayTu = { "T", "u" };
    String[] arrayTU = { "T", "U" };
    String[] arraytNull = { "t", null };

    Predicate<String> predicate = e -> Objects.equals(e, StringUtils.lowerCase(e));

    assertTrue(Assertor.<String>ofArray().anyMatch(predicate).that(arraytu).isOK());

    for (EnumAnalysisMode mode : EnumAnalysisMode.values()) {

        PredicateAssertorStepArray<String> predicateAssertor = Assertor.<String>ofArray(mode);
        PredicateStepArray<String> predicateStep = predicateAssertor.anyMatch(predicate);

        assertTrue(predicateStep.that(arraytu).isOK());
        assertTrue(predicateStep.that(arrayTu).isOK());
        assertFalse(predicateStep.that(arrayTU).isOK());
        assertTrue(predicateStep.that(arraytNull).isOK());

        assertTrue(predicateAssertor.not().anyMatch(predicate).that(arrayTU).isOK());
        assertFalse(predicateAssertor.not().anyMatch(predicate).that(arrayTu).isOK());

        assertException(() -> predicateStep.that(new String[0]).orElseThrow(), IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> predicateStep.that((String[]) null).orElseThrow(), IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> predicateAssertor.anyMatch(null).that(arrayTu).orElseThrow(),
                IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> predicateStep.that(arrayTU).orElseThrow(), IllegalArgumentException.class,
                "any array element '[T, U]' should match the predicate");
    }
}

From source file:fr.landel.utils.assertor.AssertorArrayTest.java

/**
 * Check {@link AssertorArray#anyMatch}/*from   w w  w.  j  a v a 2s .c om*/
 */
@Test
public void testAnyMatch() {
    String[] arraytu = { "t", "u" };
    String[] arrayTu = { "T", "u" };
    String[] arrayTU = { "T", "U" };
    String[] arraytNull = { "t", null };

    Predicate<String> predicate = e -> Objects.equals(e, StringUtils.lowerCase(e));

    assertTrue(Assertor.that(arraytu).allMatch(predicate).isOK());

    for (EnumAnalysisMode mode : EnumAnalysisMode.values()) {

        assertTrue(Assertor.that(arraytu, mode).allMatch(predicate).isOK());
        assertTrue(Assertor.that(arrayTu, mode).anyMatch(predicate).isOK());
        assertFalse(Assertor.that(arrayTU, mode).anyMatch(predicate).isOK());
        assertTrue(Assertor.that(arraytNull, mode).anyMatch(predicate).isOK());

        assertException(() -> Assertor.that(new String[0], mode).anyMatch(predicate).orElseThrow(),
                IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> Assertor.that((String[]) null, mode).anyMatch(predicate).orElseThrow(),
                IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> Assertor.that(arrayTu, mode).anyMatch(null).orElseThrow(),
                IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> Assertor.that(arrayTU, mode).anyMatch(predicate).orElseThrow(),
                IllegalArgumentException.class, "any array element '[T, U]' should match the predicate");
    }
}

From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineFactory.java

/**
 * Initializes a {@link StreamingMessageQueue} instance according to provided information.
 * @param queueConfiguration+//from   w  w w  .  j ava 2  s.  c  o m
 * @return
 * @throws RequiredInputMissingException
 * @throws QueueInitializationFailedException
 */
protected StreamingMessageQueue initializeQueue(final StreamingMessageQueueConfiguration queueConfiguration)
        throws RequiredInputMissingException, QueueInitializationFailedException {

    ///////////////////////////////////////////////////////////////////////////////////
    // validate input
    if (queueConfiguration == null)
        throw new RequiredInputMissingException("Missing required queue configuration");
    if (StringUtils.isBlank(queueConfiguration.getId()))
        throw new RequiredInputMissingException("Missing required queue identifier");
    //
    ///////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////////
    // check properties for optional settings
    boolean inMemoryQueue = false;
    if (queueConfiguration.getProperties() != null && !queueConfiguration.getProperties().isEmpty()) {
        String queueType = StringUtils.lowerCase(StringUtils
                .trim(queueConfiguration.getProperties().getProperty(StreamingMessageQueue.CFG_QUEUE_TYPE)));
        inMemoryQueue = StringUtils.equalsIgnoreCase(queueType, InMemoryStreamingMessageQueue.CFG_QUEUE_TYPE);
    }
    ///////////////////////////////////////////////////////////////////////////////////

    if (inMemoryQueue) {
        try {
            StreamingMessageQueue queue = new InMemoryStreamingMessageQueue();
            queue.setId(StringUtils.lowerCase(StringUtils.trim(queueConfiguration.getId())));
            queue.initialize((queueConfiguration.getProperties() != null ? queueConfiguration.getProperties()
                    : new Properties()));
            return queue;
        } catch (Exception e) {
            throw new QueueInitializationFailedException("Failed to initialize streaming message queue '"
                    + queueConfiguration.getId() + "'. Error: " + e.getMessage());
        }
    }

    try {
        StreamingMessageQueue queue = new DefaultStreamingMessageQueue();
        queue.setId(StringUtils.lowerCase(StringUtils.trim(queueConfiguration.getId())));
        queue.initialize((queueConfiguration.getProperties() != null ? queueConfiguration.getProperties()
                : new Properties()));
        return queue;
    } catch (Exception e) {
        throw new QueueInitializationFailedException("Failed to initialize streaming message queue '"
                + queueConfiguration.getId() + "'. Error: " + e.getMessage());
    }
}

From source file:io.swagger.codegen.languages.Swift3Codegen.java

@Override
public String toEnumVarName(String name, String datatype) {
    if (name.length() == 0) {
        return "empty";
    }//from   w w  w . ja v  a  2 s . co m

    // for symbol, e.g. $, #
    if (getSymbolName(name) != null) {
        return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase()), true);
    }

    // Camelize only when we have a structure defined below
    Boolean camelized = false;
    if (name.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
        name = camelize(name, true);
        camelized = true;
    }

    // Reserved Name
    String nameLowercase = StringUtils.lowerCase(name);
    if (isReservedWord(nameLowercase)) {
        return escapeReservedWord(nameLowercase);
    }

    // Check for numerical conversions
    if ("Int".equals(datatype) || "Int32".equals(datatype) || "Int64".equals(datatype)
            || "Float".equals(datatype) || "Double".equals(datatype)) {
        String varName = "number" + camelize(name);
        varName = varName.replaceAll("-", "minus");
        varName = varName.replaceAll("\\+", "plus");
        varName = varName.replaceAll("\\.", "dot");
        return varName;
    }

    // If we have already camelized the word, don't progress
    // any further
    if (camelized) {
        return name;
    }

    char[] separators = { '-', '_', ' ', ':', '(', ')' };
    return camelize(
            WordUtils.capitalizeFully(StringUtils.lowerCase(name), separators).replaceAll("[-_ :\\(\\)]", ""),
            true);
}

From source file:fr.landel.utils.assertor.AssertorArrayTest.java

/**
 * Check {@link AssertorArray#allMatch}//from   w  ww.  ja  va  2  s.  co m
 */
@Test
public void testAllMatch() {
    String[] arraytu = { "t", "u" };
    String[] arrayTu = { "T", "u" };
    String[] arrayTU = { "T", "U" };
    String[] arraytNull = { "t", null };

    Predicate<String> predicate = e -> Objects.equals(e, StringUtils.lowerCase(e));

    assertTrue(Assertor.that(arraytu).allMatch(predicate).isOK());

    for (EnumAnalysisMode mode : EnumAnalysisMode.values()) {

        assertTrue(Assertor.that(arraytu, mode).allMatch(predicate).isOK());
        assertFalse(Assertor.that(arrayTu, mode).allMatch(predicate).isOK());
        assertTrue(Assertor.that(arrayTu, mode).not().allMatch(predicate).isOK());
        assertFalse(Assertor.that(arrayTU, mode).allMatch(predicate).isOK());
        assertFalse(Assertor.that(arrayTU, mode).not().allMatch(predicate).isOK());
        assertTrue(Assertor.that(arraytNull, mode).allMatch(predicate).isOK());

        assertException(() -> Assertor.that(new String[0], mode).allMatch(predicate).orElseThrow(),
                IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> Assertor.that((String[]) null, mode).allMatch(predicate).orElseThrow(),
                IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> Assertor.that(arrayTu, mode).allMatch(null).orElseThrow(),
                IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> Assertor.that(arrayTU, mode).allMatch(predicate).orElseThrow(),
                IllegalArgumentException.class, "all the array elements '[T, U]' should match the predicate");
    }
}

From source file:fr.landel.utils.assertor.predicate.PredicateAssertorArrayTest.java

/**
 * Check {@link AssertorArray#allMatch}/*from  w w  w .  ja  v  a 2  s  .c om*/
 */
@Test
public void testAllMatch() {
    String[] arraytu = { "t", "u" };
    String[] arrayTu = { "T", "u" };
    String[] arrayTU = { "T", "U" };
    String[] arraytNull = { "t", null };

    Predicate<String> predicate = e -> Objects.equals(e, StringUtils.lowerCase(e));

    assertTrue(Assertor.<String>ofArray().allMatch(predicate).that(arraytu).isOK());

    for (EnumAnalysisMode mode : EnumAnalysisMode.values()) {

        PredicateAssertorStepArray<String> predicateAssertor = Assertor.<String>ofArray(mode);
        PredicateStepArray<String> predicateStep = predicateAssertor.allMatch(predicate);

        assertTrue(predicateStep.that(arraytu).isOK());
        assertFalse(predicateStep.that(arrayTu).isOK());
        assertFalse(predicateStep.that(arrayTU).isOK());
        assertTrue(predicateStep.that(arraytNull).isOK());

        assertException(() -> predicateStep.that(new String[0]).orElseThrow(), IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> predicateStep.that((String[]) null).orElseThrow(), IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> predicateAssertor.allMatch(null).that(arrayTu).orElseThrow(),
                IllegalArgumentException.class,
                "the array cannot be null or empty and predicate cannot be null");
        assertException(() -> predicateStep.that(arrayTU).orElseThrow(), IllegalArgumentException.class,
                "all the array elements '[T, U]' should match the predicate");
    }
}

From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineFactory.java

/**
 * Initializes a {@link MicroPipelineComponent} instance according to provided information
 * @param componentConfiguration/*from   w  w  w  . ja  va2 s .com*/
 * @return
 * @throws RequiredInputMissingException
 * @throws ComponentInitializationFailedException
 * TODO test for settings that must be provided for type SOURCE
 * TODO test for settings that must be provided for type EMITTER
 * TODO test for settings that must be provided for type OPERATOR
 * TODO test queue references in toQueues and fromQueues
 * TODO test component instantiation
 */
protected MicroPipelineComponent initializeComponent(
        final MicroPipelineComponentConfiguration componentConfiguration,
        final Map<String, StreamingMessageQueue> queues)
        throws RequiredInputMissingException, ComponentInitializationFailedException {

    ///////////////////////////////////////////////////////////////////////////////////
    // validate input
    if (componentConfiguration == null)
        throw new RequiredInputMissingException("Missing required component configuration");
    if (StringUtils.isBlank(componentConfiguration.getId()))
        throw new RequiredInputMissingException("Missing required component identifier");
    if (componentConfiguration.getType() == null)
        throw new RequiredInputMissingException("Missing required component type");
    if (StringUtils.isBlank(componentConfiguration.getName()))
        throw new RequiredInputMissingException("Missing required component name");
    if (StringUtils.isBlank(componentConfiguration.getVersion()))
        throw new RequiredInputMissingException("Missing required component version");
    if (componentConfiguration.getSettings() == null)
        throw new RequiredInputMissingException("Missing required component settings");
    //
    ////////////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////////
    // validate settings for components of type: SOURCE
    if (componentConfiguration.getType() == MicroPipelineComponentType.SOURCE) {

        if (StringUtils.isBlank(componentConfiguration.getToQueue()))
            throw new RequiredInputMissingException("Missing required queues to write content to");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getToQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown destination queue '" + componentConfiguration.getToQueue() + "'");

        ////////////////////////////////////////////////////////////////////////////////////
        // validate settings for components of type: DIRECT_RESPONSE_OPERATOR
    } else if (componentConfiguration.getType() == MicroPipelineComponentType.DIRECT_RESPONSE_OPERATOR) {

        if (StringUtils.isBlank(componentConfiguration.getToQueue()))
            throw new RequiredInputMissingException("Missing required queues to write content to");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getToQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown destination queue '" + componentConfiguration.getToQueue() + "'");

        if (StringUtils.isBlank(componentConfiguration.getFromQueue()))
            throw new RequiredInputMissingException("Missing required queues to retrieve content from");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getFromQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown source queue '" + componentConfiguration.getFromQueue() + "'");

        ////////////////////////////////////////////////////////////////////////////////////
        // validate settings for components of type: DELAYED_RESPONSE_OPERATOR
    } else if (componentConfiguration.getType() == MicroPipelineComponentType.DELAYED_RESPONSE_OPERATOR) {

        if (StringUtils.isBlank(componentConfiguration.getToQueue()))
            throw new RequiredInputMissingException("Missing required queues to write content to");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getToQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown destination queue '" + componentConfiguration.getToQueue() + "'");

        if (StringUtils.isBlank(componentConfiguration.getFromQueue()))
            throw new RequiredInputMissingException("Missing required queues to retrieve content from");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getFromQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown source queue '" + componentConfiguration.getFromQueue() + "'");

        if (StringUtils.isBlank(componentConfiguration.getSettings()
                .getProperty(DelayedResponseOperator.CFG_WAIT_STRATEGY_NAME)))
            throw new RequiredInputMissingException(
                    "Missing required settings for wait strategy applied to delayed response operator");

        ////////////////////////////////////////////////////////////////////////////////////
        // validate settings for components of type: EMITTER
    } else if (componentConfiguration.getType() == MicroPipelineComponentType.EMITTER) {

        if (StringUtils.isBlank(componentConfiguration.getFromQueue()))
            throw new RequiredInputMissingException("Missing required queues to retrieve content from");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getFromQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown source queue '" + componentConfiguration.getFromQueue() + "'");
    }
    //
    ////////////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////////
    // instantiate component class
    try {
        return this.componentRepository.newInstance(componentConfiguration.getId(),
                componentConfiguration.getName(), componentConfiguration.getVersion(),
                componentConfiguration.getSettings());
    } catch (Exception e) {
        throw new ComponentInitializationFailedException("Failed to initialize component '"
                + componentConfiguration.getId() + "'. Error: " + e.getMessage(), e);
    }
    //
    ////////////////////////////////////////////////////////////////////////////////////

}

From source file:com.sap.research.connectivity.gw.GWOperationsUtils.java

public String getControllerShowMethodBody(String remoteEntity) {

    String smallRemoteEntity = StringUtils.lowerCase(remoteEntity);
    String pluralRemoteEntity = GwUtils.getInflectorPlural(remoteEntity, Locale.ENGLISH);

    String returnString = "";

    if (existsDateFieldInController(remoteEntity)) {
        returnString += "\t\taddDateTimeFormatPatterns(uiModel);\n";
    }/*from w  ww.  j a  v a2  s  . c om*/
    returnString += "\t\tuiModel.addAttribute(\"" + smallRemoteEntity + "\", " + remoteEntity + ".find"
            + remoteEntity + "(Id));\n";
    returnString += generateURLEncodingCode("Id", "\t\t");
    returnString += "\t\tuiModel.addAttribute(\"itemId\", " + ENCODED_KEY + ");\n";
    returnString += "\t\treturn \"" + StringUtils.lowerCase(pluralRemoteEntity) + "/show\";\n";

    return returnString;
}

From source file:fr.landel.utils.assertor.AssertorIterableTest.java

/**
 * Check {@link AssertorIterable#anyMatch}
 *///from   w  ww  .  j a  v  a 2 s .  c  o m
@Test
public void testAnyMatch() {
    List<String> listtu = Arrays.asList("t", "u");
    List<String> listTu = Arrays.asList("T", "u");
    List<String> listTU = Arrays.asList("T", "U");
    List<String> listtNull = Arrays.asList("t", null);

    Predicate<String> predicate = e -> Objects.equals(e, StringUtils.lowerCase(e));

    assertTrue(Assertor.that(listtu).anyMatch(predicate).isOK());

    for (EnumAnalysisMode mode : EnumAnalysisMode.values()) {

        assertTrue(Assertor.that(listtu, mode).anyMatch(predicate).isOK());
        assertTrue(Assertor.that(listTu, mode).anyMatch(predicate).isOK());
        assertFalse(Assertor.that(listTU, mode).anyMatch(predicate).isOK());
        assertTrue(Assertor.that(listtNull, mode).anyMatch(predicate).isOK());

        assertException(
                () -> Assertor.that(Collections.<String>emptyList(), mode).anyMatch(predicate).orElseThrow(),
                IllegalArgumentException.class,
                "the iterable cannot be null or empty and predicate cannot be null");
        assertException(() -> Assertor.that((List<String>) null, mode).anyMatch(predicate).orElseThrow(),
                IllegalArgumentException.class,
                "the iterable cannot be null or empty and predicate cannot be null");
        assertException(() -> Assertor.that(listTu, mode).anyMatch(null).orElseThrow(),
                IllegalArgumentException.class,
                "the iterable cannot be null or empty and predicate cannot be null");
        assertException(() -> Assertor.that(listTU, mode).anyMatch(predicate).orElseThrow(),
                IllegalArgumentException.class, "any iterable element '[T, U]' should match the predicate");
    }
}

From source file:cgeo.geocaching.connector.oc.OkapiClient.java

private static String getPreferredLanguage() {
    final String code = Locale.getDefault().getCountry();
    if (StringUtils.isNotBlank(code)) {
        return StringUtils.lowerCase(code) + "|en";
    }//from ww  w. jav  a2s  .  co m
    return "en";
}