Example usage for org.apache.commons.lang WordUtils capitalize

List of usage examples for org.apache.commons.lang WordUtils capitalize

Introduction

In this page you can find the example usage for org.apache.commons.lang WordUtils capitalize.

Prototype

public static String capitalize(String str) 

Source Link

Document

Capitalizes all the whitespace separated words in a String.

Usage

From source file:net.caseif.unusuals.Main.java

private ItemStack createUnusual(Material type, String effect) {
    UnusualEffect uEffect = effects.get(effect);
    if (uEffect == null) {
        throw new IllegalArgumentException("Effect \"" + effect + "\" does not exist!");
    }/*w  w w . j  a  v a  2 s .co m*/

    ItemStack is = new ItemStack(type, 1);
    ItemMeta meta = is.getItemMeta();
    meta.setDisplayName(
            UNUSUAL_COLOR + "Unusual " + WordUtils.capitalize(type.toString().toLowerCase().replace("_", " ")));
    List<String> lore = new ArrayList<String>();
    lore.add(EFFECT_COLOR + "Effect: " + effect);
    meta.setLore(lore);
    is.setItemMeta(meta);
    return is;
}

From source file:cognition.common.utils.StringTools.java

private static void loadSurnames() {
    InputStream resourceAsStream = StringTools.class.getClassLoader()
            .getResourceAsStream("anonymisation/lastnames");
    try (BufferedReader br = new BufferedReader(new InputStreamReader(resourceAsStream))) {
        String line;/* w w  w.j a  v  a2s.  c om*/
        while ((line = br.readLine()) != null) {
            lastNames.add(WordUtils.capitalize(line));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(resourceAsStream);
    }
}

From source file:games.stendhal.server.maps.quests.EmotionCrystals.java

private void prepareRiddlesStep() {
    // List of NPCs
    final List<SpeakerNPC> npcList = new ArrayList<SpeakerNPC>();

    // Add the crystals to the NPC list with their riddle
    for (String color : crystalColors) {
        npcList.add(npcs.get(WordUtils.capitalize(color) + " Crystal"));
    }/*  w ww  .  j av a2  s  .c  o m*/

    // Riddles
    final List<String> riddles = new ArrayList<String>();
    // Answers to riddles
    final List<List<String>> answers = new ArrayList<List<String>>();

    // Red Crystal (crystal of anger)
    riddles.add(
            "I burn like fire. My presence is not enjoyed. Those who test me will feel my wrath. What am I?");
    answers.add(Arrays.asList("anger", "angry", "mad", "offended", "hostility", "hostile", "hate", "hatred",
            "animosity"));
    // Purple Crystal (crystal of fear)
    riddles.add(
            "I dare not come out and avoid the consequence. They try and convince my but I shall not. Trembling is my favorite activity. What am I?");
    answers.add(Arrays.asList("fear", "fearful", "fearfullness", "fright", "frightened", "afraid", "scared"));
    // Yellow Crystal (crystal of joy)
    riddles.add(
            "I can't be stopped. Only positive, no negative, can exist in my heart. If you spread me life will be as sunshine. What am I?");
    answers.add(Arrays.asList("joy", "joyful", "joyfulness", "happy", "happiness", "happyness", "cheer",
            "cheery", "cheerful", "cheerfulness"));
    // Pink Crystal (crystal of love)
    riddles.add(
            "I care for all things. I am purest of all. If you share me I'm sure I will be reciprocated. What am I?");
    answers.add(Arrays.asList("love", "amor", "amour", "amity", "compassion"));
    // Blue Crystal (crystal of peace)
    riddles.add(
            "I do not let things bother me. I never get overly energetic. Meditation is my fortay. What am I?");
    answers.add(Arrays.asList("peace", "peaceful", "peacefullness", "serenity", "serene", "calmness", "calm"));

    // Add conversation states
    for (int n = 0; n < npcList.size(); n++) {
        SpeakerNPC crystalNPC = npcList.get(n);
        String rewardItem = crystalColors[n] + " emotion crystal";
        String crystalRiddle = riddles.get(n);
        List<String> crystalAnswers = answers.get(n);

        // In place of QUEST_SLOT
        //String RIDDLER_SLOT = crystalColors.get(n) + "_crystal_riddle";

        final List<ChatAction> rewardAction = new LinkedList<ChatAction>();
        rewardAction.add(new EquipItemAction(rewardItem, 1, true));
        rewardAction.add(new IncreaseKarmaAction(5));
        rewardAction.add(new SetQuestToTimeStampAction(QUEST_SLOT, OFFSET_TIMESTAMPS + n));
        rewardAction.add(new SetQuestAction(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n, "riddle_solved"));

        final List<ChatAction> wrongGuessAction = new LinkedList<ChatAction>();
        wrongGuessAction.add(new SetQuestToTimeStampAction(QUEST_SLOT, OFFSET_TIMESTAMPS + n));
        wrongGuessAction.add(new SetQuestAction(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n, "wrong"));

        // Player asks about riddle
        crystalNPC.add(ConversationStates.ATTENDING, ConversationPhrases.QUEST_MESSAGES,
                new AndCondition(new QuestInStateCondition(QUEST_SLOT, 0, "start"), new OrCondition(
                        new QuestNotInStateCondition(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n, "riddle_solved"),
                        new AndCondition(
                                new QuestInStateCondition(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n,
                                        "riddle_solved"),
                                new NotCondition(new PlayerHasItemWithHimCondition(rewardItem)),
                                new TimePassedCondition(QUEST_SLOT, OFFSET_TIMESTAMPS + n, WAIT_TIME_RETRY)))),
                ConversationStates.ATTENDING, "Please answer the #riddle which I have for you...", null);

        // Player asks about riddle
        crystalNPC.add(ConversationStates.ATTENDING, Arrays.asList("riddle", "question", "query", "puzzle"),
                new AndCondition(new QuestInStateCondition(QUEST_SLOT, 0, "start"), new OrCondition(
                        new QuestNotInStateCondition(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n, "riddle_solved"),
                        new AndCondition(
                                new QuestInStateCondition(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n,
                                        "riddle_solved"),
                                new NotCondition(new PlayerHasItemWithHimCondition(rewardItem)),
                                new TimePassedCondition(QUEST_SLOT, OFFSET_TIMESTAMPS + n, WAIT_TIME_RETRY)))),
                ConversationStates.ATTENDING, crystalRiddle,
                new SetQuestAction(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n, "riddle"));

        // Player gets the riddle right
        crystalNPC.add(ConversationStates.ATTENDING, crystalAnswers,
                new QuestInStateCondition(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n, "riddle"),
                ConversationStates.IDLE, "That is correct. Take this crystal as a reward.",
                new MultipleActions(rewardAction));

        // Player gets the riddle wrong
        crystalNPC.add(ConversationStates.ATTENDING, "",
                new QuestInStateCondition(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n, "riddle"),
                ConversationStates.IDLE, "I'm sorry, that is incorrect.",
                new MultipleActions(wrongGuessAction));

        // Player returns before time is up, to get another chance
        crystalNPC.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
                new AndCondition(new QuestInStateCondition(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n, "wrong"),
                        new NotCondition(
                                new TimePassedCondition(QUEST_SLOT, OFFSET_TIMESTAMPS + n, WAIT_TIME_WRONG))),
                ConversationStates.IDLE, null, new SayTimeRemainingAction(QUEST_SLOT, OFFSET_TIMESTAMPS + n,
                        WAIT_TIME_WRONG, "Think hard on your answer and return to me again in"));

        // Player returns before time is up, to get another crystal
        crystalNPC.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
                new AndCondition(
                        new QuestInStateCondition(QUEST_SLOT, OFFSET_SUCCESS_MARKER + n, "riddle_solved"),
                        new NotCondition(new PlayerHasItemWithHimCondition(rewardItem)),
                        new NotCondition(
                                new TimePassedCondition(QUEST_SLOT, OFFSET_TIMESTAMPS + n, WAIT_TIME_RETRY))),
                ConversationStates.IDLE, null, new SayTimeRemainingAction(QUEST_SLOT, OFFSET_TIMESTAMPS + n,
                        WAIT_TIME_RETRY, "Oh, did you lose my crystal? I can give you a new one in"));

        // Player can't do riddle twice while they still have the reward
        crystalNPC.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
                new AndCondition(new QuestInStateCondition(QUEST_SLOT, 0, "start"),
                        new PlayerHasItemWithHimCondition(rewardItem)),
                ConversationStates.ATTENDING, "I hope you make someone happy with your crystal!", null);

        // Player asks for quest without talking to Julius first
        crystalNPC.add(ConversationStates.ATTENDING, ConversationPhrases.QUEST_MESSAGES,
                new QuestNotStartedCondition(QUEST_SLOT), ConversationStates.ATTENDING,
                "Sorry, but I have nothing to offer you. Maybe someone needs a sparkling #crystal soon...",
                null);

        crystalNPC.add(ConversationStates.ATTENDING, Arrays.asList("crystal", "sparkling crystal"),
                new QuestNotStartedCondition(QUEST_SLOT), ConversationStates.ATTENDING,
                "There is a soldier in Ados who used some beautiful crystals in jewellery for his wife...",
                null);

    }
}

From source file:com.dbs.sdwt.jpa.JpaUtil.java

public <T> boolean isPk(ManagedType<T> mt, SingularAttribute<? super T, ?> attr) {
    try {/*w  ww.ja v  a 2 s .  c o m*/
        Method m = MethodUtils.getAccessibleMethod(mt.getJavaType(),
                "get" + WordUtils.capitalize(attr.getName()), (Class<?>) null);
        if (m != null && m.getAnnotation(Id.class) != null) {
            return true;
        }

        Field field = mt.getJavaType().getField(attr.getName());
        return field.getAnnotation(Id.class) != null;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.cloudera.whirr.cm.handler.BaseTestHandler.java

private static Object any(Object value) {
    try {//from   ww  w.j av  a2 s  .  c o  m
        new CmServerLog.CmServerLogSysOut(LOG_TAG_CM_SERVER_API, false).logOperation(
                WordUtils.capitalize(Thread.currentThread().getStackTrace()[4].getMethodName()),
                new CmServerLogSyncCommand() {
                    @Override
                    public void execute() throws Exception {
                    }
                });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return value;
}

From source file:me.azenet.UHPlugin.UHPluginCommand.java

/**
 * Handles a command./*  w ww.  j  a va  2  s.co  m*/
 * 
 * @param sender The sender
 * @param command The executed command
 * @param label The alias used for this command
 * @param args The arguments given to the command
 * 
 * @author Amaury Carrade
 */
@SuppressWarnings("rawtypes")
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

    boolean ourCommand = false;
    for (String commandName : p.getDescription().getCommands().keySet()) {
        if (commandName.equalsIgnoreCase(command.getName())) {
            ourCommand = true;
            break;
        }
    }

    if (!ourCommand) {
        return false;
    }

    /** Team chat commands **/

    if (command.getName().equalsIgnoreCase("t")) {
        doTeamMessage(sender, command, label, args);
        return true;
    }
    if (command.getName().equalsIgnoreCase("g")) {
        doGlobalMessage(sender, command, label, args);
        return true;
    }
    if (command.getName().equalsIgnoreCase("togglechat")) {
        doToggleTeamChat(sender, command, label, args);
        return true;
    }

    /** /join & /leave commands **/

    if (command.getName().equalsIgnoreCase("join")) {
        doJoin(sender, command, label, args);
        return true;
    }
    if (command.getName().equalsIgnoreCase("leave")) {
        doLeave(sender, command, label, args);
        return true;
    }

    if (args.length == 0) {
        help(sender, args, false);
        return true;
    }

    String subcommandName = args[0].toLowerCase();

    // First: subcommand existence.
    if (!this.commands.contains(subcommandName)) {
        try {
            Integer.valueOf(subcommandName);
            help(sender, args, false);
        } catch (NumberFormatException e) { // If the subcommand isn't a number, it's an error.
            help(sender, args, true);
        }
        return true;
    }

    // Second: is the sender allowed?
    if (!isAllowed(sender, subcommandName)) {
        unauthorized(sender, command);
        return true;
    }

    // Third: instantiation
    try {
        Class<? extends UHPluginCommand> cl = this.getClass();
        Class[] parametersTypes = new Class[] { CommandSender.class, Command.class, String.class,
                String[].class };

        Method doMethod = cl.getDeclaredMethod("do" + WordUtils.capitalize(subcommandName), parametersTypes);

        doMethod.invoke(this, new Object[] { sender, command, label, args });

        return true;

    } catch (NoSuchMethodException e) {
        // Unknown method => unknown subcommand.
        help(sender, args, true);
        return true;

    } catch (SecurityException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException e) {
        sender.sendMessage(i.t("cmd.errorLoad"));
        e.printStackTrace();
        return false;
    }
}

From source file:cognition.common.utils.StringTools.java

private static void loadFemaleNames() {
    InputStream resourceAsStream = StringTools.class.getClassLoader()
            .getResourceAsStream("anonymisation/femaleNames");
    try (BufferedReader br = new BufferedReader(new InputStreamReader(resourceAsStream))) {
        String line;/*from   w  ww  . j av a 2s .co  m*/
        while ((line = br.readLine()) != null) {
            femaleNames.add(WordUtils.capitalize(line));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(resourceAsStream);
    }
}

From source file:net.roboconf.target.docker.internal.DockerUtils.java

/**
 * Finds the options and tries to configure them on the creation command.
 * @param options the options (key = name, value = option value)
 * @param cmd a non-null command to create a container
 * @throws TargetException//  ww  w  .  j av  a2s .com
 */
public static void configureOptions(Map<String, String> options, CreateContainerCmd cmd)
        throws TargetException {

    Logger logger = Logger.getLogger(DockerUtils.class.getName());

    // Basically, we had two choices:
    // 1. Map our properties to the Java REST API.
    // 2. By-pass it and send our custom JSon object.
    //
    // The second option is much more complicated.
    // So, we use Java reflection and some hacks to match Docker properties
    // with the setter methods available in the API. The API remains in charge
    // of generating the right JSon objects.
    Map<String, List<String>> hackedSetterNames = new HashMap<>();

    // Remains from Docker-Java 2.x (the mechanism still works)
    //
    //      List<String> list = new ArrayList<> ();
    //      list.add( "withMemoryLimit" );
    //      hackedSetterNames.put( "withMemory", list );

    // List known types
    List<Class<?>> types = new ArrayList<>();
    types.add(String.class);
    types.add(String[].class);
    types.add(long.class);
    types.add(Long.class);
    types.add(int.class);
    types.add(Integer.class);
    types.add(boolean.class);
    types.add(Boolean.class);
    types.add(Capability[].class);

    // Deal with the options
    for (Map.Entry<String, String> entry : options.entrySet()) {
        String optionValue = entry.getValue();

        // Now, guess what option to set
        String methodName = entry.getKey().replace("-", " ").trim();
        methodName = WordUtils.capitalize(methodName);
        methodName = methodName.replace(" ", "");
        methodName = "with" + methodName;

        Method _m = null;
        for (Method m : cmd.getClass().getMethods()) {

            boolean sameMethod = methodName.equalsIgnoreCase(m.getName());
            boolean methodWithAlias = hackedSetterNames.containsKey(methodName)
                    && hackedSetterNames.get(methodName).contains(m.getName());

            if (sameMethod || methodWithAlias) {

                // Only one parameter?
                if (m.getParameterTypes().length != 1) {
                    logger.warning("A method was found for " + entry.getKey()
                            + " but it does not have the right number of parameters.");
                    continue;
                }

                // The right type?
                if (!types.contains(m.getParameterTypes()[0])) {

                    // Since Docker-java 3.x, there are two methods to set cap-add and cap-drop.
                    // One takes an array as parameter, the other takes a list.
                    logger.warning("A method was found for " + entry.getKey()
                            + " but it does not have the right parameter type. "
                            + "Skipping it. You may want to add a feature request.");

                    continue;
                }

                // That's probably the right one.
                _m = m;
                break;
            }
        }

        // Handle errors
        if (_m == null)
            throw new TargetException(
                    "Nothing matched the " + entry.getKey() + " option in the REST API. Please, report it.");

        // Try to set the option in the REST client
        try {
            Object o = prepareParameter(optionValue, _m.getParameterTypes()[0]);
            _m.invoke(cmd, o);

        } catch (ReflectiveOperationException | IllegalArgumentException e) {
            throw new TargetException("Option " + entry.getKey() + " could not be set.");
        }
    }
}

From source file:com.cloudera.whirr.cm.server.CmServerBuilder.java

private Object executeObject() throws CmServerException {
    if (ip == null) {
        throw new CmServerException("Required paramater [ip] not set");
    }/*from ww w . j  av a 2 s. co  m*/
    if (command == null) {
        throw new CmServerException("Required paramater [command] not set");
    }
    if (server == null) {
        server = factory.getCmServer(version, versionApi, versionCdh, ip, ipInternal, port, user, password,
                new CmServerLog.CmServerLogSysOut(LOG_TAG_CM_SERVER_API, false));
    }
    List<Object> paramaters = new ArrayList<Object>();
    for (Class<?> clazz : COMMANDS.get(command).getParameterTypes()) {
        if (clazz.equals(CmServerCluster.class)) {
            if (cluster == null) {
                throw new CmServerException("Required paramater [cluster] not set");
            }
            paramaters.add(cluster);
        } else if (clazz.equals(File.class)) {
            if (path == null) {
                throw new CmServerException("Required paramater [path] not set");
            }
            paramaters.add(path);
        } else {
            throw new CmServerException("Unexpected paramater type [" + clazz.getName() + "]");
        }
    }
    String label = WordUtils.capitalize(command);
    try {
        logger.logOperationStartedSync(label);
        Object commandReturn = COMMANDS.get(command).invoke(server, paramaters.toArray());
        logger.logOperationFinishedSync(label);
        return commandReturn;
    } catch (Exception exception) {
        logger.logOperationFailedSync(label, exception);
        throw new CmServerException("Unexpected runtime exception executing CM Server command", exception);
    }
}

From source file:cognition.common.utils.StringTools.java

private static void loadMaleNames() {
    InputStream resourceAsStream = StringTools.class.getClassLoader()
            .getResourceAsStream("anonymisation/maleNames");
    try (BufferedReader br = new BufferedReader(new InputStreamReader(resourceAsStream))) {
        String line;// w  w  w.j a  v  a2 s .c  o m
        while ((line = br.readLine()) != null) {
            maleNames.add(WordUtils.capitalize(line));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(resourceAsStream);
    }
}