Example usage for java.lang Character isUpperCase

List of usage examples for java.lang Character isUpperCase

Introduction

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

Prototype

public static boolean isUpperCase(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is an uppercase character.

Usage

From source file:org.codehaus.griffon.commons.GriffonClassUtils.java

private static String convertPropertyName(String prop) {
    if (Character.isUpperCase(prop.charAt(0)) && Character.isUpperCase(prop.charAt(1))) {
        return prop;
    } else if (Character.isDigit(prop.charAt(0))) {
        return prop;
    } else {/*from w  w w  . j a  va  2  s  .c o m*/
        return String.valueOf(prop.charAt(0)).toLowerCase() + prop.substring(1);
    }
}

From source file:com.adito.util.Utils.java

/**
 * Converts camelCaseVersusC to camel_case_versus_c
 **///from  w w w.  j av a 2s  .  com
public static String toUnderscore(String s) {
    StringBuffer buf = new StringBuffer();
    char[] ch = s.toCharArray();
    for (int i = 0; i < ch.length; ++i) {
        if (Character.isUpperCase(ch[i])) {
            buf.append('_');
            buf.append(Character.toLowerCase(ch[i]));
        } else {
            buf.append(ch[i]);
        }
    }
    //System.err.println(s + " -> " + buf.toString());
    return buf.toString();
}

From source file:com.zhumeng.dream.orm.hibernate.HibernateDao.java

public static String camelToUnderline(String param) {
    if (param == null || "".equals(param.trim())) {
        return "";
    }/*from w ww  .  jav a2  s  .co  m*/
    int len = param.length();
    StringBuilder sb = new StringBuilder(len);
    for (int i = 0; i < len; i++) {
        char c = param.charAt(i);
        if (Character.isUpperCase(c)) {
            sb.append('_');
            sb.append(Character.toLowerCase(c));
        } else {
            sb.append(c);
        }
    }
    return sb.toString();
}

From source file:com.adito.boot.Util.java

/**
 * Turn a key into an english like phrase. E.g. <i>webForwardURL</i>
 * would be turned into <i>Web Forward URL</i>.
 * /*from ww w .j av  a  2  s. c  om*/
 * @param constant constant name
 * @return readable name
 */
public static String makeKeyReadable(String constant) {
    // vFSPath
    StringBuffer buf = new StringBuffer();
    char ch;
    char lastChar = 0;
    for (int i = 0; i < constant.length(); i++) {
        ch = constant.charAt(i);
        if (i == 0) {
            ch = Character.toUpperCase(ch);
        } else {
            if (Character.isUpperCase(ch)) {
                if (!Character.isUpperCase(lastChar)) {
                    buf.append(" ");
                }
            }
        }
        buf.append(ch);
        lastChar = ch;
    }
    return buf.toString();
}

From source file:org.codehaus.griffon.commons.GriffonClassUtils.java

public static boolean isSetter(String name, Class[] args) {
    if (StringUtils.isBlank(name) || args == null)
        return false;

    if (name.startsWith("set")) {
        if (args.length != 1)
            return false;
        name = name.substring(3);//from   ww  w  .  j  ava2s.c om
        if (name.length() > 0 && Character.isUpperCase(name.charAt(0)))
            return true;
    }

    return false;
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

public void performRestartWordSuggestion(final InputConnection ic) {
    // I assume ASK DOES NOT predict at this moment!

    // 2) predicting and moved outside the word - abort predicting, update
    // shift state
    // 2.1) to a new word - restart predicting on the new word
    // 2.2) to no word land - nothing else

    // this means that the new cursor position is outside the candidates
    // underline/*from   w  w  w.  j  av a  2  s. c  o  m*/
    // this can be either because the cursor is really outside the
    // previously underlined (suggested)
    // or nothing was suggested.
    // in this case, we would like to reset the prediction and restart
    // if the user clicked inside a different word
    // restart required?
    if (canRestartWordSuggestion()) {// 2.1
        ic.beginBatchEdit();// don't want any events till I finish handling
        // this touch
        abortCorrectionAndResetPredictionState(false);

        // locating the word
        CharSequence toLeft = "";
        CharSequence toRight = "";
        while (true) {
            CharSequence newToLeft = ic.getTextBeforeCursor(toLeft.length() + 1, 0);
            if (TextUtils.isEmpty(newToLeft) || isWordSeparator(newToLeft.charAt(0))
                    || newToLeft.length() == toLeft.length()) {
                break;
            }
            toLeft = newToLeft;
        }
        while (true) {
            CharSequence newToRight = ic.getTextAfterCursor(toRight.length() + 1, 0);
            if (TextUtils.isEmpty(newToRight) || isWordSeparator(newToRight.charAt(newToRight.length() - 1))
                    || newToRight.length() == toRight.length()) {
                break;
            }
            toRight = newToRight;
        }
        CharSequence word = toLeft.toString() + toRight.toString();
        Logger.d(TAG, "Starting new prediction on word '%s'.", word);
        mUndoCommitCursorPosition = UNDO_COMMIT_NONE;
        mWord.reset();

        final int[] tempNearByKeys = new int[1];

        for (int index = 0; index < word.length(); index++) {
            final char c = word.charAt(index);
            if (index == 0)
                mWord.setFirstCharCapitalized(Character.isUpperCase(c));

            tempNearByKeys[0] = c;
            mWord.add(c, tempNearByKeys);

            TextEntryState.typedCharacter(c, false);
        }
        ic.deleteSurroundingText(toLeft.length(), toRight.length());
        ic.setComposingText(word, 1);
        // repositioning the cursor
        if (toRight.length() > 0) {
            final int cursorPosition = getCursorPosition(ic) - toRight.length();
            Logger.d(TAG, "Repositioning the cursor inside the word to position %d", cursorPosition);
            ic.setSelection(cursorPosition, cursorPosition);
        }

        mWord.setCursorPosition(toLeft.length());
        ic.endBatchEdit();
        postUpdateSuggestions();
    } else {
        Logger.d(TAG, "performRestartWordSuggestion canRestartWordSuggestion == false");
    }
}

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * INTERNAL method that capitalizes the first character of a string
 *
 * @param s The string to capitalize//w w w.  ja v a  2  s.  c  o  m
 * @return The capitalized string
 */
private static String capitalize(String s) {
    if (s == null || s.length() == 0) {
        return "";
    }
    char first = s.charAt(0);
    if (Character.isUpperCase(first)) {
        return s;
    } else {
        return Character.toUpperCase(first) + s.substring(1);
    }
}

From source file:org.jahia.utils.maven.plugin.osgi.BuildFrameworkPackageListMojo.java

private void scanJar(Map<String, Map<String, Map<String, VersionLocation>>> packageVersionCounts, File jarFile,
        String defaultVersion) throws IOException {
    JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile));
    Manifest jarManifest = jarInputStream.getManifest();
    // Map<String, String> manifestVersions = new HashMap<String,String>();
    String specificationVersion = null;
    if (jarManifest == null) {
        getLog().warn("No MANIFEST.MF file found for dependency " + jarFile);
    } else {//  ww  w.j  a va  2s  .  c o m
        if (jarManifest.getMainAttributes() == null) {
            getLog().warn("No main attributes found in MANIFEST.MF file found for dependency " + jarFile);
        } else {
            specificationVersion = jarManifest.getMainAttributes().getValue("Specification-Version");
            if (defaultVersion == null) {
                if (jarManifest.getMainAttributes().getValue("Bundle-Version") != null) {
                } else if (specificationVersion != null) {
                    defaultVersion = specificationVersion;
                } else {
                    defaultVersion = jarManifest.getMainAttributes().getValue("Implementation-Version");
                }
            }
            String exportPackageHeaderValue = jarManifest.getMainAttributes().getValue("Export-Package");
            if (exportPackageHeaderValue != null) {
                ManifestElement[] manifestElements = new ManifestElement[0];
                try {
                    manifestElements = ManifestElement.parseHeader("Export-Package", exportPackageHeaderValue);
                } catch (BundleException e) {
                    getLog().warn("Error while parsing Export-Package header value for jar " + jarFile, e);
                }
                for (ManifestElement manifestElement : manifestElements) {
                    String[] packageNames = manifestElement.getValueComponents();
                    String version = manifestElement.getAttribute("version");
                    for (String packageName : packageNames) {
                        updateVersionLocationCounts(packageVersionCounts, jarFile.getCanonicalPath(), version,
                                version, packageName);
                    }
                }
            }
            for (Map.Entry<String, Attributes> manifestEntries : jarManifest.getEntries().entrySet()) {
                String packageName = manifestEntries.getKey().replaceAll("/", ".");
                if (packageName.endsWith(".class")) {
                    continue;
                }
                if (packageName.endsWith(".")) {
                    packageName = packageName.substring(0, packageName.length() - 1);
                }
                if (packageName.endsWith(".*")) {
                    packageName = packageName.substring(0, packageName.length() - 1);
                }
                int lastDotPos = packageName.lastIndexOf(".");
                String lastPackage = packageName;
                if (lastDotPos > -1) {
                    lastPackage = packageName.substring(lastDotPos + 1);
                }
                if (lastPackage.length() > 0 && Character.isUpperCase(lastPackage.charAt(0))) {
                    // ignore non package version
                    continue;
                }
                if (StringUtils.isEmpty(packageName) || packageName.startsWith("META-INF")
                        || packageName.startsWith("OSGI-INF") || packageName.startsWith("OSGI-OPT")
                        || packageName.startsWith("WEB-INF") || packageName.startsWith("org.osgi")) {
                    // ignore private package names
                    continue;
                }
                String packageVersion = null;
                if (manifestEntries.getValue().getValue("Specification-Version") != null) {
                    packageVersion = manifestEntries.getValue().getValue("Specification-Version");
                } else {
                    packageVersion = manifestEntries.getValue().getValue("Implementation-Version");
                }
                if (packageVersion != null) {
                    getLog().info("Found package version in " + jarFile.getName() + " MANIFEST : " + packageName
                            + " v" + packageVersion);
                    updateVersionLocationCounts(packageVersionCounts, jarFile.getCanonicalPath(),
                            packageVersion, specificationVersion, packageName);
                    // manifestVersions.put(packageName, packageVersion);
                }
            }
        }
    }
    JarEntry jarEntry = null;
    // getLog().debug("Processing file " + artifact.getFile() + "...");
    while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
        if (!jarEntry.isDirectory()) {
            String entryName = jarEntry.getName();
            String entryPackage = "";
            int lastSlash = entryName.lastIndexOf("/");
            if (lastSlash > -1) {
                entryPackage = entryName.substring(0, lastSlash);
                entryPackage = entryPackage.replaceAll("/", ".");
                if (StringUtils.isNotEmpty(entryPackage) && !entryPackage.startsWith("META-INF")
                        && !entryPackage.startsWith("OSGI-INF") && !entryPackage.startsWith("OSGI-OPT")
                        && !entryPackage.startsWith("WEB-INF") && !entryPackage.startsWith("org.osgi")) {
                    updateVersionLocationCounts(packageVersionCounts, jarFile.getCanonicalPath(),
                            defaultVersion, specificationVersion, entryPackage);
                }
            }
        }
    }
    jarInputStream.close();
}

From source file:org.botlibre.util.Utils.java

/**
 * Check if a capitalized word.// w  ww.j  av a 2 s.  c o  m
 */
public static boolean isCapitalized(String text) {
    if (text.isEmpty()) {
        return false;
    }
    boolean isCaps = Character.isUpperCase(text.charAt(0));
    if (!isCaps) {
        return false;
    }
    if (text.length() == 1) {
        return isCaps;
    }
    return !isCaps(text);
}

From source file:org.apache.axis.utils.JavaUtils.java

/**
 * Map an XML name to a Java identifier per
 * the mapping rules of JSR 101 (in version 1.0 this is
 * "Chapter 20: Appendix: Mapping of XML Names"
 * //from   ww w.j a  v  a2  s .  c  o  m
 * @param name is the xml name
 * @return the java name per JSR 101 specification
 */
public static String xmlNameToJava(String name) {
    // protect ourselves from garbage
    if (name == null || name.equals(""))
        return name;

    char[] nameArray = name.toCharArray();
    int nameLen = name.length();
    StringBuffer result = new StringBuffer(nameLen);
    boolean wordStart = false;

    // The mapping indicates to convert first character.
    int i = 0;
    while (i < nameLen && (isPunctuation(nameArray[i]) || !Character.isJavaIdentifierStart(nameArray[i]))) {
        i++;
    }
    if (i < nameLen) {
        // Decapitalization code used to be here, but we use the
        // Introspector function now after we filter out all bad chars.

        result.append(nameArray[i]);
        //wordStart = !Character.isLetter(nameArray[i]);
        wordStart = !Character.isLetter(nameArray[i]) && nameArray[i] != "_".charAt(0);
    } else {
        // The identifier cannot be mapped strictly according to
        // JSR 101
        if (Character.isJavaIdentifierPart(nameArray[0])) {
            result.append("_" + nameArray[0]);
        } else {
            // The XML identifier does not contain any characters
            // we can map to Java.  Using the length of the string
            // will make it somewhat unique.
            result.append("_" + nameArray.length);
        }
    }

    // The mapping indicates to skip over
    // all characters that are not letters or
    // digits.  The first letter/digit
    // following a skipped character is
    // upper-cased.
    for (++i; i < nameLen; ++i) {
        char c = nameArray[i];

        // if this is a bad char, skip it and remember to capitalize next
        // good character we encounter
        if (isPunctuation(c) || !Character.isJavaIdentifierPart(c)) {
            wordStart = true;
            continue;
        }
        if (wordStart && Character.isLowerCase(c)) {
            result.append(Character.toUpperCase(c));
        } else {
            result.append(c);
        }
        // If c is not a character, but is a legal Java
        // identifier character, capitalize the next character.
        // For example:  "22hi" becomes "22Hi"
        //wordStart = !Character.isLetter(c);
        wordStart = !Character.isLetter(c) && c != "_".charAt(0);
    }

    // covert back to a String
    String newName = result.toString();

    // Follow JavaBean rules, but we need to check if the first 
    // letter is uppercase first
    if (Character.isUpperCase(newName.charAt(0)))
        newName = Introspector.decapitalize(newName);

    // check for Java keywords
    if (isJavaKeyword(newName))
        newName = makeNonJavaKeyword(newName);

    return newName;
}