Example usage for java.lang Character isLowerCase

List of usage examples for java.lang Character isLowerCase

Introduction

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

Prototype

public static boolean isLowerCase(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a lowercase character.

Usage

From source file:org.lockss.util.UrlUtil.java

public static String normalizeUrlEncodingCase(String str) {
    if (!normalizeUrlEncodingCase) {
        return str;
    }//from   ww w  .  j  a  v a2 s . c  om
    int pos = str.indexOf('%');
    if (pos < 0) {
        return str;
    }
    StringBuffer sb = new StringBuffer(str);
    int len = str.length();
    do {
        if (len < pos + 3) {
            break;
        }
        char ch;
        if (Character.isLowerCase(ch = sb.charAt(pos + 1))) {
            sb.setCharAt(pos + 1, Character.toUpperCase(ch));
        }
        if (Character.isLowerCase(ch = sb.charAt(pos + 2))) {
            sb.setCharAt(pos + 2, Character.toUpperCase(ch));
        }
    } while ((pos = str.indexOf('%', pos + 3)) >= 0);
    return sb.toString();
}

From source file:eu.delving.sip.xml.SourceConverter.java

private String anonymizeString(String string) {
    if (moreNumbersThanLetters(string))
        return string;
    StringBuilder out = new StringBuilder(string.length());
    Random random = new Random(string.hashCode());
    for (char c : string.toCharArray()) {
        if (Character.isLowerCase(c)) {
            out.append((char) ('a' + (Math.abs(random.nextInt()) % 26)));
        } else if (Character.isUpperCase(c)) {
            out.append((char) ('A' + (Math.abs(random.nextInt()) % 26)));
        } else {/*from  ww w.ja v  a2 s  . co  m*/
            out.append(c);
        }
    }
    return out.toString();
}

From source file:com.netspective.commons.text.TextUtils.java

/**
 * Given a method name, return a string that would be suitable for that string to be used
 * as a xml node name. Basically, what this does is allows something like setAbcDef() to
 * match both "abcDef" and "abc-def" as node names in XML. It turns a java identifier into
 * a reasonable xml node name.//  ww  w.  j a  v  a 2 s. c o  m
 */
public String javaIdentifierToXmlNodeName(final String javaIdentifier) {
    if (javaIdentifier == null || javaIdentifier.length() == 0)
        return javaIdentifier;

    StringBuffer nodeName = new StringBuffer();
    nodeName.append(javaIdentifier.charAt(0));
    for (int i = 1; i < javaIdentifier.length(); i++) {
        //TODO: Might be a good idea to replace _ with - and to lower the case of any uppercase letters
        char ch = javaIdentifier.charAt(i);
        if (Character.isLowerCase(ch))
            nodeName.append(ch);
        else {
            nodeName.append('-');
            nodeName.append(ch);
        }
    }

    return nodeName.toString();
}

From source file:de.homelab.madgaksha.lotsofbs.util.LocaleRootWordUtils.java

/**
 * <p>//from   ww w. j ava2  s.  com
 * Swaps the case of a String using a word based algorithm.
 * </p>
 * 
 * <ul>
 * <li>Upper case character converts to Lower case</li>
 * <li>Title case character converts to Lower case</li>
 * <li>Lower case character after Whitespace or at start converts to Title
 * case</li>
 * <li>Other Lower case character converts to Upper case</li>
 * </ul>
 * 
 * <p>
 * Whitespace is defined by {@link Character#isWhitespace(char)}. A
 * <code>null</code> input String returns <code>null</code>.
 * </p>
 * 
 * <pre>
 * StringUtils.swapCase(null)                 = null
 * StringUtils.swapCase("")                   = ""
 * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
 * </pre>
 * 
 * @param str
 *            the String to swap case, may be null
 * @return the changed String, <code>null</code> if null String input
 */
public static String swapCase(final String str) {
    if (StringUtils.isEmpty(str)) {
        return str;
    }
    final char[] buffer = str.toCharArray();

    boolean whitespace = true;

    for (int i = 0; i < buffer.length; i++) {
        final char ch = buffer[i];
        if (Character.isUpperCase(ch)) {
            buffer[i] = Character.toLowerCase(ch);
            whitespace = false;
        } else if (Character.isTitleCase(ch)) {
            buffer[i] = Character.toLowerCase(ch);
            whitespace = false;
        } else if (Character.isLowerCase(ch)) {
            if (whitespace) {
                buffer[i] = Character.toTitleCase(ch);
                whitespace = false;
            } else {
                buffer[i] = Character.toUpperCase(ch);
            }
        } else {
            whitespace = Character.isWhitespace(ch);
        }
    }
    return new String(buffer);
}

From source file:org.apache.wiki.util.TextUtil.java

private static int getCharKind(int c) {
    if (c == -1) {
        return EOI;
    }// www .j a v  a2  s  .c o m

    char ch = (char) c;

    if (Character.isLowerCase(ch)) {
        return LOWER;
    } else if (Character.isUpperCase(ch)) {
        return UPPER;
    } else if (Character.isDigit(ch)) {
        return DIGIT;
    } else {
        return OTHER;
    }
}

From source file:padl.creator.javafile.eclipse.util.PadlParserUtil.java

/**
 * Get or create a ghost entity//from  w  ww  . j a v  a2 s .c  o m
 * 
 * @param isDealingWithExtend
 * @param anEntityTypeBinding
 * @param aPadlModel
 * @param aCurrentPackagePath
 * @return
 */
private static IFirstClassEntity getOrCreateGhostEntity(final boolean isDealingWithExtend,
        final ITypeBinding anEntityTypeBinding, final ICodeLevelModel aPadlModel,
        final String aCurrentPackagePath) {

    final StringBuffer tmpStringBuffer = new StringBuffer();
    String ghostName = null;
    String ghostPackagePath = null;
    String fullyQualifiedName = null;
    final String entityBindingKey = anEntityTypeBinding.getKey();
    final String prefix = "Recovered#currentType";

    if (entityBindingKey.startsWith(prefix)) {
        // ghosts in existing entities
        tmpStringBuffer.append(entityBindingKey.substring(prefix.length()));
        tmpStringBuffer.deleteCharAt(tmpStringBuffer.length() - 1);

        // Yann 2015/03/16: Symbols collision with IConstants!
        // I make sure that the name of the entity does not contain
        // any symbol used in the models, see IConstants, because
        // the entityBindingKey will be of the form:
        //   org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor<List<U>>0<Ljava/util/List<Lorg/hibernate/envers/entities/mapper/relation/lazy/proxy/C:\Data\Java Programs\hibernate-orm-3.6.4.Final\hibernate-envers\src\main\java\org\hibernate\envers\entities\mapper\relation\lazy\proxy\ListProxy~ListProxy;:TU;>;>
        if (entityBindingKey.indexOf('/') > -1 || entityBindingKey.indexOf('\\') > -1) {

            ghostName = tmpStringBuffer.substring(0, tmpStringBuffer.indexOf("0"));
        } else {
            ghostName = tmpStringBuffer.toString();
        }
        ghostPackagePath = anEntityTypeBinding.getPackage().getName();
    } else if (isDealingWithExtend && entityBindingKey.startsWith("Recovered#typeBinding")) {

        ghostName = anEntityTypeBinding.getQualifiedName();
        ghostPackagePath = anEntityTypeBinding.getPackage().getName();
    } else {
        // Pure ghosts
        // Fix for eclipse_12-15-2009 (fixed) case of generic types
        // (templates) (fixed)
        final String[] packageComponents;
        if (anEntityTypeBinding.getPackage() == null) {// case of templates
            packageComponents = new String[0];
            // should be deleted (only for debug purpose)
            /*
             * Output .getInstance() .normalOutput() .println(
             * "PadlParserUtil in getOrCreateGhostEntity anEntityTypeBinding.getPackage() == null "
             * + anEntityTypeBinding .getQualifiedName());
             */
        } else {
            packageComponents = anEntityTypeBinding.getPackage().getNameComponents();
        }

        final int numberOfNames = packageComponents.length;

        char firstLetter;
        int i = 0;
        boolean checkPackage = true;

        if (numberOfNames > 0) {
            firstLetter = packageComponents[0].toCharArray()[0];
            if (Character.isLowerCase(firstLetter)) {
                tmpStringBuffer.append(packageComponents[0]);
                i++;
            } else {
                checkPackage = false;
            }

            while (i < numberOfNames && checkPackage) {
                firstLetter = packageComponents[i].toCharArray()[0];
                if (Character.isLowerCase(firstLetter)) {
                    tmpStringBuffer.append('.');
                    tmpStringBuffer.append(packageComponents[i]);
                    i++;
                } else {
                    checkPackage = false;
                }
            }
        }

        ghostPackagePath = tmpStringBuffer.toString();
        // why? aCurrentPackagePath=display path, is it more than the
        // package???
        String packagePath = aCurrentPackagePath;
        if (aCurrentPackagePath.length() > 2) {
            /*
             * Output .getInstance() .normalOutput() .println(
             * "PadlParserUtil in getOrCreateGhostEntity aCurrentPackagePath.length() > 2 "
             * + aCurrentPackagePath.length());
             */
            packagePath = aCurrentPackagePath.substring(aCurrentPackagePath.indexOf('|') + 1).replace("|", ".");
        }

        // if package ghost is the same with the current package and this
        // ghost is not from source
        // this means generally that there is a probleme of resolving so we
        // put this ghost in a specific package
        // also when this ghost is a generic type, we do the same
        // These conditions are not always true but permit to handle a lot
        // of cases
        if ((ghostPackagePath.equals(packagePath) || ghostPackagePath.length() == 0
                && ArrayUtils.isEquals(packagePath.toCharArray(), Constants.DEFAULT_PACKAGE_ID))
                && !anEntityTypeBinding.isFromSource()
                || ghostPackagePath.length() == 0 && anEntityTypeBinding.isFromSource()
                        && anEntityTypeBinding.isTypeVariable()) {
            ghostPackagePath = "unknown.ghost.packag";
        }

        tmpStringBuffer.setLength(0);

        while (i < numberOfNames) {
            tmpStringBuffer.append(packageComponents[i]);
            tmpStringBuffer.append('.');

            i++;
        }

        tmpStringBuffer.append(anEntityTypeBinding.getName());
        ghostName = tmpStringBuffer.toString();

    }

    tmpStringBuffer.setLength(0);
    tmpStringBuffer.append(ghostPackagePath);
    if (tmpStringBuffer.length() != 0) {
        tmpStringBuffer.append('.');
    }
    tmpStringBuffer.append(ghostName);
    fullyQualifiedName = tmpStringBuffer.toString();

    final int indexOfDot = ghostName.lastIndexOf('.');

    if (indexOfDot < 0) {
        // Case of a ghost
        IFirstClassEntity ghost = aPadlModel.getTopLevelEntityFromID(fullyQualifiedName.toCharArray());
        if (ghost == null) {
            ghost = PadlParserUtil.createGhost(aPadlModel, fullyQualifiedName.toCharArray());
        }
        return ghost;
    } else {
        // case of a ghost member
        // get or create a ghost based on the package name and the ghostName
        final String searchedGhostID = PadlParserUtil.renameWith$(fullyQualifiedName, ghostPackagePath);

        StringTokenizer tokenizer;

        //   int nbTokens = tokenizer.countTokens(); // number of entities in the
        // hierarchy=class>memberClass1>MemberClass2

        tokenizer = new StringTokenizer(searchedGhostID, "$");

        IPackage searchedPackage = null;

        IFirstClassEntity currentEntity = null;
        final String currentEntityID = tokenizer.nextToken();

        searchedPackage = PadlParserUtil.getPackage(ghostPackagePath, aPadlModel);

        if (searchedPackage != null) {
            currentEntity = aPadlModel.getTopLevelEntityFromID(currentEntityID.toCharArray());

            if (currentEntity == null) {
                currentEntity = PadlParserUtil.createGhost(aPadlModel, currentEntityID.toCharArray());
            }
        } else {
            currentEntity = PadlParserUtil.createGhost(aPadlModel, currentEntityID.toCharArray());
        }

        // create the member entities
        IFirstClassEntity currentMemberEntity;
        String currentMemberEntityID;
        String currentMemberEntityName;

        while (tokenizer.hasMoreTokens()) {
            currentMemberEntityName = tokenizer.nextToken();
            currentMemberEntityID = currentEntity.getDisplayID() + '$' + currentMemberEntityName;

            currentMemberEntity = (IFirstClassEntity) currentEntity
                    .getConstituentFromID(currentMemberEntityID.toCharArray());

            if (currentMemberEntity == null) {
                currentMemberEntity = aPadlModel.getFactory().createMemberGhost(
                        currentMemberEntityID.toCharArray(), currentMemberEntityName.toCharArray());
                currentEntity.addConstituent((IConstituentOfEntity) currentMemberEntity);
            }
            currentEntity = currentMemberEntity;
        }
        // The last entity created or got in the padl model is which
        // is searched for
        return currentEntity;
    }
}

From source file:org.dhatim.edisax.util.EDIUtils.java

/**
 * Encodes a String into standard java class name convention. The following
 * steps are performed on the name: 1. First character is set to upper case.
 * 2. Illegal characters like '-' and whitespace are removed.
 *
 * @param name the original class name./*from   w  ww  . j  a  v  a  2  s.c o  m*/
 * @return the class name complying with standard java class name
 * convention.
 * @throws IllegalNameException when class name is a reserved keyword in
 * java.
 */
public static String encodeClassName(String name) throws IllegalNameException {
    String result = name;
    if (name.toUpperCase().equals(name)) {
        StringBuilder nameRebuilder = new StringBuilder();

        nameRebuilder.append(name.toLowerCase());
        nameRebuilder.setCharAt(0, name.charAt(0));
        result = nameRebuilder.toString();
    }

    result = deleteWithPascalNotation(result, '_');
    result = encodeJavaIdentifier(result);

    if (Character.isLowerCase(result.charAt(0))) {
        result = Character.toUpperCase(result.charAt(0)) + result.substring(1);
    }

    assertLegalName(result);

    return result;
}

From source file:eu.trentorise.opendata.josman.Josmans.java

/**
 * Returns the name displayed on the website as menu item for a given page.
 *
 * @param relPath path relative to the {@link JosmanProject#sourceRepoDir()} (i.e.
 * LICENSE.txt or docs/README.md)// w ww  . j  av  a  2 s.com
 */
public static String targetName(String relPath) {
    String htmlizedPath = htmlizePath(relPath);
    if (htmlizedPath.endsWith("/index.html")) {
        return "Usage";
    }
    if (htmlizedPath.endsWith("/CHANGES.html")) {
        return "Release notes";
    }
    String withoutFiletype = htmlizedPath.replace(".html", "");
    int lastSlash = withoutFiletype.lastIndexOf("/");
    String fileName = withoutFiletype;
    if (lastSlash != -1) {
        fileName = withoutFiletype.substring(lastSlash + 1);
    }
    StringBuilder sb = new StringBuilder();
    sb.append(Character.toUpperCase(fileName.charAt(0)));

    int i = 1;
    while (i < fileName.length()) {
        char ch = fileName.charAt(i);
        if (i + 1 < fileName.length()) {
            char nextCh = fileName.charAt(i + 1);
            if (Character.isLowerCase(ch) && Character.isUpperCase(nextCh)) {
                sb.append(ch + " ");
                i += 1;
                continue;
            } else {
                if (i + 2 < fileName.length()) {
                    char nextNextCh = fileName.charAt(i + 2);
                    if (Character.isUpperCase(ch) && Character.isUpperCase(nextCh)
                            && Character.isLowerCase(nextNextCh)) {
                        sb.append(ch);
                        sb.append(" ");
                        sb.append(Character.toLowerCase(nextCh));
                        i += 2;
                        continue;
                    } else {
                        if (Character.isUpperCase(ch) && Character.isUpperCase(nextCh)) {
                            sb.append(ch);
                            i += 1;
                            continue;
                        }
                    }
                }
            }
        }

        sb.append(Character.toLowerCase(ch));
        i += 1;
    }
    return sb.toString();
}

From source file:org.talend.dataprep.api.filter.SimpleFilterService.java

/**
 * Test a string value against a pattern returned during value analysis.
 *
 * @param value A string value. May be null.
 * @param pattern A pattern as returned in value analysis.
 * @return <code>true</code> if value matches, <code>false</code> otherwise.
 *///  w  ww.  j  av  a 2  s. c om
private boolean matches(String value, String pattern) {
    if (value == null && pattern == null) {
        return true;
    }
    if (value == null) {
        return false;
    }
    // Character based patterns
    if (StringUtils.containsAny(pattern, new char[] { 'A', 'a', '9' })) {
        if (value.length() != pattern.length()) {
            return false;
        }
        final char[] valueArray = value.toCharArray();
        final char[] patternArray = pattern.toCharArray();
        for (int i = 0; i < valueArray.length; i++) {
            if (patternArray[i] == 'A') {
                if (!Character.isUpperCase(valueArray[i])) {
                    return false;
                }
            } else if (patternArray[i] == 'a') {
                if (!Character.isLowerCase(valueArray[i])) {
                    return false;
                }
            } else if (patternArray[i] == '9') {
                if (!Character.isDigit(valueArray[i])) {
                    return false;
                }
            } else {
                if (valueArray[i] != patternArray[i]) {
                    return false;
                }
            }
        }
    } else {
        final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        try {
            formatter.toFormat().parseObject(value);
        } catch (ParseException e) {
            return false;
        }
    }
    return true;
}

From source file:org.apache.axis.wsdl.toJava.JavaGeneratorFactory.java

/** Refactored to call recursively for JAX-RPC 1.1 spec 4.2.5. */
protected int javifyTypeEntryName(SymbolTable symbolTable, TypeEntry entry, HashMap anonQNames, int uniqueNum) {
    TypeEntry tEntry = entry;/*from ww w. j ava  2s  .  c om*/
    String dims = tEntry.getDimensions();
    TypeEntry refType = tEntry.getRefType();
    while (refType != null) {
        tEntry = refType;
        dims += tEntry.getDimensions();
        refType = tEntry.getRefType();
    }

    TypeEntry te = tEntry;
    while (te != null) {
        TypeEntry base = SchemaUtils.getBaseType(te, symbolTable);
        if (base == null)
            break;

        uniqueNum = javifyTypeEntryName(symbolTable, base, anonQNames, uniqueNum);

        if (Utils.getEnumerationBaseAndValues(te.getNode(), symbolTable) == null
                && SchemaUtils.getComplexElementExtensionBase(te.getNode(), symbolTable) == null
                && te.getContainedAttributes() == null) {
            if (!SchemaUtils.isSimpleTypeWithUnion(te.getNode())) {
                if (base.isSimpleType()) {
                    // Case 1:
                    // <simpleType name="mySimpleStringType">
                    //   <restriction base="xs:string">
                    //   </restriction>
                    // </simpleType>
                    te.setSimpleType(true);
                    te.setName(base.getName());
                    te.setRefType(base);
                }

                if (base.isBaseType()) {
                    // Case 2:
                    // <simpleType name="FooString">
                    //   <restriction base="foo:mySimpleStringType">
                    //   </restriction>
                    // </simpleType>
                    te.setBaseType(true);
                    te.setName(base.getName());
                    te.setRefType(base);
                }
            }
        }

        if (!te.isSimpleType())
            break;

        te = base;
    }

    // Need to javify the ref'd TypeEntry if it was not
    // already processed
    if (tEntry.getName() == null) {
        boolean processed = false; // true if the java name is already determined
        // Get the QName of the ref'd TypeEntry, which
        // is will be used to javify the name
        QName typeQName = tEntry.getQName();

        // In case of <xsd:list itemType="...">,
        // set typeQName to the value of the itemType attribute.
        QName itemType = SchemaUtils.getListItemType(tEntry.getNode());
        if (itemType != null) {
            // Get the typeEntry so we know the absolute base type
            TypeEntry itemEntry = symbolTable.getTypeEntry(itemType, false);
            // TODO - If the itemEntry is not found, we need to throw
            // an exception.  "Item is referenced, but not defined"
            javifyTypeEntryName(symbolTable, itemEntry, anonQNames, uniqueNum);
            // Grab the referenced type, If it's there.
            TypeEntry refedEntry = itemEntry.getRefType();
            QName baseName = refedEntry == null ? itemEntry.getQName() : refedEntry.getQName();
            typeQName = new QName(baseName.getNamespaceURI(), baseName.getLocalPart() + "[]");
        }

        if (emitter.isDeploy()) {
            Class class1 = (Class) emitter.getQName2ClassMap().get(typeQName);
            if (class1 != null && !class1.isArray()) {
                tEntry.setName(getJavaClassName(class1));
                processed = true;
            }
        }

        if (!processed) {
            if ((typeQName.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) < 0)) {
                // Normal Case: The ref'd type is not anonymous
                // Simply construct the java name from
                // the qName
                tEntry.setName(emitter.getJavaName(typeQName));
            } else {
                // This is an anonymous type name.
                // Axis uses '>' as a nesting token to generate
                // unique qnames for anonymous types.
                // Only consider the localName after the last '>'
                // when generating the java name
                // String localName = typeQName.getLocalPart();
                // localName =
                // localName.substring(
                // localName.lastIndexOf(
                // SymbolTable.ANON_TOKEN)+1);
                // typeQName = new QName(typeQName.getNamespaceURI(),
                // localName);
                String localName = typeQName.getLocalPart();

                // Check to see if this is an anonymous type,
                // if it is, replace Axis' ANON_TOKEN with
                // an underscore to make sure we don't run
                // into name collisions with similarly named
                // non-anonymous types
                StringBuffer sb = new StringBuffer(localName);
                int aidx;

                while ((aidx = sb.toString().indexOf(SymbolTable.ANON_TOKEN)) > -1) {
                    sb.replace(aidx, aidx + SymbolTable.ANON_TOKEN.length(), "");
                    char c = sb.charAt(aidx);
                    if (Character.isLetter(c) && Character.isLowerCase(c)) {
                        sb.setCharAt(aidx, Character.toUpperCase(c));
                    }
                }

                localName = sb.toString();
                typeQName = new QName(typeQName.getNamespaceURI(), localName);

                if (emitter.isTypeCollisionProtection() && !emitter.getNamespaceExcludes()
                        .contains(new NamespaceSelector(typeQName.getNamespaceURI()))) {
                    // If there is already an existing type,
                    // there will be a collision.
                    // If there is an existing anon type,
                    // there will be a  collision.
                    // In both cases, mangle the name.
                    if (symbolTable.getType(typeQName) != null || anonQNames.get(typeQName) != null) {
                        localName += "Type" + uniqueNum++;
                        typeQName = new QName(typeQName.getNamespaceURI(), localName);
                    }

                    anonQNames.put(typeQName, typeQName);
                }

                // Now set the name with the constructed qname
                tEntry.setName(emitter.getJavaName(typeQName));
            }
        } // if (!processed)

        Vector elements = tEntry.getContainedElements();
        if (elements != null) {
            for (int i = 0; i < elements.size(); i++) {
                ElementDecl elem = (ElementDecl) elements.get(i);
                String varName = emitter.getJavaVariableName(typeQName, elem.getQName(), true);
                elem.setName(varName);
            }
        }

        Vector attributes = tEntry.getContainedAttributes();
        if (attributes != null) {
            for (int i = 0; i < attributes.size(); i++) {
                ContainedAttribute attr = (ContainedAttribute) attributes.get(i);
                String varName = emitter.getJavaVariableName(typeQName, attr.getQName(), false);
                attr.setName(varName);
            }
        }
    }

    // Set the entry with the same name as the ref'd entry
    // but add the appropriate amount of dimensions
    entry.setName(tEntry.getName() + dims);

    return uniqueNum;
}