List of usage examples for java.lang String hashCode
public int hashCode()
From source file:net.nightwhistler.pageturner.Configuration.java
public int getLastPosition(String fileName) { SharedPreferences bookPrefs = getPrefsForBook(fileName); int pos = bookPrefs.getInt(KEY_POS, -1); if (pos != -1) { return pos; }/*from w w w .j a v a2 s. c o m*/ //Fall-back to older settings String bookHash = Integer.toHexString(fileName.hashCode()); pos = settings.getInt(KEY_POS + bookHash, -1); if (pos != -1) { return pos; } // Fall-back for even older settings. return settings.getInt(KEY_POS + fileName, -1); }
From source file:com.example.android.mediabrowserservice.model.MusicProvider.java
private MediaMetadata buildFromJSON(JSONObject json, String basePath) throws JSONException { String title = json.getString(JSON_TITLE); String album = json.getString(JSON_ALBUM); String artist = json.getString(JSON_ARTIST); String genre = json.getString(JSON_GENRE); String source = json.getString(JSON_SOURCE); String iconUrl = json.getString(JSON_IMAGE); int trackNumber = json.getInt(JSON_TRACK_NUMBER); int totalTrackCount = json.getInt(JSON_TOTAL_TRACK_COUNT); int duration = json.getInt(JSON_DURATION) * 1000; // ms LogHelper.d(TAG, "Found music track: ", json); // Media is stored relative to JSON file if (!source.startsWith("http")) { source = basePath + source;/*from w ww. java2 s. c om*/ } if (!iconUrl.startsWith("http")) { iconUrl = basePath + iconUrl; } // Since we don't have a unique ID in the server, we fake one using the hashcode of // the music source. In a real world app, this could come from the server. String id = String.valueOf(source.hashCode()); // Adding the music source to the MediaMetadata (and consequently using it in the // mediaSession.setMetadata) is not a good idea for a real world music app, because // the session metadata can be accessed by notification listeners. This is done in this // sample for convenience only. return new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_MEDIA_ID, id) .putString(CUSTOM_METADATA_TRACK_SOURCE, source).putString(MediaMetadata.METADATA_KEY_ALBUM, album) .putString(MediaMetadata.METADATA_KEY_ARTIST, artist) .putLong(MediaMetadata.METADATA_KEY_DURATION, duration) .putString(MediaMetadata.METADATA_KEY_GENRE, genre) .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadata.METADATA_KEY_TITLE, title) .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, trackNumber) .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, totalTrackCount).build(); }
From source file:com.aujur.ebookreader.Configuration.java
public int getLastPosition(String fileName) { SharedPreferences bookPrefs = getPrefsForBook(fileName); int pos = bookPrefs.getInt(KEY_POS, -1); if (pos != -1) { return pos; }//from ww w . j a v a2 s .c o m // Fall-back to older settings String bookHash = Integer.toHexString(fileName.hashCode()); pos = settings.getInt(KEY_POS + bookHash, -1); if (pos != -1) { return pos; } // Fall-back for even older settings. return settings.getInt(KEY_POS + fileName, -1); }
From source file:fuse.okuyamafs.OkuyamaFilesystem.java
public int release(String path, Object fh, int flags) throws FuseException { log.info("release " + path + " " + fh + " " + flags); synchronized (this.parallelDataAccessSync[((path.hashCode() << 1) >>> 1) % 100]) { List bufferedDataFhList = writeBufFpMap.removeGroupingData(path); if (bufferedDataFhList != null) { for (int idx = 0; idx < bufferedDataFhList.size(); idx++) { Object bFh = bufferedDataFhList.get(idx); this.fixNoCommitData(bFh); }//from ww w. j a v a2s. c om } openStatusMap.remove(path.trim()); this.fixNoCommitData(fh); } return 0; }
From source file:net.nightwhistler.pageturner.Configuration.java
public int getLastIndex(String fileName) { SharedPreferences bookPrefs = getPrefsForBook(fileName); int pos = bookPrefs.getInt(KEY_IDX, -1); if (pos != -1) { return pos; }/*from w w w . j a va2 s . c om*/ //Fall-backs to older setting in central file String bookHash = Integer.toHexString(fileName.hashCode()); pos = settings.getInt(KEY_IDX + bookHash, -1); if (pos != -1) { return pos; } // Fall-back for even older settings. return settings.getInt(KEY_IDX + fileName, -1); }
From source file:fuse.okuyamafs.OkuyamaFilesystem.java
public int unlink(String path) throws FuseException { log.info("unlink " + path); try {/*from w w w. ja v a 2 s.c om*/ synchronized (this.parallelDataAccessSync[((path.hashCode() << 1) >>> 1) % 100]) { // ???????????flush? List bufferedDataFhList = writeBufFpMap.removeGroupingData(path); if (bufferedDataFhList != null) { for (int idx = 0; idx < bufferedDataFhList.size(); idx++) { Object bFh = bufferedDataFhList.get(idx); this.fixNoCommitData(bFh); } } Map metaInfo = client.getDataMetaInfo(path); boolean deleteFlg = true; if (metaInfo.size() > 1) { if (metaInfo.get("pathdetail") != null && metaInfo.get("attribute") != null) { deleteFlg = false; String pathInfoStr = client.getPathDetail(path.trim()); if (pathInfoStr == null) return Errno.ENOENT; String[] pathInfo = pathInfoStr.split("\t"); if (client.removePathDetail(path.trim()) == false) return Errno.EIO; if (client.removeAttribute(path.trim()) == false) return Errno.EIO; client.deleteValue(path.trim(), pathInfo[pathInfo.length - 2]); } } if (deleteFlg) { try { client.removePathDetail(path); client.removeAttribute(path); String pathInfoStr = (String) metaInfo.get("pathdetail"); if (pathInfoStr != null) { String[] pathInfo = pathInfoStr.split("\t"); client.deleteValue(path, pathInfo[pathInfo.length - 2]); } } catch (Exception innerE) { } log.fatal("broken file remove filename=[" + path + "]"); } } } catch (Exception e) { throw new FuseException(e).initErrno(FuseException.EIO); } return 0; }
From source file:com.aujur.ebookreader.Configuration.java
public int getLastIndex(String fileName) { SharedPreferences bookPrefs = getPrefsForBook(fileName); int pos = bookPrefs.getInt(KEY_IDX, -1); if (pos != -1) { return pos; }/*from w ww . j a v a2 s .c o m*/ // Fall-backs to older setting in central file String bookHash = Integer.toHexString(fileName.hashCode()); pos = settings.getInt(KEY_IDX + bookHash, -1); if (pos != -1) { return pos; } // Fall-back for even older settings. return settings.getInt(KEY_IDX + fileName, -1); }
From source file:com.github.stephanarts.cas.ticket.registry.provider.UpdateMethod.java
/** * Execute the JSONRPCFunction./* w w w . j a va 2 s . c o m*/ * * @param params JSONRPC Method Parameters. * * @return JSONRPC result object * * @throws JSONRPCException implementors can throw JSONRPCExceptions containing the error. */ public JSONObject execute(final JSONObject params) throws JSONRPCException { JSONObject result = new JSONObject(); Ticket ticket; String ticketId = null; String serializedTicket = null; logger.debug("Update Ticket {}", ticketId); if (params.length() != 2) { throw new JSONRPCException(-32602, "Invalid Params"); } if (!(params.has("ticket-id") && params.has("ticket"))) { throw new JSONRPCException(-32602, "Invalid Params"); } try { ticketId = params.getString("ticket-id"); serializedTicket = params.getString("ticket"); ByteArrayInputStream bi = new ByteArrayInputStream( DatatypeConverter.parseBase64Binary(serializedTicket)); ObjectInputStream si = new ObjectInputStream(bi); ticket = (Ticket) si.readObject(); if (ticket.isExpired()) { logger.info("Ticket Expired {}", ticketId); } if (!this.map.containsKey(ticket.hashCode())) { logger.warn("Missing Key {}", ticketId); } this.map.put(ticketId.hashCode(), ticket); } catch (final Exception e) { throw new JSONRPCException(-32501, "Could not decode Ticket"); } logger.debug("Ticket-ID '{}'", ticketId); return result; }
From source file:com.cyberway.issue.crawler.frontier.AbstractFrontier.java
/** * Utility method to return a scratch dir for the given key's temp files. * Every key gets its own subdir. To avoid having any one directory with * thousands of files, there are also two levels of enclosing directory * named by the least-significant hex digits of the key string's java * hashcode.// w ww . ja v a 2s .c om * * @param key * @return File representing scratch directory */ protected File scratchDirFor(String key) { String hex = Integer.toHexString(key.hashCode()); while (hex.length() < 4) { hex = "0" + hex; } int len = hex.length(); return new File(this.controller.getStateDisk(), hex.substring(len - 2, len) + File.separator + hex.substring(len - 4, len - 2) + File.separator + key); }
From source file:fuse.okuyamafs.OkuyamaFilesystem.java
public int truncate(String path, long size) throws FuseException { log.info("truncate " + path + " " + size); try {/*from w w w. j a v a2 s .c om*/ synchronized (this.parallelDataAccessSync[((path.hashCode() << 1) >>> 1) % 100]) { // ???????????flush? List bufferedDataFhList = writeBufFpMap.removeGroupingData(path); if (bufferedDataFhList != null) { for (int idx = 0; idx < bufferedDataFhList.size(); idx++) { Object bFh = bufferedDataFhList.get(idx); this.fixNoCommitData(bFh); } } String pathInfoStr = client.getPathDetail(path.trim()); if (pathInfoStr == null) return Errno.ENOENT; String[] pathInfo = pathInfoStr.split("\t"); if (new Long(pathInfo[4].trim()).longValue() > size) { client.removeValue(path.trim(), size, (Long.parseLong(pathInfo[4]) - size), pathInfo[pathInfo.length - 2]); } else { client.appendingNullData(path.trim(), size, pathInfo[pathInfo.length - 2]); } pathInfo[4] = new Long(size).toString(); pathInfo[5] = new Long(System.currentTimeMillis() / 1000L).toString(); int assistBlockSize = 0; if ((size % blockSize) > 0) { assistBlockSize = 1; } pathInfo[6] = new Long((size / blockSize) + assistBlockSize).toString(); StringBuilder strBuf = new StringBuilder(64); strBuf.append(pathInfo[0]).append("\t").append(pathInfo[1]).append("\t").append(pathInfo[2]) .append("\t").append(pathInfo[3]).append("\t").append(pathInfo[4]).append("\t") .append(pathInfo[5]).append("\t").append(pathInfo[6]).append("\t").append(pathInfo[7]) .append("\t").append(pathInfo[8]).append("\t").append(pathInfo[9]).append("\t") .append("-1"); if (!client.setPathDetail(path.trim(), strBuf.toString())) return Errno.EIO; } } catch (FuseException fe) { throw fe; } catch (Exception e) { throw new FuseException(e).initErrno(FuseException.EACCES); } return 0; }