Example usage for java.lang Character toLowerCase

List of usage examples for java.lang Character toLowerCase

Introduction

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

Prototype

public static int toLowerCase(int codePoint) 

Source Link

Document

Converts the character (Unicode code point) argument to lowercase using case mapping information from the UnicodeData file.

Usage

From source file:com.github.pockethub.android.ui.repo.RepositoryListFragment.java

private void updateHeaders(final List<Repository> repos) {
    HeaderFooterListAdapter<?> rootAdapter = getListAdapter();
    if (rootAdapter == null) {
        return;//from   ww w.j  av  a  2 s.com
    }

    DefaultRepositoryListAdapter adapter = (DefaultRepositoryListAdapter) rootAdapter.getWrappedAdapter();
    adapter.clearHeaders();

    if (repos.isEmpty()) {
        return;
    }

    // Add recent header if at least one recent repository
    Repository first = repos.get(0);
    if (recentRepos.contains(first)) {
        adapter.registerHeader(first, getString(R.string.recently_viewed));
    }

    // Advance past all recent repositories
    int index;
    Repository current = null;
    for (index = 0; index < repos.size(); index++) {
        Repository repository = repos.get(index);
        if (recentRepos.contains(repository.id())) {
            current = repository;
        } else {
            break;
        }
    }

    if (index >= repos.size()) {
        return;
    }

    if (current != null) {
        adapter.registerNoSeparator(current);
    }

    // Register header for first character
    current = repos.get(index);
    char start = Character.toLowerCase(current.name().charAt(0));
    adapter.registerHeader(current, Character.toString(start).toUpperCase(US));

    char previousHeader = start;
    for (index = index + 1; index < repos.size(); index++) {
        current = repos.get(index);
        char repoStart = Character.toLowerCase(current.name().charAt(0));
        if (repoStart <= start) {
            continue;
        }

        // Don't include separator for the last element of the previous
        // character
        if (previousHeader != repoStart) {
            adapter.registerNoSeparator(repos.get(index - 1));
        }

        adapter.registerHeader(current, Character.toString(repoStart).toUpperCase(US));
        previousHeader = repoStart;
        start = repoStart++;
    }

    // Don't include separator for last element
    adapter.registerNoSeparator(repos.get(repos.size() - 1));
}

From source file:com.prowidesoftware.swift.model.SwiftBlockUser.java

/**
 * Checks if the block name is valid for a user defined block.
 * @param blockName the block name/*w  w w .  j a  v a 2  s.  c  o  m*/
 * @return true if the block name and number are valid 
 * 
 * @since 5.0
 */
static public Boolean isValidName(String blockName) {
    // name and number must be defined
    if (blockName == null)
        return (Boolean.FALSE);

    // try as a number
    try {
        Integer num = Integer.decode(blockName);
        if (!SwiftBlockUser.isValidName(num).booleanValue())
            return (Boolean.FALSE);
    } catch (NumberFormatException nfe) {
        // do nothing (it was not a number)
    }
    ;

    // for named blocks, the name must be only one letter
    if (blockName.length() != 1)
        return (Boolean.FALSE);

    // only upper or lower case letters
    char c = Character.toLowerCase(blockName.charAt(0));
    if (!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z')))
        return (Boolean.FALSE);

    return (Boolean.TRUE);
}

From source file:org.eclipse.plugin.kpax.beaninspector.introspector.BeanIntrospector.java

private String uncapitalize(String value) {
    if (value.length() < 2) {
        return value.toLowerCase();
    } else if (Character.isUpperCase(value.charAt(0)) && Character.isUpperCase(value.charAt(1))) {
        return value;
    } else {//from  w  w w  . j  ava 2  s . c o  m
        return Character.toLowerCase(value.charAt(0)) + value.substring(1);
    }
}

From source file:jenkins.scm.api.SCMHeadMixinEqualityGenerator.java

/**
 * Creates the {@link SCMHeadMixin.Equality} instance.
 *
 * @param type the {@link SCMHead} type to create the instance for.
 * @return the {@link SCMHeadMixin.Equality} instance.
 */// w  ww. ja  v a  2 s  .co m
@NonNull
private SCMHeadMixin.Equality create(@NonNull Class<? extends SCMHead> type) {
    Map<String, Method> properties = new TreeMap<String, Method>();
    for (Class clazz : (List<Class>) ClassUtils.getAllInterfaces(type)) {
        if (!SCMHeadMixin.class.isAssignableFrom(clazz)) {
            // not a mix-in
            continue;
        }
        if (SCMHeadMixin.class == clazz) {
            // no need to check this by reflection
            continue;
        }
        if (!Modifier.isPublic(clazz.getModifiers())) {
            // not public
            continue;
        }
        // this is a mixin interface, only look at declared properties;
        for (Method method : clazz.getDeclaredMethods()) {
            if (method.getReturnType() == Void.class) {
                // nothing to do with us
                continue;
            }
            if (!Modifier.isPublic(method.getModifiers())) {
                // should never get here
                continue;
            }
            if (Modifier.isStatic(method.getModifiers())) {
                // might get here with Java 8
                continue;
            }
            if (method.getParameterTypes().length != 0) {
                // not a property
                continue;
            }
            String name = method.getName();
            if (!name.matches("^((is[A-Z0-9_].*)|(get[A-Z0-9_].*))$")) {
                // not a property
                continue;
            }
            if (name.startsWith("is")) {
                name = "" + Character.toLowerCase(name.charAt(2))
                        + (name.length() > 3 ? name.substring(3) : "");
            } else {
                name = "" + Character.toLowerCase(name.charAt(3))
                        + (name.length() > 4 ? name.substring(4) : "");
            }
            if (properties.containsKey(name)) {
                // a higher priority interface already defined the method
                continue;
            }
            properties.put(name, method);
        }
    }
    if (properties.isEmpty()) {
        // no properties to consider
        return new ConstantEquality();
    }
    if (forceReflection) {
        return new ReflectiveEquality(properties.values().toArray(new Method[properties.size()]));
    }
    // now we define the class
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    String name = SCMHeadMixin.class.getPackage().getName() + ".internal." + type.getName();

    // TODO Move to 1.7 opcodes once baseline 1.612+
    cw.visit(Opcodes.V1_6, ACC_PUBLIC, name.replace('.', '/'), null, Type.getInternalName(Object.class),
            new String[] { Type.getInternalName(SCMHeadMixin.Equality.class) });
    generateDefaultConstructor(cw);
    generateEquals(cw, properties.values());
    byte[] image = cw.toByteArray();

    Class<? extends SCMHeadMixin.Equality> c = defineClass(name, image, 0, image.length)
            .asSubclass(SCMHeadMixin.Equality.class);

    try {
        return c.newInstance();
    } catch (InstantiationException e) {
        // fallback to reflection
    } catch (IllegalAccessException e) {
        // fallback to reflection
    }
    return new ReflectiveEquality(properties.values().toArray(new Method[properties.size()]));

}

From source file:org.eclipse.ecr.core.storage.sql.extensions.EmbeddedFunctions.java

public static final String parseWord(String string) {
    int len = string.length();
    if (len < 3) {
        return null;
    }/*  w w w  .j a  va  2  s.c  o  m*/
    StringBuilder buf = new StringBuilder(len);
    for (int i = 0; i < len; i++) {
        char c = Character.toLowerCase(string.charAt(i));
        if (c == '\u00e6') {
            buf.append("ae");
        } else if (c >= '\u00e0' && c <= '\u00ff') {
            buf.append(UNACCENTED.charAt((c) - 0xe0));
        } else if (c == '\u0153') {
            buf.append("oe");
        } else {
            buf.append(c);
        }
    }
    // simple heuristic to remove plurals
    int l = buf.length();
    if (l > 3 && buf.charAt(l - 1) == 's') {
        buf.setLength(l - 1);
    }
    String word = buf.toString();
    if (stopWords.contains(word)) {
        return null;
    }
    return word;
}

From source file:UTFEncodingUtil.java

/**
 * Decodes the given string using the encoding UTF-8.
 *
 * @param s        the string that should be encoded.
 * @return the encoded string./*from  ww w .  ja  va  2 s .c om*/
 */
public static String decodeUTF(final String s) {
    final StringBuffer sbuf = new StringBuffer();
    final char[] chars = s.toCharArray();
    final int l = chars.length;
    int sumb = 0;
    for (int i = 0, more = -1; i < l; i++) {
        /* Get next byte b from URL segment s */
        final int ch = chars[i];
        final int b;
        switch (ch) {
        case '%':
            final char lch = s.charAt(++i);
            final int hb = (Character.isDigit(lch) ? lch - '0' : 10 + Character.toLowerCase(lch) - 'a') & 0xF;
            final char hch = s.charAt(++i);
            final int lb = (Character.isDigit(hch) ? hch - '0' : 10 + Character.toLowerCase(hch) - 'a') & 0xF;
            b = (hb << 4) | lb;
            break;
        case '+':
            b = ' ';
            break;
        default:
            b = ch;
        }
        /* Decode byte b as UTF-8, sumb collects incomplete chars */
        if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
            sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb
            if (--more == 0) {
                sbuf.append((char) sumb); // Add char to sbuf
            }
        } else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits)
            sbuf.append((char) b); // Store in sbuf
        } else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits)
            sumb = b & 0x1f;
            more = 1; // Expect 1 more byte
        } else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits)
            sumb = b & 0x0f;
            more = 2; // Expect 2 more bytes
        } else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits)
            sumb = b & 0x07;
            more = 3; // Expect 3 more bytes
        } else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits)
            sumb = b & 0x03;
            more = 4; // Expect 4 more bytes
        } else /*if ((b & 0xfe) == 0xfc)*/
        { // 1111110x (yields 1 bit)
            sumb = b & 0x01;
            more = 5; // Expect 5 more bytes
        }
        /* We don't test if the UTF-8 encoding is well-formed */
    }
    return sbuf.toString();
}

From source file:com.actionbarsherlock.internal.view.menu.MenuItemImpl.java

public MenuItem setShortcut(char numericChar, char alphaChar) {
    mShortcutNumericChar = numericChar;//from ww  w . j  a v  a  2  s  .  co m
    mShortcutAlphabeticChar = Character.toLowerCase(alphaChar);

    mMenu.onItemsChanged(false);

    return this;
}

From source file:hydrograph.ui.expression.editor.sourceviewer.SourceViewer.java

private void handleVerifyKeyPressed(VerifyEvent event) {
    if (!event.doit) {
        return;/*  w  w w .j a  va 2s  .  c om*/
    }
    try {
        KeyStroke triggerKeyStroke = HotKeyUtil.getHotKey(HotKeyUtil.contentAssist);
        if (triggerKeyStroke != null) {

            if ((triggerKeyStroke.getModifierKeys() == KeyStroke.NO_KEY
                    && triggerKeyStroke.getNaturalKey() == event.character)
                    || (((triggerKeyStroke.getNaturalKey() == event.keyCode)
                            || (Character.toLowerCase(triggerKeyStroke.getNaturalKey()) == event.keyCode)
                            || (Character.toUpperCase(triggerKeyStroke.getNaturalKey()) == event.keyCode))
                            && ((triggerKeyStroke.getModifierKeys() & event.stateMask) == triggerKeyStroke
                                    .getModifierKeys()))) {

                doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
                event.doit = false;
                return;
            }
        }
    } catch (Exception e) {
    }

    if (event.stateMask != SWT.CTRL) {
        return;
    }

    switch (event.character) {
    case ' ':
        doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
        event.doit = false;
        break;

    case '.':
        doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
        event.doit = false;
        break;
    case 'y' - 'a' + 1:
        doOperation(ITextOperationTarget.REDO);
        event.doit = false;
        break;
    case 'z' - 'a' + 1:
        doOperation(ITextOperationTarget.UNDO);
        event.doit = false;
        break;
    default:
    }
}

From source file:org.apache.hyracks.data.std.primitive.UTF8StringPointable.java

public static boolean endsWith(UTF8StringPointable src, UTF8StringPointable pattern, boolean ignoreCase) {
    int len1 = src.getUTF8Length();
    int len2 = pattern.getUTF8Length();
    if (len2 > len1) {
        return false;
    }//from ww  w  . j a  va2s.c  om

    int s1Start = src.getMetaDataLength();
    int s2Start = pattern.getMetaDataLength();

    int c1 = len1 - len2;
    int c2 = 0;
    while (c1 < len1 && c2 < len2) {
        char ch1 = src.charAt(s1Start + c1);
        char ch2 = pattern.charAt(s2Start + c2);

        if (ch1 != ch2) {
            if (!ignoreCase || ignoreCase && Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) {
                break;
            }
        }
        c1 += src.charSize(s1Start + c1);
        c2 += pattern.charSize(s2Start + c2);
    }
    return (c2 == len2);
}

From source file:com.espertech.esper.event.bean.PropertyHelper.java

/**
 * Adds to the given list of property descriptors the mapped properties, ie.
 * properties that have a getter method taking a single String value as a parameter.
 * @param clazz to introspect/*  www. ja  va  2 s  . co m*/
 * @param result is the list to add to
 */
protected static void addMappedProperties(Class clazz, List<InternalEventPropDescriptor> result) {
    Set<String> uniquePropertyNames = new HashSet<String>();
    Method[] methods = clazz.getMethods();

    for (int i = 0; i < methods.length; i++) {
        String methodName = methods[i].getName();
        if (!methodName.startsWith("get")) {
            continue;
        }

        String inferredName = methodName.substring(3, methodName.length());
        if (inferredName.length() == 0) {
            continue;
        }

        Class<?> parameterTypes[] = methods[i].getParameterTypes();
        if (parameterTypes.length != 1) {
            continue;
        }

        if (parameterTypes[0] != String.class) {
            continue;
        }

        String newInferredName = null;
        // Leave uppercase inferred names such as URL
        if (inferredName.length() >= 2) {
            if ((Character.isUpperCase(inferredName.charAt(0)))
                    && (Character.isUpperCase(inferredName.charAt(1)))) {
                newInferredName = inferredName;
            }
        }
        // camelCase the inferred name
        if (newInferredName == null) {
            newInferredName = Character.toString(Character.toLowerCase(inferredName.charAt(0)));
            if (inferredName.length() > 1) {
                newInferredName += inferredName.substring(1, inferredName.length());
            }
        }
        inferredName = newInferredName;

        // if the property inferred name already exists, don't supply it
        if (uniquePropertyNames.contains(inferredName)) {
            continue;
        }

        result.add(new InternalEventPropDescriptor(inferredName, methods[i], EventPropertyType.MAPPED));
        uniquePropertyNames.add(inferredName);
    }
}