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:com.adaptris.core.marshaller.xstream.XStreamUtils.java

/**
* Converts a camelcase name into a lowercase hyphen separated format for output to XML. Used by the marshalling process to
* convert a java class/field name into an xml element name.
* 
* @param fieldName - Current element name to be processed.
* @return translated name//  w  w  w.ja va  2s.  co m
*/
public static String toXmlElementName(String fieldName) {
    if (fieldName == null) {
        return null;
    }
    if (fieldName.length() == 0) {
        return fieldName;
    }
    if (fieldName.length() == 1) {
        return fieldName.toLowerCase();
    }

    // -- Follow the Java beans Introspector::decapitalize
    // -- convention by leaving alone String that start with
    // -- 2 uppercase characters.
    if (Character.isUpperCase(fieldName.charAt(0)) && Character.isUpperCase(fieldName.charAt(1))) {
        return fieldName;
    }

    // -- process each character
    StringBuilder cbuff = new StringBuilder(fieldName);
    cbuff.setCharAt(0, Character.toLowerCase(cbuff.charAt(0)));

    boolean ucPrev = false;
    for (int i = 1; i < cbuff.length(); i++) {
        char ch = cbuff.charAt(i);
        if (Character.isUpperCase(ch)) {
            if (ucPrev) {
                continue;
            }
            ucPrev = true;
            cbuff.insert(i, '-');
            ++i;
            cbuff.setCharAt(i, Character.toLowerCase(ch));
        } else {
            ucPrev = false;
        }
    }
    return cbuff.toString();
}

From source file:com.mawujun.utils.string.StringUtils.java

/**
 * ?/* w w  w.  ja v  a 2 s. co  m*/
 * @author mawujun email:160649888@163.com qq:16064988
 * @param param
 * @return
 */
public static String camelToUnderline(String param) {
    if (param == null || "".equals(param.trim())) {
        return "";
    }
    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(UNDERLINE);
            sb.append(Character.toLowerCase(c));
        } else {
            sb.append(c);
        }
    }
    return sb.toString();
}

From source file:org.amplafi.flow.FlowUtils.java

public String toLowerCase(String flowName) {
    StringBuilder sb = new StringBuilder();
    if (isNotBlank(flowName)) {
        for (int i = 0; i < flowName.length(); i++) {
            if (Character.isUpperCase(flowName.charAt(i))) {
                if (i > 0) {
                    sb.append('-');
                }/*from   w w w  . ja va  2  s .c om*/
                sb.append(Character.toLowerCase(flowName.charAt(i)));
            } else {
                sb.append(flowName.charAt(i));
            }
        }
    }
    return sb.toString();
}

From source file:org.mayocat.localization.internal.DefaultEntityLocalizationService.java

@Override
public <T extends Localized> T localize(T entity, Locale locale) {
    if (locale == null || entity.getLocalizedVersions() == null
            || !entity.getLocalizedVersions().containsKey(locale)) {
        return entity;
    }//from   www  .j  av a  2  s.  co m

    T copiedEntity = SerializationUtils.clone(entity);

    if (copiedEntity == null) {
        return entity;
    }

    // Special I/O case for loaded attachment : set back the input stream manually
    if (copiedEntity instanceof LoadedAttachment) {
        ((LoadedAttachment) copiedEntity)
                .setData(new AttachmentData(((LoadedAttachment) entity).getData().getStream()));
    }

    // Handle entity fields :
    // - loops over methods, checking for setters, then for each one of them
    // - infer a field name from found setter
    // - check if that field has a "LocalizedField" annotation, if not ignore
    // - if it does, try to find this field in the locale's map of translations
    // - if found and not null or empty string use the setter to set this as the localized field value

    for (Method method : copiedEntity.getClass().getDeclaredMethods()) {
        if (method.getName().startsWith("set") && Character.isUpperCase(method.getName().charAt(3))) {
            // Found a setter.
            if (method.getName().length() <= 4) {
                continue;
            }
            String fieldName = method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4);

            Field field = null;
            try {
                field = copiedEntity.getClass().getDeclaredField(fieldName);
            } catch (NoSuchFieldException e) {
                this.logger.debug("Cannot find field for setter {}", method.getName());
            }

            // Check if either field or method has a "LocalizedField" annotation
            if (field != null && (field.isAnnotationPresent(LocalizedField.class)
                    || method.isAnnotationPresent(LocalizedField.class))) {
                Object value = null;
                if (copiedEntity.getLocalizedVersions().get(locale).containsKey(fieldName)) {

                    value = copiedEntity.getLocalizedVersions().get(locale).get(fieldName);

                    if (String.class.isAssignableFrom(value.getClass())
                            && Strings.isNullOrEmpty((String) value)) {
                        // Ignore empty strings, consider them as nulls
                        continue;
                    }

                    boolean setterAccessible = method.isAccessible();
                    method.setAccessible(true);
                    try {
                        method.invoke(copiedEntity, value);
                    } catch (IllegalAccessException | InvocationTargetException e) {
                        logger.error("Cannot set property {}", field.getName());
                    }

                    method.setAccessible(setterAccessible);
                }
            }
        }
    }

    // Handle entity addons :
    // - check if entity has addons and those addons are loaded, and the localized version contains something
    // for addons
    // - if yes, then loop over all the entity addons, and for each :
    // - try to find the equivalent addon in the map of translation
    // - if found, and its value is not null or empty string, replace the addon value by the localized one

    if (hasLoadedAddons(copiedEntity)
            && copiedEntity.getLocalizedVersions().get(locale).containsKey("addons")) {
        Map<String, AddonGroup> entityAddons = ((HasAddons) copiedEntity).getAddons().get();
        final Map<String, Object> localizedAddons = (Map<String, Object>) copiedEntity.getLocalizedVersions()
                .get(locale).get("addons");

        for (AddonGroup addon : entityAddons.values()) {
            if (localizedAddons.containsKey(addon.getGroup())) {
                Map<String, Object> localizedGroup = (Map<String, Object>) localizedAddons
                        .get(addon.getGroup());

                if (Map.class.isAssignableFrom(addon.getValue().getClass())) {

                    // Non-sequence addons

                    Map<String, Object> value = (Map<String, Object>) addon.getValue();
                    Map<String, Object> localizedGroupValue = (Map<String, Object>) localizedGroup.get("value");

                    for (String field : value.keySet()) {
                        Object localizedValue = localizedGroupValue.get(field);

                        if (localizedValue == null || (String.class.isAssignableFrom(localizedValue.getClass())
                                && Strings.isNullOrEmpty((String) localizedValue))) {
                            // Ignore empty strings, consider them as nulls
                            continue;
                        }

                        ((Map<String, Object>) addon.getValue()).put(field, localizedValue);
                    }
                } else if (List.class.isAssignableFrom(addon.getValue().getClass())) {

                    // Sequence addons

                    List<Map<String, Object>> values = (List<Map<String, Object>>) addon.getValue();
                    try {
                        List<Map<String, Object>> localizedGroupValue = (List<Map<String, Object>>) localizedGroup
                                .get("value");
                        Integer i = 0;
                        for (Map<String, Object> value : values) {
                            Map<String, Object> localizedGroupValueItem = localizedGroupValue.get(i);

                            for (String field : value.keySet()) {
                                Object localizedValue = localizedGroupValueItem.get(field);

                                if (localizedValue == null
                                        || (String.class.isAssignableFrom(localizedValue.getClass())
                                                && Strings.isNullOrEmpty((String) localizedValue))) {
                                    // Ignore empty strings, consider them as nulls
                                    continue;
                                }

                                ((List<Map<String, Object>>) addon.getValue()).get(i).put(field,
                                        localizedValue);
                            }
                            i++;
                        }
                    } catch (ClassCastException e) {
                        // Ignore...
                    }
                }
            }
        }
    }

    return copiedEntity;
}

From source file:org.apache.struts2.convention.SEOActionNameBuilder.java

public String build(String className) {
    String actionName = className;

    if (actionName.equals(actionSuffix))
        throw new IllegalStateException(
                "The action name cannot be the same as the action suffix [" + actionSuffix + "]");

    // Truncate Action suffix if found
    if (actionName.endsWith(actionSuffix)) {
        actionName = actionName.substring(0, actionName.length() - actionSuffix.length());
    }/*from   w  w w. jav  a  2s  .c  o  m*/

    // Convert to underscores
    char[] ca = actionName.toCharArray();
    StringBuilder build = new StringBuilder("" + ca[0]);
    boolean lower = true;
    for (int i = 1; i < ca.length; i++) {
        char c = ca[i];
        if (Character.isUpperCase(c) && lower) {
            build.append(separator);
            lower = false;
        } else if (!Character.isUpperCase(c)) {
            lower = true;
        }

        build.append(c);
    }

    actionName = build.toString();
    if (lowerCase) {
        actionName = actionName.toLowerCase();
    }

    if (LOG.isTraceEnabled()) {
        LOG.trace("Changed action name from [#0] to [#1]", className, actionName);
    }

    return actionName;
}

From source file:org.diorite.config.impl.actions.AbstractPropertyAction.java

@Override
public ActionMatcherResult matchesAction(Method method) {
    MethodInvoker methodInvoker = new MethodInvoker(method);
    if (methodInvoker.isStatic() || methodInvoker.isNative()) {
        return FAIL;
    }//from   w  w  w . j a v a2s.c o m
    for (Pattern pattern : this.patterns) {
        Matcher matcher = pattern.matcher(method.getName());
        if (matcher.matches() && (matcher.groupCount() > 0)) {
            String property = matcher.group("property");
            if ((property == null) || property.isEmpty()) {
                return FAIL;
            }
            char firstChar = property.charAt(0);
            if (Character.isUpperCase(firstChar)) {
                property = Character.toLowerCase(firstChar) + property.substring(1);
            }
            return new ActionMatcherResult(
                    this.matchesAction0(methodInvoker, methodInvoker.getParameterTypes()), property);
        }
    }
    return FAIL;
}

From source file:eu.annocultor.converters.europeana.EuropeanaLabelExtractor.java

boolean precheckisDfgCoverage(String label) {
    return label.length() > 3 && Character.isUpperCase(label.charAt(0))
            && Character.isUpperCase(label.charAt(1));
}

From source file:org.romaframework.core.Utility.java

public static String getClearName(String iJavaName) {
    StringBuilder buffer = new StringBuilder();

    char c;/*from   ww  w .ja va  2s  .  co m*/
    if (iJavaName != null) {
        buffer.append(Character.toUpperCase(iJavaName.charAt(0)));
        for (int i = 1; i < iJavaName.length(); ++i) {
            c = iJavaName.charAt(i);

            if (Character.isUpperCase(c)) {
                buffer.append(' ');
            }

            buffer.append(c);
        }

    }
    return buffer.toString();
}

From source file:annis.dao.autogenqueries.AutoSimpleRegexQuery.java

@Override
public void analyzingQuery(SaltProject saltProject) {

    List<String> tokens = new ArrayList<>();
    for (SCorpusGraph g : saltProject.getSCorpusGraphs()) {
        if (g != null) {
            for (SDocument doc : g.getSDocuments()) {
                SDocumentGraph docGraph = doc.getSDocumentGraph();
                EList<SNode> sNodes = docGraph.getSNodes();

                if (sNodes != null) {
                    for (SNode n : sNodes) {
                        if (n instanceof SToken) {
                            tokens.add(CommonHelper.getSpannedText((SToken) n));
                        }/*from   w w w.j  a v a 2 s  .c o m*/
                    }
                }
            }
        }
    }

    // try to find a word with which is contained twice with Capitalize letter.
    text = null;
    for (int i = 0; i < tokens.size(); i++) {
        for (int j = i + 1; j < tokens.size(); j++) {
            if (tokens.get(i).equalsIgnoreCase(tokens.get(j))) {

                if (tokens.get(i).length() > 1 && ((Character.isLowerCase(tokens.get(i).charAt(0))
                        && Character.isUpperCase(tokens.get(j).charAt(0)))
                        || (Character.isLowerCase(tokens.get(j).charAt(0))
                                && Character.isUpperCase(tokens.get(i).charAt(0))))) {
                    text = tokens.get(i);
                    break;
                }
            }
        }
    }

    if (text != null) {
        Character upperLetter = Character.toUpperCase(text.charAt(0));
        Character lowerLetter = Character.toLowerCase(text.charAt(0));
        String rest = StringUtils.substring(text, -(text.length() - 1));

        finalAQL = "/[" + upperLetter + lowerLetter + "]" + rest + "/";
    } else {
        // select one random token from the result
        int tries = 10;
        int r = new Random().nextInt(tokens.size() - 1);
        text = tokens.get(r);
        while ("".equals(text) && tries > 0) {
            r = new Random().nextInt(tokens.size() - 1);
            text = tokens.get(r);
            tries--;
        }

        if (!"".equals(text) && text.length() > 1) {
            Character upperLetter = Character.toUpperCase(text.charAt(0));
            Character lowerLetter = Character.toLowerCase(text.charAt(0));
            String rest = StringUtils.substring(text, -(text.length() - 1));

            finalAQL = "/[" + upperLetter + lowerLetter + "]" + rest + "/";
        } else {
            finalAQL = "";
        }
    }
}

From source file:io.github.mywarp.mywarp.bukkit.util.versionsupport.MinecraftLocaleParser.java

/**
 * Converts a String to a Locale./*w w w .  j  a  v a2 s.  c  o m*/
 *
 * <p>This method takes the string format of a locale and creates the locale object from it.</p>
 *
 * <pre>
 *   toLocaleCaseInsensitive("")           = new Locale("", "")
 *   toLocaleCaseInsensitive("en")         = new Locale("en", "")
 *   toLocaleCaseInsensitive("en_GB")      = new Locale("en", "GB")
 *   toLocaleCaseInsensitive("en_GB_xxx")  = new Locale("en", "GB", "xyz")   (#)
 * </pre>
 *
 * <p>(#) The behaviour of the JDK variant constructor changed between JDK1.3 and JDK1.4. In JDK1.3, the constructor
 * upper cases the variant, in JDK1.4, it doesn't. Thus, the result from getVariant() may vary depending on your
 * JDK.</p>
 *
 * <p>This method validates the input: The length must be correct. The separator must be an underscore. </p>
 *
 * <p>It does <b>not</b> validate whether language and country code are lower or uppercase.</p>
 *
 * @param str the locale String to convert
 * @return a Locale
 * @throws IllegalArgumentException if the string is an invalid format
 * @see Locale#forLanguageTag(String)
 */
//Note: this implementation is adapted from Apache Commons 2.6
private static Locale toLocaleCaseInsensitive(final String str) {
    checkNotNull(str);

    if (str.isEmpty()) { //JDK 8 introduced an empty locale where all fields are blank which we do not support
        throw new IllegalArgumentException("Invalid locale format: " + str);
    }
    if (str.contains("#")) { //Cannot handle Java 7 script & extensions
        throw new IllegalArgumentException("Invalid locale format: " + str);
    }
    final int len = str.length();
    if (len < 2) {
        throw new IllegalArgumentException("Invalid locale format: " + str);
    }

    //String starting with '_'
    final char ch0 = str.charAt(0);
    if (ch0 == '_') {
        if (len < 3) {
            throw new IllegalArgumentException("Invalid locale format: " + str);
        }
        final char ch1 = str.charAt(1);
        final char ch2 = str.charAt(2);
        if (!Character.isUpperCase(ch1) || !Character.isUpperCase(ch2)) {
            throw new IllegalArgumentException("Invalid locale format: " + str);
        }
        if (len == 3) {
            return new Locale(StringUtils.EMPTY, str.substring(1, 3));
        }
        if (len < 5) {
            throw new IllegalArgumentException("Invalid locale format: " + str);
        }
        if (str.charAt(3) != '_') {
            throw new IllegalArgumentException("Invalid locale format: " + str);
        }
        return new Locale(StringUtils.EMPTY, str.substring(1, 3), str.substring(4));
    }

    //String string with characters, e.g. 'en_US'
    final String[] split = str.split("_", -1);
    final int occurrences = split.length - 1;
    switch (occurrences) {
    case 0:
        if ((len == 2 || len == 3)) {
            return new Locale(str);
        }
        throw new IllegalArgumentException("Invalid locale format: " + str);

    case 1:
        if ((split[0].length() == 2 || split[0].length() == 3) && split[1].length() == 2) {
            return new Locale(split[0], split[1]);
        }
        throw new IllegalArgumentException("Invalid locale format: " + str);

    case 2:
        if ((split[0].length() == 2 || split[0].length() == 3)
                && (split[1].length() == 0 || split[1].length() == 2) && split[2].length() > 0) {
            return new Locale(split[0], split[1], split[2]);
        }

        //fallthrough
    default:
        throw new IllegalArgumentException("Invalid locale format: " + str);
    }
}