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:com.emc.licensekey.activation.dao.impl.MockSiteDAO.java

private static String getRandomMacAddress(String name) {
    return String.format("AA:BB:CC:DD:" + "%02X:%02X", name.hashCode() % 9, name.hashCode() % 3);
}

From source file:Main.java

/**
 * Pretty crap long hashcode algo. FIXME
 * @param s The string to get the long hash code for
 * @return the long has code//from   w ww .j  a va 2s . co m
 */
public static long longHashCode(String s) {
    long h = 0;
    int len = s.length();
    int off = 0;
    int hashPrime = s.hashCode();
    char val[] = s.toCharArray();
    for (int i = 0; i < len; i++) {
        h = (31 * h + val[off++] + (hashPrime * h));
    }
    return h;
}

From source file:com.buaa.cfs.common.oncrpc.RpcUtil.java

public static int getNewXid(String caller) {
    return xid = ++xid + caller.hashCode();
}

From source file:model.NotesImageFile.java

/**
 * Takes a regular filename and creates a unique filename with date values included
 * @param fileName - the plain filename/*from www  .java2  s  . c  o m*/
 * @return 
 */
public static String createUniqueFileName(String fileName) {
    int hashcode = fileName.hashCode();
    DateFormat df = new SimpleDateFormat("yyyy-mm-dd-HH-mm-ss");
    Calendar calobj = Calendar.getInstance();
    System.out.println(df.format(calobj.getTime()));
    return (df.format(calobj.getTime()) + hashcode + fileName);
}

From source file:Main.java

public static String getCacheFileName(String url) {
    StringBuilder builder = new StringBuilder();
    builder.setLength(0);/*ww w. ja  va2  s.c om*/
    builder.append(CACHE_DIRECTORY);
    builder.append(url.hashCode()).append(".jpg");
    return builder.toString();
}

From source file:net.sourceforge.atunes.kernel.modules.lyrics.LyricsCache.java

/**
 * Lyrics Filename/*from  w  w w .ja v a 2  s.  c  o  m*/
 * 
 * @param album
 * @return
 */
private static String getFileNameForLyric(String artist, String title) {
    return StringUtils.getString(artist.hashCode(), title.hashCode(), ".xml");
}

From source file:com.chinamobile.bcbsp.graph.MetaDataOfGraph.java

/**
 * Compute the local partition rule.//from ww w.  j  av a  2  s .  c  o  m
 * @param dstVertexID
 * @return int
 */
public static int localPartitionRule(String dstVertexID) {
    int hashBucketNumber = BCBSP_DISKGRAPH_HASHNUMBER;
    int hashCode = dstVertexID.hashCode();
    int hashIndex = hashCode % hashBucketNumber; // bucket index
    hashIndex = (hashIndex < 0 ? hashIndex + hashBucketNumber : hashIndex);
    return hashIndex;
}

From source file:IO.FileWriter.java

/**
 * Write a given InputStream to file/*w ww  .ja  va2  s . c om*/
 *
 * @param is InputStream represent a file
 * @param file_path the destination file path
 * @return true if the file was successfully written to the disk
 */
public static boolean SaveInputStreamToFile(InputStream is, String file_path) {
    boolean success = false;
    try {
        File f = new File(file_path);
        is.reset();
        try (FileOutputStream fos = new FileOutputStream(f)) {
            byte[] buf = new byte[4096];
            int bytesRead;
            while ((bytesRead = is.read(buf)) != -1) {
                fos.write(buf, 0, bytesRead);
            }
        }
        success = true;
        is.reset();
    } catch (FileNotFoundException exception) {
        //Cope with filenames in exotic languages like chinees
        String fileName = Files.GetFileNameWithoutExtension(file_path);
        file_path = file_path.replace(fileName, fileName.hashCode() + "");
        success = SaveInputStreamToFile(is, file_path);
    } catch (IOException exception) {
        Console.PrintException("Error save InputStream to file", exception);
    }
    return success;
}

From source file:Main.java

public static File findInDiscCache(Context context, String imageUri) {
    File individualCacheDir = getIndividualCacheDirectory(context);
    String fileName = String.valueOf(imageUri.hashCode());
    File image = new File(individualCacheDir, fileName);
    return image.exists() ? image : null;
}

From source file:Main.java

public static File genDiscCacheFile(Context context, String imageUri) {
    File individualCacheDir = getIndividualCacheDirectory(context);
    String fileName = String.valueOf(imageUri.hashCode());
    File file = new File(individualCacheDir, fileName);
    Long currentTime = System.currentTimeMillis();
    file.setLastModified(currentTime);//from  w  w  w  .  ja v a2  s . c o  m
    return file;
}