Java ID Value Create toIdSet(boolean includeAlphaCharacters, String nonAlphaCharacters)

Here you can find the source of toIdSet(boolean includeAlphaCharacters, String nonAlphaCharacters)

Description

Encodes a set of ASCII characters (< 127) as a bitset of 4 32-bit values.

License

Apache License

Declaration

private static int[] toIdSet(boolean includeAlphaCharacters, String nonAlphaCharacters) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/* w  w  w .ja  v  a 2 s.  c  om*/
     * Encodes a set of ASCII characters (< 127) as a bitset of 4 32-bit values.
     */
    private static int[] toIdSet(boolean includeAlphaCharacters, String nonAlphaCharacters) {
        int[] bits = new int[4]; // 4*32=128 which covers all ASCII
        if (includeAlphaCharacters) {
            for (int ch = 'A'; ch <= 'Z'; ch++) {
                bits[ch >>> 5] |= (1 << (ch & 31));
            }
            for (int ch = 'a'; ch <= 'z'; ch++) {
                bits[ch >>> 5] |= (1 << (ch & 31));
            }
        }
        for (int i = 0; i < nonAlphaCharacters.length(); i++) {
            int ch = nonAlphaCharacters.charAt(i);
            if (ch >= 128) {
                throw new AssertionError(); // out of range
            }
            bits[ch >>> 5] |= (1 << (ch & 31));
        }
        return bits;
    }
}

Related

  1. toIdentifier(String text)
  2. toIdentifierString(long val)
  3. toIdentityEncodedString(byte[] data)
  4. toIdentityHashCodeInteger(Object value)
  5. toIdentityVariableName(String varName)
  6. toIDString(final byte[] id)