Example usage for java.lang String charAt

List of usage examples for java.lang String charAt

Introduction

In this page you can find the example usage for java.lang String charAt.

Prototype

public char charAt(int index) 

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:Main.java

public static long prefixCodedToLong(final String prefixCoded) {
    final int shift = prefixCoded.charAt(0) - SHIFT_START_LONG;
    if (shift > 63 || shift < 0)
        throw new NumberFormatException(
                "Invalid shift value in prefixCoded string (is encoded value really a LONG?)");
    long sortableBits = 0L;
    for (int i = 1, len = prefixCoded.length(); i < len; i++) {
        sortableBits <<= 7;/*  w w w .  ja va 2  s .  c  o m*/
        final char ch = prefixCoded.charAt(i);
        if (ch > 0x7f) {
            throw new NumberFormatException("Invalid prefixCoded numerical value representation (char "
                    + Integer.toHexString(ch) + " at position " + i + " is invalid)");
        }
        sortableBits |= ch;
    }
    return (sortableBits << shift) ^ 0x8000000000000000L;
}

From source file:Main.java

public static int SDBMHash(String str) {
    int hash = 0;

    for (int i = 0; i < str.length(); i++) {
        hash = str.charAt(i) + (hash << 6) + (hash << 16) - hash;
    }/*from  ww w.jav a2s  .c  om*/

    return (hash & 0x7FFFFFFF);
}

From source file:Main.java

public static int parseIS(String s) {
    return s != null && s.length() != 0 ? Integer.parseInt(s.charAt(0) == '+' ? s.substring(1) : s) : 0;
}

From source file:Main.java

public static int getPathLevels(String path) {
    int result = 0;

    for (int i = 0; i < path.length(); i++) {
        if (path.charAt(i) == '/') {
            result++;//from  www.  j av a2  s  .c  o m
        }
    }
    return result;
}

From source file:Main.java

public static boolean isHex(String key) {
    for (int i = key.length() - 1; i >= 0; i--) {
        final char c = key.charAt(i);
        if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
            return false;
        }/*from   w  w  w .  j  a  v  a  2  s  .  c o  m*/
    }

    return true;
}

From source file:Main.java

public static int parseDual(String s) {
    if (s.length() < 2 || Character.toLowerCase(s.charAt(s.length() - 1)) != 'd')
        throw new NumberFormatException("not a dual number: " + s);

    if (s.length() > 33)
        throw new NumberFormatException("number has more than 32 digits:" + s);

    int val = 0;
    for (int i = 0; i < s.length() - 1; i++) {
        val = val << 1;
        switch (s.charAt(i)) {
        case '1':
            val |= 1;
            break;
        case '0':
            break;
        default://from w  w  w.  j  a  v a  2  s. c  om
            throw new NumberFormatException("not a dual number: " + s);
        }
    }
    return val;
}

From source file:Main.java

public static String getShortWeekdayName(int day) {
    if (day < 1 || day > 7)
        throw new IndexOutOfBoundsException("Invalid index, value must be between 1 and 7");
    String dayName = dateFormatSymbols.getShortWeekdays()[day];
    return dayName.replace(dayName.charAt(0), Character.toUpperCase(dayName.charAt(0)));
}

From source file:Main.java

public static void putString(ByteBuffer buf, String str) {
    int len = str.length();
    for (int i = 0; i < len; i++) {
        buf.putChar(str.charAt(i));
    }/*from w  w  w. j a v a2 s. c  om*/
}

From source file:Main.java

private static void checkOffset(String paramString, int paramInt, char paramChar)
        throws IndexOutOfBoundsException {
    char c = paramString.charAt(paramInt);
    if (c != paramChar)
        throw new IndexOutOfBoundsException("Expected '" + paramChar + "' character but found '" + c + "'");
}

From source file:Main.java

public static int createDir(String path) {
    int len = path.length();
    if (len < 1)
        return -1;
    if (path.charAt(len - 1) != '/')
        path += "/";
    if (new File(path).mkdir())
        return 0;
    return -1;/*from w w  w .j a  v a  2s  .c  om*/
}