Example usage for java.lang Character getNumericValue

List of usage examples for java.lang Character getNumericValue

Introduction

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

Prototype

public static int getNumericValue(int codePoint) 

Source Link

Document

Returns the int value that the specified character (Unicode code point) represents.

Usage

From source file:com.yahoo.squidb.data.JSONPropertyTest.java

private Map<String, Map<String, List<Integer>>> mockComplicatedMap() {
    HashMap<String, Map<String, List<Integer>>> crazyMap = new HashMap<>();

    Map<String, List<Integer>> internalMap1 = new HashMap<>();
    internalMap1.put("123", Arrays.asList(1, 2, 3));
    internalMap1.put("4567", Arrays.asList(4, 5, 6, 7));

    crazyMap.put("ABC", internalMap1);
    Map<String, List<Integer>> internalMap2 = new HashMap<>();
    internalMap2.put("XYZ", Arrays.asList(Character.getNumericValue('x'), Character.getNumericValue('y'),
            Character.getNumericValue('z')));
    internalMap2.put("Empty", new ArrayList<Integer>());
    internalMap2.put("NilValue", null);
    crazyMap.put("XYZ", internalMap2);
    return crazyMap;
}

From source file:com.manydesigns.portofino.actions.admin.tables.forms.ColumnForm.java

@Updatable(false)
@Insertable(false)/*from  ww w .jav a2 s  .co  m*/
@Label("Length")
public String getShortLength() {
    if (getLength() == null) {
        return null;
    }
    String[] suffix = new String[] { "", "K", "M", "G", "T" };
    java.text.DecimalFormat decimalFormat = new java.text.DecimalFormat("##0E0");
    String result = decimalFormat.format(getLength());
    int suffixIndex = Character.getNumericValue(result.charAt(result.length() - 1)) / 3;
    return result.replaceAll("E[0-9]", suffix[suffixIndex]);
}

From source file:edu.chalmers.dat076.moviefinder.service.TitleParser.java

/**
 * returns next number in mySb and deletes it and everything before it in
 * mySb.//from www . j  av a2s  . c o  m
 *
 * @param mySb
 * @return
 */
public int getNextNumber(StringBuilder mySb) {
    int value = -1;
    boolean deleteAll = true;

    for (int i = 0; i < mySb.length(); i++) {

        // Character.isDigit(i) better or worse?
        if ('0' <= mySb.charAt(i) && mySb.charAt(i) <= '9') {
            if (value < 0) {
                value = 0;
            } else {
                value = value * 10;
            }
            value = value + Character.getNumericValue(mySb.charAt(i));
        } else if (value > 0) {
            mySb.delete(0, i);
            deleteAll = false;
            break;
        }
    }
    if (deleteAll && value > 0) {
        mySb.setLength(0);
    }
    return value;
}

From source file:org.orcid.frontend.web.controllers.PublicProfileController.java

private boolean isProfileValidForIndex(OrcidProfile profile) {
    String orcid = profile.getOrcidIdentifier().getPath();
    if (orcid != null) {
        int validAge = 3 + (Character.getNumericValue(orcid.charAt(orcid.length() - 2))) / 2;
        if (profile.getOrcidHistory() != null && profile.getOrcidHistory().getSubmissionDate() != null
                && profile.getOrcidHistory().getSubmissionDate().getValue() != null) {
            Date profileCreationDate = profile.getOrcidHistory().getSubmissionDate().getValue()
                    .toGregorianCalendar().getTime();
            Date currentDate = new Date();

            Calendar temp = Calendar.getInstance();
            temp.setTime(profileCreationDate);
            temp.add(Calendar.DATE, validAge);
            profileCreationDate = temp.getTime();
            if (profileCreationDate.before(currentDate)) {
                return true;
            }/*from   w w  w.  j a v a 2s . c o  m*/
        }
    }
    return false;
}

From source file:com.google.sample.cast.refplayer.Synchronization.java

public void buildSocketConnection() {

    Thread socket = new Thread("Client") {

        private Socket clientSocket;
        BufferedInputStream in;//  w w w. j  av a 2  s  .  co m

        @Override
        public void run() {
            Log.d("SocketConnection", "Run");
            try {
                // set server IP and Port
                //InetAddress serverIp = InetAddress.getByName("10.0.1.27"); // CSCLab Tina
                //InetAddress serverIp = InetAddress.getByName("10.0.1.103");   // CSCLab Jack
                InetAddress serverIp = InetAddress.getByName("192.168.1.100"); // CVLab Sever
                int serverPort = 7777;
                clientSocket = new Socket(serverIp, serverPort);
                Log.d("SocketConnection", "Socket built");

                BufferedInputStream input = new BufferedInputStream(clientSocket.getInputStream());

                // repeat
                Looper.prepare();

                while (clientSocket.isConnected()) {
                    Log.d("SocketConnection", "Connection built");
                    byte[] data_byte = new byte[1024];
                    String data = "";
                    int length;
                    if ((length = input.read(data_byte)) > 0) {
                        data += new String(data_byte, 0, length);
                        Log.d("SocketConnection", "Data: " + data);

                        String subdata[] = data.split(",", 2);
                        String type[] = subdata[0].split(":", 2);
                        String value[] = subdata[1].split(":", 2);

                        Log.d("SocketConnection", "type[1]: " + type[1]);

                        if (type[1].equals("\"gesture\"")) {
                            Log.d("SocketConnection", "gesture");
                            setVolume(0);
                        } else if (type[1].equals("\"gaze\"")) {
                            Log.d("SocketConnection", "gaze");
                            setFocus((Character.getNumericValue(value[1].charAt(0))));
                        } else {
                            Log.d("SocketConnection", "default");
                        }
                    }
                }

                Looper.loop();

            } catch (Exception e) {
                // handle disconnection
                e.printStackTrace();
                Log.e("SocketConnection", e.toString());

                // shut down when disconnect
                finish();
            }
        }
    };

    socket.start();

}

From source file:org.latticesoft.util.common.NumeralUtil.java

/**
 * Compares 2 char array for equality, greater than or less than.
 * @param c1 char array 1//from w  w  w  . j a  va2  s. c o m
 * @param c2 char array 2
 * @return 1 if char array 1 is greater than char array 2;
 * 0 if they are the same; and -1 if char array 1 is less
 * than char array 2
 */
public static int compareCharArray(char c1[], char c2[]) {
    int count = (c1.length < c2.length) ? c1.length : c2.length;
    for (int i = 0; i < count; i++) {
        int i1 = Character.getNumericValue(c1[i]);
        int i2 = Character.getNumericValue(c2[i]);
        if (i1 > i2) {
            return 1;
        } else if (i1 < i2) {
            return -1;
        } // else is equal
    }
    // at this stage, either equal
    // now check length
    if (c1.length > c2.length) {
        return 1;
    } else if (c1.length < c2.length) {
        return -1;
    }
    return 0;
}

From source file:org.LexGrid.util.sql.DBUtility.java

/**
 * Construct the next identifier to use after the given identifier. Expects
 * (and returns) a 2 character string - using the characters a-z in the
 * first position and the characters a-z and 0-9 in the second position.
 * Case insensitive. Wraps if it gets to zz. Starts with a0 (if no
 * identifier is provided)/*from w ww . j  av  a  2 s .com*/
 * 
 * @param currentIdentifier
 * @return
 * @throws Exception
 *             if it doesn't understand the identifier.
 */
public static String computeNextIdentifier(String currentIdentifier) throws Exception {
    String temp;
    if (currentIdentifier == null || currentIdentifier.length() == 0) {
        temp = "a0";
    } else if (StringUtils.isNumeric(currentIdentifier)) {
        temp = "a0";
    } else if (currentIdentifier.length() != 2) {
        throw new Exception("Invalid identifer passed in.  Must be a 2 character string.");
    } else {
        temp = currentIdentifier;
    }

    char a = temp.toLowerCase().charAt(0);
    char b = temp.toLowerCase().charAt(1);

    int ai = Character.getNumericValue(a);
    int bi = Character.getNumericValue(b);

    if (ai < 10 || ai > 35) {
        throw new Exception("Invalid identifer passed in.  First character must be a letter.");
    }

    if (bi < 0 || bi > 35) {
        throw new Exception("Invalid identifer passed in.  Second character must be a letter or a number.");
    }

    if (bi < 35) {
        bi++;
    } else {
        bi = 0;
        ai++;
    }

    if (ai > 35) {
        ai = 10;
    }

    return new String(Character.forDigit(ai, 36) + "" + Character.forDigit(bi, 36));
}

From source file:org.apache.orc.impl.mask.RedactMaskFactory.java

/**
 * Get the replacement digit. This routine supports non-ASCII values for the
 * replacement. For example, if the user gives one of "7", "", "" or "?"
 * the value is 7.//www.  j  a v  a2s  . co  m
 * @param digitCodePoint the code point that is replacing digits
 * @return the number from 0 to 9 to use as the numeric replacement
 */
static int getReplacementDigit(int digitCodePoint) {
    int dig = Character.getNumericValue(digitCodePoint);
    if (dig >= 0 && dig <= 9) {
        return dig;
    } else {
        return DEFAULT_NUMBER_DIGIT;
    }
}

From source file:edu.cornell.med.icb.goby.modes.CompactToFastaMode.java

/**
 * Return a fake nucleotide corresponding to a color space character, or leave unchanged if
 * input is not color space./*from  w w w  .  j  a v  a2s . c o  m*/
 *
 * @param c The character to get the fake nucleotide for
 * @return he fake nucleotide represented by the input
 */
private char getFakeNtCharacter(final char c) {
    final int i = Character.getNumericValue(c);
    return i >= 0 && i < FAKE_NT_ALPHABET.length ? FAKE_NT_ALPHABET[i] : c;
}

From source file:CSSDFarm.UserInterface.java

private int stringToIntConverter(String string) {
    int total = string.length();
    int x = 0;//from   ww w. j  ava  2  s . co  m
    for (int i = 0; i < total; i++) {
        if (i == 0) {
            x = Character.getNumericValue(string.charAt(i));
        } else {
            x += Character.getNumericValue(string.charAt(i));
        }
    }
    return x;
}