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

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

Introduction

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

Prototype

public static String capitalize(final String str) 

Source Link

Document

Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .

Usage

From source file:com.gammalabs.wifianalyzer.wifi.band.WiFiChannelCountryGHZ5.java

SortedSet<Integer> findChannels(@NonNull String countryCode) {
    SortedSet<Integer> results = new TreeSet<>(channels);
    SortedSet<Integer> exclude = channelsToExclude.get(StringUtils.capitalize(countryCode));
    if (exclude != null) {
        results.removeAll(exclude);//from   w  w w. j a va 2  s  .c  o  m
    }
    return Collections.unmodifiableSortedSet(results);
}

From source file:com.handany.base.generator.Generator.java

public static List<ColumnBean> getColumns(final TableBean tableBean) {
    return jdbcTemplate.query("select * from COLUMNS where table_schema = ? and table_name = ?",
            new Object[] { SCHEMA_NAME, tableBean.getTableName() }, new RowMapper<ColumnBean>() {

                @Override/*w w w.j ava 2  s.co  m*/
                public ColumnBean mapRow(ResultSet rs, int i) throws SQLException {
                    ColumnBean columnBean = new ColumnBean();
                    String columnName = rs.getString("column_name");
                    columnBean.setColumnName(columnName);
                    columnBean.setColumnNameNoDash(delDash(columnName));
                    columnBean
                            .setColumnNameCapitalized(StringUtils.capitalize(columnBean.getColumnNameNoDash()));
                    columnBean.setColumnComment(rs.getString("column_comment"));

                    String charLength = rs.getString("character_maximum_length");
                    if (StringUtils.isNoneBlank(charLength)) {
                        columnBean.setLength(Long.parseLong(charLength));
                    }

                    String columnType = rs.getString("column_type").toLowerCase();
                    if (columnType.startsWith("varchar") || columnType.startsWith("char")
                            || columnType.startsWith("clob") || ("text").equals(columnType)
                            || ("longtext").equals(columnType) || columnType.startsWith("enum")) {
                        columnBean.setColumnType("String");
                        columnBean.setColumnTypeRsGetter("getString");
                    } else if (columnType.startsWith("tinyint") || columnType.startsWith("smallint")
                            || columnType.startsWith("mediumint")) {
                        columnBean.setColumnType("Integer");
                        columnBean.setColumnTypeRsGetter("getInt");
                    } else if (columnType.startsWith("int") || columnType.startsWith("bigint")) {
                        columnBean.setColumnType("Long");
                        columnBean.setColumnTypeRsGetter("getLong");
                    } else if (("timestamp").equals(columnType) || ("datetime").equals(columnType)
                            || ("date").equals(columnType)) {
                        columnBean.setColumnType("Date");
                        columnBean.setColumnTypeRsGetter("getDate");
                        tableBean.setHasDateColumn(true);
                    } else if (columnType.startsWith("float")) {
                        columnBean.setColumnType("Float");
                        columnBean.setColumnTypeRsGetter("getFloat");
                    } else if (columnType.startsWith("double")) {
                        columnBean.setColumnType("Double");
                        columnBean.setColumnTypeRsGetter("getDouble");
                    } else if (columnType.startsWith("decimal")) {
                        columnBean.setColumnType("BigDecimal");
                        columnBean.setColumnTypeRsGetter("getBigDecimal");
                        tableBean.setHasBigDecimal(true);
                    } else {
                        throw new RuntimeException("Unsupported type: [" + columnType + "]!");
                    }

                    String dataType = rs.getString("data_type").toUpperCase();

                    if ("DATETIME".equals(dataType)) {
                        dataType = "TIMESTAMP";
                    } else if ("TEXT".equals(dataType)) {
                        dataType = "LONGVARCHAR";
                    }

                    columnBean.setColumnJdbcType(dataType);

                    return columnBean;
                }

            });
}

From source file:me.bramhaag.discordselfbot.commands.admin.CommandEvaluate.java

@Command(name = "evaluate", aliases = { "eval", "e" }, minArgs = 1)
public void execute(@NonNull Message message, @NonNull TextChannel channel, @NonNull String[] args) {

    String input = Util.combineArgs(Arrays.copyOfRange(args, 1, args.length));
    Evaluate.Language language = Evaluate.Language.getLanguage(args[0]);

    if (language == null) {
        language = Evaluate.Language.JAVASCRIPT;
        input = Util.combineArgs(args);
    }//  w  w  w  .  ja va  2s . c o  m

    input = input.startsWith("```") && input.endsWith("```") ? input.substring(3, input.length() - 3) : input;

    Evaluate.Result result = language.evaluate(Collections.unmodifiableMap(Stream
            .of(ent("jda", message.getJDA()), ent("channel", message.getChannel()),
                    ent("guild", message.getGuild()), ent("msg", message), ent("user", message.getAuthor()),
                    ent("member", message.getGuild().getMember(message.getAuthor())),
                    ent("bot", message.getJDA().getSelfUser()))
            .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue))),
            input);

    message.editMessage(new EmbedBuilder()
            .setTitle("Evaluate " + StringUtils.capitalize(language.name().toLowerCase()), null)
            .addField("Input",
                    new MessageBuilder().appendCodeBlock(input, language.name().toLowerCase()).build()
                            .getRawContent(),
                    true)
            .addField("Output",
                    new MessageBuilder().appendCodeBlock(result.getOutput(), "javascript").build()
                            .getRawContent(),
                    true)
            .setFooter(result.getStopwatch().elapsed(TimeUnit.NANOSECONDS) == 0
                    ? Constants.CROSS_EMOTE + " An error occurred"
                    : String.format(Constants.CHECK_EMOTE + " Took %d ms (%d ns) to complete | %s",
                            result.getStopwatch().elapsed(TimeUnit.MILLISECONDS),
                            result.getStopwatch().elapsed(TimeUnit.NANOSECONDS), Util.generateTimestamp()),
                    null)
            .setColor(color).build()).queue();
}

From source file:com.conversantmedia.mapreduce.mrunit.UnitTestDistributedResourceManager.java

protected Object getBeanValue(String property, Object bean) {
    Object value = null;/*from ww  w.  j ava 2 s .com*/
    String methodName = "get" + StringUtils.capitalize(property);
    try {
        Method method = bean.getClass().getDeclaredMethod(methodName);
        method.setAccessible(true);
        value = method.invoke(bean);
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException e) {
        logger().info("Unable to find method [" + methodName + "] for distributed resource.");
    }

    return value;
}

From source file:com.ijuru.ijambo.web.PlayServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from  w  ww  . j a v a  2 s . c om*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String message;
    String playerIdentifier = request.getParameter("id");
    String incoming = request.getParameter("incoming");

    if (StringUtils.isEmpty(playerIdentifier)) {
        message = "Player identifier must be provided";
    } else if (StringUtils.isEmpty(incoming)) {
        message = "Incoming message must be provided";
    } else {
        // Remove keyword from incoming message
        if (incoming.toLowerCase().startsWith("ijambo "))
            incoming = incoming.substring(7).trim();

        // Parse difficulty as a parameter
        Difficulty difficulty = null;
        try {
            difficulty = Difficulty.valueOf(incoming.toUpperCase());
        } catch (Exception ex) {
        }
        ;

        Player player = Context.getPlayerDAO().getPlayer(playerIdentifier);

        Word word = Context.getWordDAO().getRandomWord(difficulty);
        String scramble = Utils.scrambleWord(word.getWord().toUpperCase());
        String diffDisplay = StringUtils.capitalize(word.getDifficulty().name().toLowerCase());

        message = "[" + diffDisplay + "] unscramble " + scramble + " to find '" + word.getMeaning() + "'";

        if (player == null) {
            message += ". Play again to get answer";

            player = new Player(playerIdentifier, word.getWord());
        } else {
            message += ". Previous answer: " + player.getPrevAnswer().toUpperCase();

            player.setPrevAnswer(word.getWord());
        }

        Context.getPlayerDAO().save(player);
    }

    response.getWriter().write(message);
}

From source file:io.github.lxgaming.teleportbow.commands.HelpCommand.java

private Text buildDescription(AbstractCommand command) {
    Text.Builder textBuilder = Text.builder();
    textBuilder.append(Text.of(TextColors.AQUA, "Command: ", TextColors.DARK_GREEN,
            StringUtils.capitalize(command.getPrimaryAlias().orElse("unknown"))));
    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.of(TextColors.AQUA, "Description: ", TextColors.DARK_GREEN,
            StringUtils.defaultIfBlank(command.getDescription(), "No description provided")));
    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.of(TextColors.AQUA, "Usage: ", TextColors.DARK_GREEN, "/", Reference.PLUGIN_ID, " ",
            command.getPrimaryAlias().orElse("unknown")));
    if (StringUtils.isNotBlank(command.getUsage())) {
        textBuilder.append(Text.of(" ", TextColors.DARK_GREEN, command.getUsage()));
    }/*from w ww .  ja va 2s .  c om*/

    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.of(TextColors.AQUA, "Permission: ", TextColors.DARK_GREEN,
            StringUtils.defaultIfBlank(command.getPermission(), "None")));
    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.NEW_LINE);
    textBuilder.append(Text.of(TextColors.GRAY, "Click to auto-complete."));
    return textBuilder.build();
}

From source file:com.javaetmoi.core.batch.tasklet.CreateElasticIndexMappingTasklet.java

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    LOG.debug("Creating the {} mapping type for the index {}", mappingType, indexName);

    String source = IOUtils.toString(indexMapping.getInputStream(), "UTF-8");
    PutMappingRequestBuilder request = esClient.admin().indices().preparePutMapping(indexName);
    request.setSource(source).setType(mappingType);
    PutMappingResponse response = request.execute().actionGet();
    if (!response.isAcknowledged()) {
        throw new RuntimeException("The index mappings has not been acknowledged");
    }/*from w  w w.java2 s .c o  m*/

    ElasticSearchHelper.refreshIndex(esClient, indexName);

    LOG.info("{} mapping type created for the index {}", StringUtils.capitalize(mappingType), indexName);
    return RepeatStatus.FINISHED;

}

From source file:com.ppcxy.cyfm.showcase.demos.utilities.string.ApacheStringUtilsDemo.java

@Test
public void otherUtils() {
    // ignoreCase:contains/startWith/EndWith/indexOf/lastIndexOf
    assertThat(StringUtils.containsIgnoreCase("Aaabbb", "aaa")).isTrue();
    assertThat(StringUtils.indexOfIgnoreCase("Aaabbb", "aaa")).isEqualTo(0);

    // 0// w  w w .j av  a  2s  .  c o  m
    assertThat(StringUtils.leftPad("1", 3, '0')).isEqualTo("001");
    assertThat(StringUtils.leftPad("12", 3, '0')).isEqualTo("012");

    // ???
    assertThat(StringUtils.abbreviate("abcdefg", 7)).isEqualTo("abcdefg");
    assertThat(StringUtils.abbreviate("abcdefg", 6)).isEqualTo("abc...");

    // ?/?
    assertThat(StringUtils.capitalize("abc")).isEqualTo("Abc");
    assertThat(StringUtils.uncapitalize("Abc")).isEqualTo("abc");
}

From source file:ch.jamiete.hilda.commands.ChannelSeniorCommand.java

/**
 * Sends a message detailing the subcommands of this command.
 * @param channel/*from ww w  .j a va2 s  . c o  m*/
 */
public void help(final TextChannel channel, final Member member) {
    final MessageBuilder mb = new MessageBuilder();

    mb.append(StringUtils.capitalize(this.getName()) + " Help", Formatting.UNDERLINE);
    mb.append("\n");
    mb.append(this.getDescription(), Formatting.ITALICS);
    mb.append("\n\n");
    mb.append("Use ").append(CommandManager.PREFIX + this.getName() + " <command>", Formatting.BOLD);
    mb.append(" to use this command:");

    for (final ChannelCommand subcommand : this.subcommands) {
        if (subcommand.getHide() || subcommand.getMinimumPermission() != null
                && !member.hasPermission(channel, subcommand.getMinimumPermission())) {
            continue;
        }

        mb.append("\n  ");
        mb.append(subcommand.getName(), Formatting.BOLD);
        mb.append("  ");
        mb.append(subcommand.getDescription());
    }

    channel.sendMessage(mb.build()).queue();
}

From source file:jp.co.cyberagent.parquet.msgpack.compat.TestParquetThriftCompatibility.java

@Test
public void testing() {
    ParquetIterator parquet = ParquetIterator
            .fromResource("test-data/spark/parquet-thrift-compat.snappy.parquet");

    String[] suits = new String[] { "SPADES", "HEARTS", "DIAMONDS", "CLUBS" };
    for (int i = 0; i < 10; i++) {
        HashMap<Value, Value> nonNullablePrimitiveValues = new HashMap<>();
        {/*from w w w  . ja  va  2 s.co m*/
            HashMap<Value, Value> m = nonNullablePrimitiveValues;
            m.put(newString("boolColumn"), newBoolean(i % 2 == 0));
            m.put(newString("byteColumn"), newInteger(i));
            m.put(newString("shortColumn"), newInteger(i + 1));
            m.put(newString("intColumn"), newInteger(i + 2));
            m.put(newString("longColumn"), newInteger(i * 10));
            m.put(newString("doubleColumn"), newFloat(i + 0.2));
            // Thrift `BINARY` values are actually unencoded `STRING` values, and thus are always
            // treated as `BINARY (UTF8)` in parquet-thrift, since parquet-thrift always assume
            // Thrift `STRING`s are encoded using UTF-8.
            m.put(newString("binaryColumn"), newString("val_" + i));
            m.put(newString("stringColumn"), newString("val_" + i));
            // Thrift ENUM values are converted to Parquet binaries containing UTF-8 strings
            m.put(newString("enumColumn"), newString(suits[i % 4]));
        }

        HashMap<Value, Value> nullablePrimitiveValues = new HashMap<>();
        for (Map.Entry<Value, Value> entry : nonNullablePrimitiveValues.entrySet()) {
            Value key = newString("maybe" + StringUtils.capitalize(entry.getKey().toString()));
            Value value = (i % 3 == 0) ? newNil() : entry.getValue();
            nullablePrimitiveValues.put(key, value);
        }

        HashMap<Value, Value> complexValues = new HashMap<>();
        {
            HashMap<Value, Value> m = complexValues;
            m.put(newString("stringsColumn"),
                    newArray(newString("arr_" + i), newString("arr_" + (i + 1)), newString("arr_" + (i + 2))));
            // Thrift `SET`s are converted to Parquet `LIST`s
            m.put(newString("intSetColumn"), newArray(newInteger(i)));
            m.put(newString("intToStringColumn"),
                    newMap(newInteger(i), newString("val_" + i), newInteger(i + 1), newString("val_" + (i + 1)),
                            newInteger(i + 2), newString("val_" + (i + 2))));

            m.put(newString("complexColumn"), newMap(newInteger(i + 0), newComplexInnerValue(i),
                    newInteger(i + 1), newComplexInnerValue(i), newInteger(i + 2), newComplexInnerValue(i)));
        }

        HashMap<Value, Value> row = new HashMap<>();
        row.putAll(nonNullablePrimitiveValues);
        row.putAll(nullablePrimitiveValues);
        row.putAll(complexValues);

        Value expected = newMap(row);
        Value actual = parquet.next();
        assertThat(actual, is(expected));
    }
}