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:br.msf.commons.util.CharSequenceUtils.java

public static int countUppercaseChain(final CharSequence sequence) {
    if (isBlankOrNull(sequence)) {
        return 0;
    } else if (length(sequence) == 1) {
        return hasUppercase(sequence) ? 1 : 0;
    }/*from  w  w  w.ja  v a 2 s.  c o  m*/
    int max = 0;
    int count = 0;
    for (int i = 0; i < sequence.length(); i++) {
        if (Character.isUpperCase(sequence.charAt(i))) {
            count++;
        } else {
            if (count > max) {
                max = count;
            }
            count = 0;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}

From source file:org.rdkit.knime.wizards.RDKitNodesWizardsPage.java

/**
 * Generates a friendly and easily readable name based on the passed in name.
 * Replaces for instance underscores with spaces, corrects lower and upper
 * cases when necessary.//  www  . j a va 2s . c om
 *
 * @param name A name of something. Can be null.
 *
 * @return A friendly name. Is empty when null was passed in.
 */
public static String generateFriendlyName(final String name) {
    String workName = "";

    if (name != null) {
        workName = name.trim();

        // Don't touch, if length is <= 2 (usually a variable like x, y, z)
        if (workName.length() > 2) {
            workName = workName.replaceAll("_", " ");
            workName = workName.replaceAll("\\s", " ");

            final StringBuilder sbFriendlyName = new StringBuilder();

            int iCountUpperCase = 0;
            boolean bWasSpace = false;
            char[] chars = workName.toCharArray();
            chars[0] = Character.toUpperCase(chars[0]);

            for (char c : chars) {
                final boolean bIsUpperCase = Character.isUpperCase(c);
                final boolean bIsLowerCase = Character.isLowerCase(c);

                if (bIsUpperCase && iCountUpperCase == 0) {
                    sbFriendlyName.append(" ");
                }

                if (bIsLowerCase && iCountUpperCase > 1) {
                    sbFriendlyName.insert(sbFriendlyName.length() - 1, " ");
                }

                if (bWasSpace) {
                    c = Character.toUpperCase(c);
                }

                sbFriendlyName.append(c);

                if (bIsUpperCase) {
                    iCountUpperCase++;
                } else {
                    iCountUpperCase = 0;
                }

                bWasSpace = (c == ' ');
            }

            workName = sbFriendlyName.toString().trim();

            // If more than one whitespace was added in the middle, reduce
            // multiple to single space
            workName = workName.trim().replaceAll("\\s+", " ");
        }
    }

    return workName;
}

From source file:co.id.app.sys.util.StringUtils.java

public static String splitByUpperCase(String name, boolean isUpperCase) {
    StringBuilder builder = new StringBuilder();
    boolean lastUpperCase = true;
    for (int i = 0, size = name.length(); i < size; i++) {
        char ch = name.charAt(i);
        if (Character.isUpperCase(ch)) {
            if (!lastUpperCase) {
                builder.append('_');
            }/*from  ww w.  j  a v  a  2  s  .com*/
        }
        builder.append(ch);
        lastUpperCase = Character.isUpperCase(ch);
    }
    if (isUpperCase) {
        return builder.toString().toUpperCase();
    }
    return builder.toString().toLowerCase();
}

From source file:de.innovationgate.webgate.api.jdbc.WGDatabaseImpl.java

protected String buildHqlContentOrderClause(String contentExpression, WGColumnSet order,
        Map<String, Object> params) throws WGAPIException {

    List<String> hqlTerms = new ArrayList<String>();
    WGDocumentImpl langDoc = null;//  w w  w  .java2 s  .com

    int itemNameIdx = 0;
    for (WGColumnSet.Term term : order.getTerms()) {

        String clause = null;

        if (Character.isUpperCase(term.getName().charAt(0))) {

            StringBuffer clauseTerm = new StringBuffer();

            WGColumnSet.ColumnMeta columnMeta = WGColumnSet.COLUMN_METAS.get(term.getName());
            if (columnMeta == null) {
                throw new WGIllegalArgumentException("Unknown column meta name: " + term.getName());
            }
            for (Class<? extends WGDocument> loc : columnMeta.getLocations()) {
                if (loc == WGStructEntry.class) {
                    clauseTerm.append(contentExpression).append(".structentry");
                } else if (loc == WGContent.class) {
                    clauseTerm.append(contentExpression);
                } else if (loc == WGContentType.class) {
                    clauseTerm.append(contentExpression).append(".structentry.contenttype");
                } else if (loc == WGLanguage.class) {
                    clauseTerm.append(contentExpression).append(".language");
                } else {
                    continue;
                }

                clauseTerm.append(".").append(columnMeta.getMetaName().toLowerCase());

                // Metas with special data structures
                if (loc == WGStructEntry.class && term.getName().equals(WGStructEntry.META_PUBLISHED)) {
                    clauseTerm.append("[content.language.name]");
                }

                clause = clauseTerm.toString();
                break;

            }

        } else {
            itemNameIdx++;
            params.put("itemname" + itemNameIdx, term.getName());
            String property = term.getFlags().containsKey("type") ? term.getFlags().get("type") : "text";
            clause = contentExpression + ".items[:itemname" + itemNameIdx + "]." + property;

        }

        if (clause != null) {
            if ("true".equals(term.getFlags().get("ci"))) {
                clause = "lower(" + clause + ")";
            }
            if ("true".equals(term.getFlags().get("desc"))) {
                clause += " desc";
            } else {
                clause += " asc";
            }
            hqlTerms.add(clause);
        }

    }
    return WGUtils.serializeCollection(hqlTerms, ", ");

}

From source file:org.andromda.cartridges.gui.GuiUtils.java

/**
 * Returns <code>true</code> if the argument name will not cause any troubles with the Jakarta commons-beanutils
 * library, which basically means it does not start with an lowercase characters followed by an uppercase character.
 * This means there's a bug in that specific library that causes an incompatibility with the Java Beans
 * specification as implemented in the JDK.
 * /*from   ww  w  . j a  v  a  2s.  c  om*/
 * @param name the name to test, may be <code>null</code>
 * @return <code>true</code> if the name is safe to use with the Jakarta libraries, <code>false</code> otherwise
 */
public static boolean isSafeName(final String name) {

    boolean safe = true;

    if ((name != null) && (name.length() > 1)) {

        safe = !(Character.isLowerCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1)));

    }

    return safe;

}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Find a new rolename which lets the new {@link Schema} still be
 * consistent./*from w ww. j ava2s  . co  m*/
 * 
 * @param connectedVertexClass
 *            {@link VertexClass} for which the new rolename should be
 *            created
 * @return String the new rolename
 */
private String createNewUniqueRoleName(VertexClass connectedVertexClass) {
    String baseRolename = connectedVertexClass.get_qualifiedName().replaceAll(Pattern.quote("."), "_");
    // ensure that the rolename starts with an lower case letter
    if (Character.isUpperCase(baseRolename.charAt(0))) {
        baseRolename = Character.toLowerCase(baseRolename.charAt(0)) + baseRolename.substring(1);
    }

    // find a unique rolename
    HashMap<String, Object> boundVars = new HashMap<>();
    boundVars.put("start", connectedVertexClass);
    int counter = 0;
    Object result;
    do {
        counter++;
        GreqlQuery query = GreqlQuery.createQuery("using start:"
                + "exists ic:start<->{structure.SpecializesVertexClass}*<->{structure.EndsAt}<->{structure.ComesFrom,structure.GoesTo}^2@ic.roleName=\""
                + baseRolename + (counter == 1 ? "" : counter) + "\"");
        GreqlEnvironment environment = new GreqlEnvironmentAdapter(boundVars);
        result = query.evaluate(connectedVertexClass.getGraph(), environment);
    } while (result instanceof Boolean ? (Boolean) result : false);

    return baseRolename + (counter == 1 ? "" : counter);
}

From source file:StringUtil.java

private static String cutLastWord(String string, boolean preserveFirst) {
    int ndx = string.length() - 1;
    while (ndx >= 0) {
        if (Character.isUpperCase(string.charAt(ndx)) == true) {
            break;
        }/*ww  w . java  2s.  c o  m*/
        ndx--;
    }
    if (ndx >= 0) {
        if ((ndx == 0) && (preserveFirst == true)) {
            return string;
        }
        string = string.substring(0, ndx);
    }
    return string;
}

From source file:mondrian.olap.Util.java

/**
 * Converts a camel-case name to an upper-case name with underscores.
 *
 * <p>For example, <code>camelToUpper("FooBar")</code> returns "FOO_BAR".
 *
 * @param s Camel-case string//w  w  w  .j  a  v  a 2  s.co m
 * @return  Upper-case string
 */
public static String camelToUpper(String s) {
    StringBuilder buf = new StringBuilder(s.length() + 10);
    int prevUpper = -1;
    for (int i = 0; i < s.length(); ++i) {
        char c = s.charAt(i);
        if (Character.isUpperCase(c)) {
            if (i > prevUpper + 1) {
                buf.append('_');
            }
            prevUpper = i;
        } else {
            c = Character.toUpperCase(c);
        }
        buf.append(c);
    }
    return buf.toString();
}

From source file:lineage2.gameserver.handler.admincommands.impl.AdminEditChar.java

/**
 * Method formatClassForDisplay./*from   ww  w . ja v  a  2s  . c  o  m*/
 * @param className ClassId
 * @return String
 */
private String formatClassForDisplay(ClassId className) {
    String classNameStr = className.toString();
    char[] charArray = classNameStr.toCharArray();
    for (int i = 1; i < charArray.length; i++) {
        if (Character.isUpperCase(charArray[i])) {
            classNameStr = classNameStr.substring(0, i) + " " + classNameStr.substring(i);
        }
    }
    return classNameStr;
}

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

/**
 * _more_//from  ww  w  .j  av  a2  s .c om
 *
 * @param label _more_
 *
 * @return _more_
 */
public static String makeLabel(String label) {
    label = label.replaceAll("_", " ");
    StringBuilder tmpSB = new StringBuilder();
    StringBuilder sb = new StringBuilder();
    boolean lastCharUpperCase = false;
    for (int i = 0; i < label.length(); i++) {
        char c = label.charAt(i);
        boolean isUpperCase = Character.isUpperCase(c);
        if (i > 0) {
            if (isUpperCase) {
                if (!lastCharUpperCase) {
                    sb.append(" ");
                }
            }
        }
        lastCharUpperCase = isUpperCase;
        sb.append(c);
    }

    label = sb.toString();
    label = label.replaceAll("__+", "_");

    for (String tok : StringUtil.split(label, " ", true, true)) {
        tok = tok.substring(0, 1).toUpperCase() + tok.substring(1, tok.length()).toLowerCase();
        tmpSB.append(tok);
        tmpSB.append(" ");
    }
    label = tmpSB.toString().trim();

    return label;

}