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:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java

/**
 * Creates a setter for the last added field.
 * //from   w  w  w  . j  a  va2s.co m
 * @return the class node builder
 */
public ClassNodeBuilder withSetter() {
    if (isInterface) {
        return this;
    }
    final String name = lastField.name;
    final String desc = lastField.desc;
    addMethod("set" + Character.toUpperCase(name.charAt(0)) + name.substring(1), "(" + desc + ")V");
    final Type type = Type.getType(desc);
    addInsn(new VarInsnNode(Opcodes.ALOAD, 0));
    addInsn(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), 1));
    addInsn(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, name, desc));
    addInsn(new InsnNode(Opcodes.RETURN));
    return this;
}

From source file:com.madrobot.di.wizard.json.JSONDeserializer.java

private String getAddMethodName(String fieldName) {
    return "add" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
}

From source file:com.joliciel.talismane.machineLearning.features.DynamicSourceCodeBuilderImpl.java

@Override
public Feature<T, ?> getFeature() {
    if (isDynamic) {
        // this feature implemented addDynamicSourceCode
        // construct the class code surrounding the checkInternal method

        if (LOG.isDebugEnabled())
            LOG.debug("Building class for " + rootFeature.getName());

        this.indentation = 0;
        indentString = "";

        String packageName = this.rootFeature.getClass().getPackage().getName() + ".runtime";
        String className = this.rootFeature.getClass().getSimpleName() + "_" + dynamiser.nextClassIndex();
        String qualifiedName = packageName + "." + className;
        Class<?> outcomeType = this.dynamiser.getOutcomeType(rootFeature);
        String returnType = outcomeType.getSimpleName();
        String contextType = this.dynamiser.getContextClass().getSimpleName();

        this.appendToClass("package " + packageName + ";");

        imports.add(Feature.class);
        imports.add(FeatureResult.class);
        imports.add(RuntimeEnvironment.class);

        imports.add(this.dynamiser.getContextClass());

        imports.add(this.rootFeature.getFeatureType());

        Class<?> parentClass = null;
        String checkMethodSuffix = "";
        if (AbstractCachableFeature.class.isAssignableFrom(rootFeature.getClass())) {
            parentClass = AbstractCachableFeature.class;
            checkMethodSuffix = "Internal";
        } else if (AbstractMonitorableFeature.class.isAssignableFrom(rootFeature.getClass())) {
            parentClass = AbstractMonitorableFeature.class;
            checkMethodSuffix = "Internal";
        } else {/*from w  w w .  j a v a  2s  .c o m*/
            parentClass = AbstractFeature.class;
        }
        imports.add(parentClass);

        for (Feature<T, ?> classLevelFeature : classLevelFeatures.values()) {
            imports.add(classLevelFeature.getFeatureType());
        }

        Set<String> importNames = new TreeSet<String>();
        for (Class<?> oneImport : imports) {
            if (!oneImport.getName().startsWith("java.lang."))
                importNames.add(oneImport.getName());
        }

        for (String importName : importNames) {
            this.appendToClass("import " + importName + ";");
        }

        String implementedInterface = this.rootFeature.getFeatureType().getSimpleName();
        if (this.rootFeature.getFeatureType().getTypeParameters().length > 0)
            implementedInterface += "<" + contextType + ">";

        this.appendToClass("public final class " + className + " extends " + parentClass.getSimpleName() + "<"
                + contextType + ", " + returnType + "> implements " + implementedInterface + " {");
        this.indent();

        for (Entry<String, Feature<T, ?>> classLevelFeatureEntry : classLevelFeatures.entrySet()) {
            String argumentName = classLevelFeatureEntry.getKey();
            Feature<T, ?> argument = classLevelFeatureEntry.getValue();
            String argumentType = argument.getFeatureType().getSimpleName();

            String argumentNameInitialCaps = Character.toUpperCase(argumentName.charAt(0))
                    + argumentName.substring(1);

            if (argument.getFeatureType().getTypeParameters().length == 0) {
                this.appendToClass("private " + argumentType + " " + argumentName + ";");
                this.appendToClass("public " + argumentType + " get" + argumentNameInitialCaps + "() { return "
                        + argumentName + "; }");
                this.appendToClass("public void set" + argumentNameInitialCaps + "(" + argumentType
                        + " value) { " + argumentName + "=value; }");
            } else {
                this.appendToClass("private " + argumentType + "<" + contextType + "> " + argumentName + ";");
                this.appendToClass("public " + argumentType + "<" + contextType + "> get"
                        + argumentNameInitialCaps + "() { return " + argumentName + "; }");
                this.appendToClass("public void set" + argumentNameInitialCaps + "(" + argumentType + "<"
                        + contextType + "> value) { " + argumentName + "=value; }");
            }
        }

        this.appendToClass("public FeatureResult<" + returnType + "> check" + checkMethodSuffix + "("
                + contextType + " context, RuntimeEnvironment env) {");
        this.indent();

        this.classBuilder.append(methodBuilder);

        this.outdent();
        this.appendToClass("}");

        this.appendToClass("@SuppressWarnings({ \"rawtypes\" })");
        this.appendToClass("@Override");
        this.appendToClass("public Class<? extends Feature> getFeatureType() {");
        this.indent();
        this.appendToClass("return " + this.rootFeature.getFeatureType().getSimpleName() + ".class;");
        this.outdent();
        this.appendToClass("}");

        this.outdent();
        this.appendToClass("}");

        if (LOG.isTraceEnabled()) {
            // write the class to the temp directory if trace is enabled
            try {
                File tempFile = File.createTempFile(className + "_", ".java");

                Writer tempFileWriter = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(tempFile, false), "UTF8"));
                tempFileWriter.write(this.classBuilder.toString());
                tempFileWriter.flush();
                tempFileWriter.close();
            } catch (IOException ioe) {
                LogUtils.logError(LOG, ioe);
            }
        }

        DynamicCompiler compiler = this.dynamiser.getCompiler();

        List<String> optionList = new ArrayList<String>();
        //         optionList.add("-Xlint:unchecked");
        //         optionList.add("-verbose");

        @SuppressWarnings("unchecked")
        Class<Feature<T, ?>> newFeatureClass = (Class<Feature<T, ?>>) compiler.compile(qualifiedName,
                this.classBuilder, optionList);

        // instantiate the feature
        Feature<T, ?> newFeature = null;
        try {
            newFeature = newFeatureClass.newInstance();
        } catch (InstantiationException e) {
            LogUtils.logError(LOG, e);
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            LogUtils.logError(LOG, e);
            throw new RuntimeException(e);
        }

        // assign the dependencies
        for (Entry<String, Feature<T, ?>> classLevelFeatureEntry : classLevelFeatures.entrySet()) {
            String argumentName = classLevelFeatureEntry.getKey();
            Feature<T, ?> argument = classLevelFeatureEntry.getValue();
            String argumentNameInitialCaps = Character.toUpperCase(argumentName.charAt(0))
                    + argumentName.substring(1);

            Method method;

            try {
                method = newFeature.getClass().getMethod("set" + argumentNameInitialCaps,
                        argument.getFeatureType());
            } catch (SecurityException e) {
                LogUtils.logError(LOG, e);
                throw new RuntimeException(e);
            } catch (NoSuchMethodException e) {
                LogUtils.logError(LOG, e);
                throw new RuntimeException(e);
            }

            try {
                method.invoke(newFeature, argument);
            } catch (IllegalArgumentException e) {
                LogUtils.logError(LOG, e);
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                LogUtils.logError(LOG, e);
                throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
                LogUtils.logError(LOG, e);
                throw new RuntimeException(e);
            }
        }
        newFeature.setName(rootFeature.getName());
        newFeature.setCollectionName(rootFeature.getCollectionName());

        return newFeature;
    } else {
        // this feature didn't implement addDynamicSourceCode - dynamise its arguments
        if (LOG.isDebugEnabled())
            LOG.debug("No dynamic code for " + rootFeature.getName());

        this.dynamise(rootFeature);
        return rootFeature;
    }
}

From source file:com.searchbox.framework.web.SystemController.java

/**
 * Try to run a getter function. This is useful because java 1.6 has a few
 * extra useful functions on the <code>OperatingSystemMXBean</code>
 *
 * If you are running a sun jvm, there are nice functions in:
 * UnixOperatingSystemMXBean and com.sun.management.OperatingSystemMXBean
 *
 * it is package protected so it can be tested...
 *//*from  ww  w  .  j a v  a  2 s  . c  o m*/
static void addGetterIfAvaliable(Object obj, String getter, Map<String, Object> info) {
    // This is a 1.6 function, so lets do a little magic to *try* to make it
    // work
    try {
        String n = Character.toUpperCase(getter.charAt(0)) + getter.substring(1);
        Method m = obj.getClass().getMethod("get" + n);
        m.setAccessible(true);
        Object v = m.invoke(obj, (Object[]) null);
        if (v != null) {
            info.put(getter, v);
        }
    } catch (Exception ex) {
    } // don't worry, this only works for 1.6
}

From source file:org.guicerecipes.spring.converter.SpringConverter.java

protected String getSetterMethod(PropertyValue propertyValue) {
    String name = propertyValue.getName();
    StringBuilder sb = new StringBuilder(propertyValue.getName().length() + 3);
    sb.append("set");
    if (name.length() > 0) {
        sb.append(Character.toUpperCase(name.charAt(0)));
        sb.append(name.substring(1));/*from www.j ava 2  s.co  m*/
    }
    return sb.toString();
}

From source file:com.netspective.sparx.util.xml.XmlSource.java

/**
 * Given a text string, return a string that would be suitable for that string to be used
 * as a Java identifier (as a variable or method name). Depending upon whether ucaseInitial
 * is set, the string starts out with a lowercase or uppercase letter. Then, the rule is
 * to convert all periods into underscores and title case any words separated by
 * underscores. This has the effect of removing all underscores and creating mixed case
 * words. For example, Person_Address becomes personAddress or PersonAddress depending upon
 * whether ucaseInitial is set to true or false. Person.Address would become Person_Address.
 *//*from w ww  .  jav a 2s .  c  om*/
public static String xmlTextToJavaIdentifier(String xml, boolean ucaseInitial) {
    if (xml == null || xml.length() == 0)
        return xml;

    StringBuffer identifier = new StringBuffer();
    char ch = xml.charAt(0);
    identifier.append(ucaseInitial ? Character.toUpperCase(ch) : Character.toLowerCase(ch));

    boolean uCase = false;
    for (int i = 1; i < xml.length(); i++) {
        ch = xml.charAt(i);
        if (ch == '.') {
            identifier.append('_');
        } else if (ch != '_' && Character.isJavaIdentifierPart(ch)) {
            identifier.append(Character.isUpperCase(ch) ? ch
                    : (uCase ? Character.toUpperCase(ch) : Character.toLowerCase(ch)));
            uCase = false;
        } else
            uCase = true;
    }
    return identifier.toString();
}

From source file:au.org.intersect.dms.bookinggw.impl.BookingGatewayServiceImpl.java

/**
 * Calculate initials from name parts./*  w w  w .ja  va  2s  .co  m*/
 * 
 * @param fname
 *            the first name.
 * @param mname
 *            the middle name.
 * @param lname
 *            the last name.
 * @return initials
 */
private static String calculateInitials(String fname, String mname, String lname) {
    StringTokenizer tokenizer = new StringTokenizer(fname + SPACE + mname + SPACE + lname);
    StringBuffer sb = new StringBuffer();
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if (token.length() > 0) {
            sb.append(Character.toUpperCase(token.charAt(0)));
        }
    }
    return sb.toString();
}

From source file:StringUtil.java

/**
 * Internal method for changing the first character case. It is significantly
 * faster using StringBuffers then just simply Strings.
 *//*  w w w.ja v  a  2s .  c om*/
private static String changeFirstCharacterCase(boolean capitalize, String str) {
    int strLen = str.length();
    if (strLen == 0) {
        return str;
    }
    StringBuilder buf = new StringBuilder(strLen);
    if (capitalize) {
        buf.append(Character.toUpperCase(str.charAt(0)));
    } else {
        buf.append(Character.toLowerCase(str.charAt(0)));
    }
    buf.append(str.substring(1));
    return buf.toString();
}

From source file:ca.uhn.hl7v2.sourcegen.SourceGenerator.java

public static String makeAlternateAccessorName(String fieldDesc, String parentName, int index) {
    StringBuffer aName = new StringBuffer();

    aName.append(StringUtils.capitalize(parentName.toLowerCase())).append(index).append("_");

    char[] chars = fieldDesc.toCharArray();
    boolean lastCharWasNotLetter = true;
    int inBrackets = 0;
    StringBuffer bracketContents = new StringBuffer();
    for (int i = 0; i < chars.length; i++) {
        if (chars[i] == '(')
            inBrackets++;// w  w w  .  jav a  2 s .  c o  m
        if (chars[i] == ')')
            inBrackets--;

        if (Character.isLetterOrDigit(chars[i])) {
            if (inBrackets > 0) {
                //buffer everthing in brackets
                bracketContents.append(chars[i]);
            } else {
                //add capitalized bracketed text if appropriate 
                if (bracketContents.length() > 0) {
                    aName.append(capitalize(filterBracketedText(bracketContents.toString())));
                    bracketContents = new StringBuffer();
                }
                if (lastCharWasNotLetter) {
                    //first letter of each word is upper-case
                    aName.append(Character.toUpperCase(chars[i]));
                } else {
                    aName.append(chars[i]);
                }
                lastCharWasNotLetter = false;
            }
        } else {
            lastCharWasNotLetter = true;
        }
    }
    aName.append(capitalize(filterBracketedText(bracketContents.toString())));
    String retVal = aName.toString();

    return retVal;
}

From source file:ly.apps.android.rest.client.example.activities.MainActivity.java

private String capitalize(String line) {
    return Character.toUpperCase(line.charAt(0)) + line.substring(1);
}