Example usage for java.lang String hashCode

List of usage examples for java.lang String hashCode

Introduction

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

Prototype

public int hashCode() 

Source Link

Document

Returns a hash code for this string.

Usage

From source file:Main.java

public static Intent createShortcutIntent(String url) {
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
    shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    return shortcutIntent;
}

From source file:Main.java

public static String toMD5(String key) {
    String cacheKey;/*from ww w.j  a va  2s . co  m*/
    if (mDigest == null) {
        return String.valueOf(key.hashCode());
    }
    mDigest.update(key.getBytes());
    cacheKey = bytesToHexString(mDigest.digest());
    return cacheKey;
}

From source file:Main.java

public static int getCost(String uniqID) {

    // Currently hard coding the cost value : // TODO: has to be removed
    int hashCode = uniqID.hashCode();
    if (hashCode < 0)
        hashCode = hashCode * -1;//from  ww w.  j  av  a2 s. c  om
    int cost = hashCode % 40 + 10;
    if (cost % 6 == 0 || cost % 8 == 0) {
        cost = 0;
    }
    return cost;
}

From source file:Main.java

private static String generateDeviceUniqueIdentifier(Context context) {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice = "" + tm.getDeviceId();
    final String tmSerial = "" + tm.getSimSerialNumber();
    final String androidId = ""
            + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    final String packageBasedAndroidId = context.getPackageName() + androidId;

    UUID deviceUuid = new UUID(packageBasedAndroidId.hashCode(),
            ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return deviceUuid.toString();
}

From source file:Main.java

private static int colorFor(String username) {
    return 0xFFFFFFFF & username.hashCode();
}

From source file:Main.java

public static String getDeviceID(Activity a) {
    TelephonyManager tm = (TelephonyManager) a.getApplicationContext()
            .getSystemService(Context.TELEPHONY_SERVICE);
    String id = tm.getDeviceId();
    if (id == null)
        id = "DefaultTwitchUser";
    return Integer.toHexString(id.hashCode());
}

From source file:com.emc.licensekey.activation.dao.impl.MockSiteDAO.java

private static String getRandomIpAddress(String name) {
    try {/*w  w  w .  ja  v  a2s .c o  m*/
        return name.hashCode() % 255 + "." + name.hashCode() % 200 + "." + name.hashCode() % 100 + "."
                + name.hashCode() % 50;
    } catch (Exception e) {
        return "121.12.112.1";
    }
}

From source file:Main.java

public static boolean readBooleanAttribute(Element elem, String name, boolean defaultValue) {
    boolean back = defaultValue;

    String str = elem.getAttribute(name);
    if (str != null) {
        if (str.length() > 0) {
            int hash = str.hashCode();
            if ((hash == "yes".hashCode()) || (hash == "true".hashCode())) {
                back = true;//  ww w  .j a  v  a  2s  . c  o m
            } else {
                back = false;
            }
        }
    }

    return back;
}

From source file:TwoStrings.java

public static void compare(String one, String two) {
    System.out.println("Comparing...");
    if (one == two) {
        System.out.println("Strings are shared: " + one.hashCode() + ", " + two.hashCode());
    } else if (one.equals(two)) {
        System.out.println("At least the strings are equal: " + one.hashCode() + ", " + two.hashCode());
        System.out.println((Object) one);
        System.out.println(two);//from   w  w w .  ja va2s. c  o m
    } else
        System.out.println("This is rather distressing, sir.");
    System.out.println();
}

From source file:Main.java

public static String getVlaueFromAnnotation(Annotation annotation, String annName) {
    if (cache == null) {
        cache = new LruCache(500);
    }/*from  www .j  a v  a  2 s. co  m*/
    String annotationString = annotation.toString();
    String cacheKey = "getVlaueByColumnAnnotation:" + annotationString.hashCode() + "," + annName;
    String ret = (String) cache.get(cacheKey);
    if (ret == null || "".equals(ret)) {
        String pattern = annName + "=(.*?),";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(annotation.toString());
        if (m.find()) {
            ret = m.group();
            ret = ret.substring(annName.length() + 1, ret.length() - 1);
        }
        cache.put(cacheKey, ret);
    }
    return ret;
}