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

/**
 * Store a picture that has just been saved to disk in the MediaStore.
 * /*from www.  j a  va2  s . com*/
 * @param imageFile
 *            The File of the picture
 * @return The Uri provided by the MediaStore.
 */
public static Uri storePicture(Context ctx, File imageFile, String imageName) {
    ContentResolver cr = ctx.getContentResolver();
    imageName = imageName.substring(imageName.lastIndexOf('/') + 1);
    ContentValues values = new ContentValues(7);
    values.put(Images.Media.TITLE, imageName);
    values.put(Images.Media.DISPLAY_NAME, imageName);
    values.put(Images.Media.DESCRIPTION, "");
    values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());
    values.put(Images.Media.MIME_TYPE, "image/jpeg");
    values.put(Images.Media.ORIENTATION, 0);
    File parentFile = imageFile.getParentFile();
    String path = parentFile.toString().toLowerCase();
    String name = parentFile.getName().toLowerCase();
    values.put(Images.ImageColumns.BUCKET_ID, path.hashCode());
    values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, name);
    values.put("_data", imageFile.toString());

    Uri uri = cr.insert(sStorageURI, values);

    return uri;
}

From source file:Main.java

public static String getFilesPath(String root) {
    if (root == null) {
        throw new IllegalArgumentException("root can't be null");
    }/*from www. j a v a 2s.  com*/

    if (filesPathCache != null && cachedRoot.hashCode() == root.hashCode())
        return filesPathCache;

    if (root.lastIndexOf('/') == -1) {
        filesPathCache = root + "/" + root + "_files/";
        cachedRoot = root;
        return filesPathCache;
    } else {
        int indexOfSlash = root.lastIndexOf('/');

        if (indexOfSlash != -1) {
            filesPathCache = root + "/" + extractMapName(root) + "_files/";
            cachedRoot = root;
        }

        return filesPathCache;
    }
}

From source file:com.screenslicer.common.Crypto.java

public static int fastHashInt(String str) {
    try {//  w w w. jav  a2  s  .  co m
        return str.hashCode();
    } catch (Exception e) {
        Log.exception(e);
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static String hashString(String input) {
    MessageDigest md5;/*from  w  ww .ja v a  2 s  .  c  o m*/
    try {
        md5 = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return String.valueOf(input.hashCode());
    }
    md5.update(input.getBytes());
    byte[] hash = md5.digest();
    return toHex(hash);
}

From source file:com.objy.se.utils.TargetList.java

private static long hash(List<Object> values) {
    String value = "";
    for (Object obj : values) {
        value += obj.toString();/*from   w ww  .  j  a v a2  s  .  com*/
    }
    return value.hashCode();
}

From source file:Main.java

public static int getColorForName(String name) {
    if (name.isEmpty()) {
        return 0xFF202020;
    }/*from  w  w  w  .j  av a  2 s  .  co m*/
    int colors[] = { 0xFFe91e63, 0xFF9c27b0, 0xFF673ab7, 0xFF3f51b5, 0xFF5677fc, 0xFF03a9f4, 0xFF00bcd4,
            0xFF009688, 0xFFff5722, 0xFF795548, 0xFF607d8b };
    return colors[(int) ((name.hashCode() & 0xffffffffl) % colors.length)];
}

From source file:Main.java

/**
 * get a unique hash of the device.// w  ww  .  j a v  a2  s  .c o  m
 * 
 * @return a unique hash of the device.
 */
public static String getDeviceId(Context ctx) {
    if (ctx == null) {
        return null;
    }

    String androidId = "" + android.provider.Settings.Secure.getString(
            ctx.getApplicationContext().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
    String deviceName = getDeviceName();

    UUID deviceUuid = new UUID(androidId.hashCode(),
            (long) deviceName.hashCode() << 32 | deviceName.hashCode());
    String deviceId = deviceUuid.toString().replace("-", "");

    return deviceId;
}

From source file:com.objy.se.utils.TargetList.java

private static long hashOfValues(Property... nameValues) {
    String value = "";
    for (Property nameValue : nameValues) {
        value += nameValue.attrValue.toString();
    }//from w w w . ja v a  2  s.  c  o  m
    return value.hashCode();
}

From source file:edu.stanford.junction.provider.irc.Junction.java

public static String makeIRCName(String name) {
    String s = String.valueOf(name.hashCode());
    s = s.replace("-", "0");
    s = "x" + s.substring(0, Math.min(s.length() - 1, 7));
    return s;//from  w  w  w .  ja va 2s. c  o  m
}

From source file:com.yahoo.research.scoring.classifier.NutchOnlineClassifier.java

/**
 * This is a simple functions which returns a hash within a fixed limited.
 * The returned has will be between 0 and (limit - 1)
 * //from w w  w . java  2s. c  o  m
 * @param str
 *            The {@link String} which should be hashed.
 * @param limit
 *            The maximal hash-size (int)
 * @return the corresponding hash value between 0 and (limit - 1) for the
 *         given input {@link String}
 */
private static int getHash(String str, int limit) {
    int hashCode = Math.abs(str.hashCode() % (limit));
    return hashCode;
}