Example usage for java.lang Character toUpperCase

List of usage examples for java.lang Character toUpperCase

Introduction

In this page you can find the example usage for java.lang Character toUpperCase.

Prototype

public static int toUpperCase(int codePoint) 

Source Link

Document

Converts the character (Unicode code point) argument to uppercase using case mapping information from the UnicodeData file.

Usage

From source file:com.netflix.spinnaker.halyard.cli.command.v1.NestableCommand.java

protected String translateFieldName(String fieldName) {
    if (fieldName == null || fieldName.isEmpty()) {
        throw new IllegalArgumentException("A field name must be supplied to translate.");
    }/*from  w w  w .  j a va  2  s  .c o m*/

    int i = 0;
    char c = fieldName.charAt(i);
    while (c == '-') {
        i++;
        c = fieldName.charAt(i);
    }

    fieldName = fieldName.substring(i);
    String[] delimited = fieldName.split("-");

    if (delimited.length == 1) {
        return delimited[0];
    }

    for (i = 1; i < delimited.length; i++) {
        String token = delimited[i];
        if (token.length() == 0) {
            continue;
        }

        token = Character.toUpperCase(token.charAt(0)) + token.substring(1);
        delimited[i] = token;
    }

    return String.join("", delimited);
}

From source file:com.l2jfree.gameserver.util.Util.java

/**
 * Capitalizes the first letter of every "word" in a string.<BR>
 * (Based on ucwords() function of PHP)//from w  w  w  . ja v  a 2 s . c o m
 * 
 * @param String str
 * @return String containing the modified string.
 */
public static String capitalizeWords(String str) {
    char[] charArray = str.toCharArray();
    String result = "";

    // Capitalize the first letter in the given string!
    charArray[0] = Character.toUpperCase(charArray[0]);

    for (int i = 0; i < charArray.length; i++) {
        if (Character.isWhitespace(charArray[i]))
            charArray[i + 1] = Character.toUpperCase(charArray[i + 1]);

        result += Character.toString(charArray[i]);
    }

    return result;
}

From source file:forge.card.CardType.java

@Override
public boolean hasStringType(String t) {
    if (t.isEmpty()) {
        return false;
    }//from w w w .java 2 s.  co m
    if (hasSubtype(t)) {
        return true;
    }
    final char firstChar = t.charAt(0);
    if (Character.isLowerCase(firstChar)) {
        t = Character.toUpperCase(firstChar) + t.substring(1); //ensure string is proper case for enum types
    }
    final CoreType type = stringToCoreType.get(t);
    if (type != null) {
        return hasType(type);
    }
    final Supertype supertype = stringToSupertype.get(t);
    if (supertype != null) {
        return hasSupertype(supertype);
    }
    return false;
}

From source file:com.orion.plugin.Plugin.java

/**
 * Register a <tt>Command</tt> for this <tt>Plugin</tt>
 * /*from   w  w w.j a  v a2  s  .  c o m*/
 * @author Daniele Pantaleone
 * @param  name The name of the <tt>Command</tt>
 * @param  alias An alias for the <tt>Command</tt>
 * @param  group The minimum <tt>Group</tt> that can access the <tt>Command</tt>
 **/
protected void registerCommand(String name, String alias, String group) {

    try {

        // Checking name and alias value
        if ((name != null) && (name.trim().isEmpty()))
            name = null;
        if ((alias != null) && (alias.trim().isEmpty()))
            alias = null;

        // Checking if we got a proper command name as input
        // If it's detected as NULL the command will not be registered
        if (name == null)
            throw new CommandRegisterException("command name detected as NULL or empty string");

        // Trimming and lowercasing the name
        name = name.toLowerCase().trim();

        // Checking if the command name is already mapped over another method
        if (this.regcommands.containsKey(name))
            throw new CommandRegisterException("command !" + name + " is already mapped over another command");

        // Checking if the command alias is already mapped over another method
        if (alias != null) {

            // Trimming and lowercasing the alias
            alias = alias.toLowerCase().trim();

            if (this.regcommands.containsKey(alias)) {
                this.warn("Skipping alias registration for command !" + name + ": alias !" + alias
                        + " is already mapped over another command");
                alias = null;
            }

        }

        // Getting the Group object
        Group minGroup = this.groups.getByMagic(group);

        // Checking minGroup
        if (minGroup == null) {
            minGroup = this.groups.getByKeyword("superadmin");
            this.warn("Minimum required group level detected as NULL for command !" + name
                    + ". Casting to default: " + minGroup.getName());
        }

        // Getting the plugin method
        Method method = this.getClass().getMethod(
                "Cmd" + Character.toUpperCase(name.charAt(0)) + name.substring(1).toLowerCase(), Command.class);

        if (method.isAnnotationPresent(Dependency.class)) {

            // The specified command has some dependancies that need
            // to be checked before to register it in the command list
            Dependency dependancy = method.getAnnotation(Dependency.class);

            if ((dependancy.console().equals(UrT42Console.class))
                    && (!this.console.getClass().equals(UrT42Console.class))) {
                this.log.debug("Skipping command !" + name + " registration. !" + name
                        + " is available as from Urban Terror 4.2");
                return;
            }

        }

        RegisteredCommand command = new RegisteredCommand(method, this, minGroup);
        this.regcommands.put(name, alias, command);
        this.debug("Registered command [ name : " + name + " | alias : " + alias + " | minLevel : "
                + minGroup.getLevel() + " ]");

    } catch (ClassNotFoundException | SQLException | NoSuchMethodException | SecurityException e) {

        // Logging the exception
        this.error("Unable to register command !" + name, e);

    } catch (CommandRegisterException e) {

        // Log a warning so the user will notice
        this.warn("Unable to register command", e);

    }

}

From source file:com.jskj.assets.server.dataGen.GenData.java

private void addStringSetterGetting(TopLevelClass topLevelClass, IntrospectedTable introspectedTable,
        String name) {//from w w  w . jav  a2 s  .c  om
    CommentGenerator commentGenerator = context.getCommentGenerator();
    Field field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    // field.setType(FullyQualifiedJavaType.getIntInstance());
    field.setType(PrimitiveTypeWrapper.getStringInstance());
    field.setName(name);
    // field.setInitializationString("-1");
    commentGenerator.addFieldComment(field, introspectedTable);
    topLevelClass.addField(field);
    char c = name.charAt(0);
    String camel = Character.toUpperCase(c) + name.substring(1);
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("set" + camel);
    method.addParameter(new Parameter(PrimitiveTypeWrapper.getStringInstance(), name));
    method.addBodyLine("this." + name + "=" + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(PrimitiveTypeWrapper.getStringInstance());
    method.setName("get" + camel);
    method.addBodyLine("return " + name + ";");
    commentGenerator.addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}

From source file:StringUtils.java

public static String capitalize(String string) {
    return string == null ? null
            : string.length() == 0 ? "" : Character.toUpperCase(string.charAt(0)) + string.substring(1);
}

From source file:com.medallia.tiny.Strings.java

private static String capitalizeSingleEnglishName(String lcName) {
    if (lcName == null || lcName.length() == 0)
        return "";
    String exFound = enCapExceptions.get(lcName);
    if (exFound != null)
        return exFound;
    StringBuilder res = new StringBuilder(lcName.length());
    int i;/* ww w  .ja  v a2  s.  c om*/
    int n = lcName.length();
    if (lcName.startsWith("d'")) {
        res.append("d'");
        i = 2;
    } else if (lcName.startsWith("mc")) {
        res.append("Mc");
        if (n > 2)
            res.append(Character.toUpperCase(lcName.charAt(2)));
        i = 3;
    } else if (lcName.startsWith("mac")) {
        res.append("Mac");
        if (n > 3)
            res.append(Character.toUpperCase(lcName.charAt(3)));
        i = 4;
    } else {
        res.append(Character.toUpperCase(lcName.charAt(0)));
        i = 1;
    }
    for (; i < n; i++) {
        if (lcName.charAt(i) == ' ' && (i > 0) && (lcName.charAt(i - 1) != ' '))
            res.append(' ');
        if (i == 0)
            res.append(Character.toUpperCase(lcName.charAt(i)));
        else {
            switch (lcName.charAt(i - 1)) {
            case '-':
            case '.':
            case ' ':
                res.append(Character.toUpperCase(lcName.charAt(i)));
                break;
            case '\'':
                if (i == (n - 1))
                    res.append(lcName.charAt(i));
                else
                    res.append(Character.toUpperCase(lcName.charAt(i)));
                break;
            default:
                res.append(lcName.charAt(i));
                break;
            }
        }
    }
    return res.toString();
}

From source file:com.amazonaws.services.kinesis.clientlibrary.config.KinesisClientLibConfigurator.java

private void withProperty(String propertyKey, Properties properties, KinesisClientLibConfiguration config) {
    if (propertyKey.isEmpty()) {
        throw new IllegalArgumentException("The property can't be empty string");
    }/*w  w  w .  j ava  2s  .c  o m*/
    // Assume that all the setters in KinesisClientLibConfiguration are in the following format
    // They all start with "with" followed by the variable name with first letter capitalized
    String targetMethodName = PREFIX + Character.toUpperCase(propertyKey.charAt(0)) + propertyKey.substring(1);
    String propertyValue = properties.getProperty(propertyKey);
    if (nameToMethods.containsKey(targetMethodName)) {
        for (Method method : nameToMethods.get(targetMethodName)) {
            if (method.getParameterTypes().length == 1 && method.getName().equals(targetMethodName)) {
                Class<?> paramType = method.getParameterTypes()[0];
                if (classToDecoder.containsKey(paramType)) {
                    IPropertyValueDecoder<?> decoder = classToDecoder.get(paramType);
                    try {
                        method.invoke(config, decoder.decodeValue(propertyValue));
                        LOG.info(String.format("Successfully set property %s with value %s", propertyKey,
                                propertyValue));
                        return;
                    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                        // At this point, we really thought that we could call this method.
                        LOG.warn(String.format("Encountered an error while invoking method %s with value %s. "
                                + "Exception was %s", method, propertyValue, e));
                    } catch (UnsupportedOperationException e) {
                        LOG.warn(String.format("The property %s is not supported as type %s at this time.",
                                propertyKey, paramType));
                    }
                } else {
                    LOG.debug(
                            String.format("No method for decoding parameters of type %s so method %s could not "
                                    + "be invoked.", paramType, method));
                }
            } else {
                LOG.debug(
                        String.format(
                                "Method %s doesn't look like it is appropriate for setting property %s. "
                                        + "Looking for something called %s.",
                                method, propertyKey, targetMethodName));
            }
        }
    } else {
        LOG.debug(
                String.format("There was no appropriately named method for setting property %s.", propertyKey));
    }
}

From source file:com.github.lindenb.jvarkit.tools.backlocate.BackLocate.java

private void backLocate(PrintStream out, KnownGene gene, String geneName, char aa1, char aa2, int peptidePos1)
        throws IOException {

    final GeneticCode geneticCode = getGeneticCodeByChromosome(gene.getChromosome());
    RNASequence wildRNA = null;/*w  w w. j  av  a  2 s  .  c o  m*/
    ProteinCharSequence wildProt = null;

    if (genomicSeq == null || !gene.getChromosome().equals(genomicSeq.getChrom())) {
        LOG.info("fetch genome");
        this.genomicSeq = new GenomicSequence(this.indexedFastaSequenceFile, gene.getContig());
    }

    if (gene.isPositiveStrand()) {
        int exon_index = 0;
        while (exon_index < gene.getExonCount()) {
            for (int i = gene.getExonStart(exon_index); i < gene.getExonEnd(exon_index); ++i) {
                if (i < gene.getCdsStart())
                    continue;
                if (i >= gene.getCdsEnd())
                    break;

                if (wildRNA == null) {
                    wildRNA = new RNASequence(genomicSeq, '+');
                }

                wildRNA.genomicPositions.add(i);

                if (wildRNA.length() % 3 == 0 && wildRNA.length() > 0 && wildProt == null) {
                    wildProt = new ProteinCharSequence(geneticCode, wildRNA);
                }
            }
            ++exon_index;
        }

    } else // reverse orientation
    {
        int exon_index = gene.getExonCount() - 1;
        while (exon_index >= 0) {
            for (int i = gene.getExonEnd(exon_index) - 1; i >= gene.getExonStart(exon_index); --i) {
                if (i >= gene.getCdsEnd())
                    continue;
                if (i < gene.getCdsStart())
                    break;

                if (wildRNA == null) {
                    wildRNA = new RNASequence(genomicSeq, '-');
                }

                wildRNA.genomicPositions.add(i);
                if (wildRNA.length() % 3 == 0 && wildRNA.length() > 0 && wildProt == null) {
                    wildProt = new ProteinCharSequence(geneticCode, wildRNA);
                }

            }
            --exon_index;
        }

    } //end of if reverse

    if (wildProt == null) {
        stderr().println("#no protein found for transcript:" + gene.getName());
        return;
    }
    int peptideIndex0 = peptidePos1 - 1;
    if (peptideIndex0 >= wildProt.length()) {
        out.println("#index out of range for :" + gene.getName() + " petide length=" + wildProt.length());
        return;
    }

    if (wildProt.charAt(peptideIndex0) != aa1) {
        out.println("##Warning ref aminod acid for " + gene.getName() + "  [" + peptidePos1
                + "] is not the same (" + wildProt.charAt(peptideIndex0) + "/" + aa1 + ")");
    } else {
        out.println("##" + gene.getName());
    }
    int indexesInRNA[] = new int[] { 0 + peptideIndex0 * 3, 1 + peptideIndex0 * 3, 2 + peptideIndex0 * 3 };
    final String wildCodon = "" + wildRNA.charAt(indexesInRNA[0]) + wildRNA.charAt(indexesInRNA[1])
            + wildRNA.charAt(indexesInRNA[2]);
    /* 2015 : adding possible mut codons */
    final Set<String> possibleAltCodons = new HashSet<>();
    final char bases[] = new char[] { 'A', 'C', 'G', 'T' };
    for (int codon_pos = 0; codon_pos < 3; ++codon_pos) {
        StringBuilder sb = new StringBuilder(wildCodon);
        for (char mutBase : bases) {
            sb.setCharAt(codon_pos, mutBase);
            if (geneticCode.translate(sb.charAt(0), sb.charAt(1), sb.charAt(2)) == Character.toUpperCase(aa2)) {
                possibleAltCodons.add(sb.toString());
            }
        }
    }

    for (int indexInRna : indexesInRNA) {
        out.print(geneName);
        out.print('\t');
        out.print(aa1);
        out.print('\t');
        out.print(peptidePos1);
        out.print('\t');
        out.print(aa2);
        out.print('\t');
        out.print(gene.getName());
        out.print('\t');
        out.print(gene.getStrand() == Strand.NEGATIVE ? "-" : "+");
        out.print('\t');
        out.print(wildProt.charAt(peptideIndex0));
        out.print('\t');
        out.print(indexInRna);
        out.print('\t');
        out.print(wildCodon);
        out.print('\t');
        if (possibleAltCodons.isEmpty()) {
            out.print('.');
        } else {
            boolean first = true;
            for (String mutCodon : possibleAltCodons) {
                if (!first)
                    out.print('|');
                first = false;
                out.print(mutCodon);
            }
        }
        out.print('\t');
        out.print(wildRNA.charAt(indexInRna));
        out.print('\t');
        out.print(gene.getChromosome());
        out.print('\t');
        out.print(wildRNA.genomicPositions.get(indexInRna));
        out.print('\t');
        String exonName = null;
        for (KnownGene.Exon exon : gene.getExons()) {
            int genome = wildRNA.genomicPositions.get(indexInRna);
            if (exon.getStart() <= genome && genome < exon.getEnd()) {
                exonName = exon.getName();
                break;
            }
        }
        out.print(exonName);
        if (this.printSequences) {
            String s = wildRNA.toString();
            out.print('\t');
            out.print(s.substring(0, indexInRna) + "[" + s.charAt(indexInRna) + "]"
                    + (indexInRna + 1 < s.length() ? s.substring(indexInRna + 1) : ""));
            s = wildProt.toString();
            out.print('\t');
            out.print(
                    s.substring(0, peptideIndex0) + "[" + aa1 + "/" + aa2 + "/" + wildProt.charAt(peptideIndex0)
                            + "]" + (peptideIndex0 + 1 < s.length() ? s.substring(peptideIndex0 + 1) : ""));
        }
        out.println();
    }
}

From source file:net.sf.jabref.bst.BibtexCaseChanger.java

private int convertNonControl(char[] c, int start, StringBuilder sb, FORMAT_MODE format) {
    int pos = start;
    switch (format) {
    case TITLE_LOWERS:
    case ALL_LOWERS:
        sb.append(Character.toLowerCase(c[pos]));
        pos++;//from   www.j  ava  2  s  .c o  m
        break;
    case ALL_UPPERS:
        sb.append(Character.toUpperCase(c[pos]));
        pos++;
        break;
    default:
        LOGGER.info("convertNonControl - Unknown format: " + format);
        break;
    }
    return pos;
}