List of usage examples for java.lang String hashCode
public int hashCode()
From source file:eu.planets_project.tb.gui.backing.exp.ExpTypeExecutablePP.java
/** * Builds the currentXMLConfig from the given service/param configuration * and writes it to a temporary file that's accessible via an external url ref. * This can be used within the browser to download the currentXMLConfig * @return//from w ww .j a v a 2 s . c o m */ public String getTempFileDownloadLinkForCurrentXMLConfig() { DataHandler dh = new DataHandlerImpl(); String currXMLConfig = buildXMLConfigFromCurrentConfiguration(); if (currXMLConfig == null) { return null; } //save it's hashcode - for caching purposes if ((this.currXMLConfigHashCode != -1) && (this.currXMLConfigHashCode != currXMLConfig.hashCode())) { this.currXMLConfigHashCode = currXMLConfig.hashCode(); try { //get a temporary file File f = dh.createTempFileInExternallyAccessableDir(); Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8")); out.write(currXMLConfig); out.close(); currXMLConfigTempFileURI = "" + dh.getHttpFileRef(f); return currXMLConfigTempFileURI; } catch (Exception e) { log.debug("Error getting TempFileDownloadLinkForCurrentXMLConfig " + e); return null; } } else { //FIXME: still missing to check if this temp file ref still exists //returned the cached object return this.currXMLConfigTempFileURI; } }
From source file:com.google.acre.script.HostEnv.java
@JSFunction public Scriptable load_system_script(String script, Scriptable scope) { int pathIndex = script.lastIndexOf('/'); String script_name = (pathIndex == -1) ? script : script.substring(pathIndex + 1); //String script_id = (ACRE_AUTORELOADING) ? script + lastModifiedTime(script) : script; String script_id = script + lastModifiedTime(script); String script_id_hash = Integer.toHexString(script_id.hashCode()); Scriptable newScope = load_script_from_cache(script_name, script_id_hash, scope, true); if (newScope == null) { String content = openResourceFile(script); newScope = load_script_from_string(content, script_name, script_id_hash, scope, null, true); }// w w w .j a va 2s.c o m return newScope; }
From source file:com.xpn.xwiki.render.DefaultXWikiRenderingEngine.java
private String getKey(String text, XWikiDocument contentdoc, XWikiDocument includingdoc, XWikiContext context) { String qs = ((context == null || context.getRequest() == null) ? "" : context.getRequest().getQueryString()); if (qs != null) { qs = qs.replaceAll("refresh=1&?", ""); qs = qs.replaceAll("&?refresh=1", ""); }/*from ww w .j av a 2s . com*/ String db = ((context == null) ? "xwiki" : context.getDatabase()); String cdoc = ((contentdoc == null) ? "" : contentdoc.getDatabase() + ":" + contentdoc.getFullName() + ":" + contentdoc.getRealLanguage() + ":" + contentdoc.getVersion()); String idoc = ((includingdoc == null) ? "" : includingdoc.getDatabase() + ":" + includingdoc.getFullName() + ":" + includingdoc.getRealLanguage() + ":" + includingdoc.getVersion()); String action = ((context == null) ? "view" : context.getAction()); String lang = ((context == null) ? "" : context.getLanguage()); lang += ((contentdoc == null) ? "" : ":" + contentdoc.getRealLanguage()); return db + "-" + cdoc + "-" + idoc + "-" + qs + "-" + action + "-" + lang + "-" + text.hashCode(); }
From source file:com.draagon.meta.manager.db.ObjectManagerDB.java
/** * Executes the specified query and maps it to the given object. * * String oql = "[" + Product.CLASSNAME + "]" + " SELECT {P.*}, {M.name} AS * manuName" + " FROM [" + Product.CLASSNAME + "=P]," + " [" + * Manufacturer.CLASSNAME + "=M]" + " WHERE {M.id}={P.manuId} AND {M.id} > * ?";/*w w w . j a v a2 s.co m*/ * * String oql = "[{min:int,max:int,num:int}]" + " SELECT MIN({extra2}) AS * min, MAX({extra2}) AS max, COUNT(1) AS num" + " FROM [" + * Product.CLASSNAME + "]"; */ public Collection<?> executeQuery(ObjectConnection c, String query, Collection<?> arguments) throws MetaException { Connection conn = (Connection) c.getDatastoreConnection(); // Check for a valid transaction if enforced checkTransaction(conn, false); try { MetaObject resultClass = null; query = query.trim(); if (query.startsWith("[{")) { int i = query.indexOf("}]"); if (i <= 0) { throw new MetaException("OQL does not contain a closing '}]': [" + query + "]"); } String classTemplate = query.substring(2, i).trim(); query = query.substring(i + 2).trim(); String templateClassname = "draagon::meta::manager::db::OQL" + classTemplate.hashCode(); // Get the result class, try it from the cache first resultClass = templateCache.get(templateClassname); if (resultClass == null) { resultClass = ValueMetaObject.createFromTemplate(templateClassname, classTemplate); templateCache.put(templateClassname, resultClass); } } else if (query.startsWith("[")) { int i = query.indexOf("]"); if (i <= 0) { throw new MetaException("OQL does not contain a closing ']': [" + query + "]"); } String className = query.substring(1, i).trim(); query = query.substring(i + 1).trim(); resultClass = MetaObject.forName(className); } else { throw new MetaException( "OQL does not contain a result set definition using []'s or {}'s: [" + query + "]"); } PreparedStatement s = getPreparedStatement(conn, query, arguments); try { if (log.isDebugEnabled()) { log.debug("SQL (" + conn.hashCode() + ") - executeQuery: [" + query + " " + arguments + "]"); } ResultSet rs = s.executeQuery(); LinkedList<Object> data = new LinkedList<Object>(); try { ObjectMappingDB mapping = (ObjectMappingDB) getReadMapping(resultClass); while (rs.next()) { Object o = resultClass.newInstance(); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { String col = rs.getMetaData().getColumnName(i); MetaField mf = getFieldForColumn(resultClass, mapping, col); if (mf != null) { parseField(o, mf, rs, i); } } data.add(o); } return data; } finally { rs.close(); } } finally { s.close(); } } catch (SQLException e) { log.error("Unable to execute object query [" + query + " (" + arguments + ")]: " + e.getMessage()); throw new MetaException( "Unable to execute object query [" + query + " (" + arguments + ")]: " + e.getMessage(), e); } }
From source file:com.tc.object.ApplicatorDNAEncodingTest.java
public void helpTestStringEncodingDecoding(String s, boolean compressed) throws Exception { // Encode string using applicator encoding into data final DNAEncoding applicatorEncoding = getApplicatorEncoding(); TCByteBufferOutputStream output = new TCByteBufferOutputStream(); applicatorEncoding.encode(s, output); final TCByteBuffer[] data = output.toArray(); // Decode string from data using storage encoding (into UTF8ByteDataHolder) into decoded final DNAEncoding storageEncoding = getStorageEncoder(); TCByteBufferInputStream input = new TCByteBufferInputStream(data); final UTF8ByteDataHolder decoded = (UTF8ByteDataHolder) storageEncoding.decode(input); if (compressed) { assertTrue(decoded instanceof UTF8ByteCompressedDataHolder); final UTF8ByteCompressedDataHolder compressedDecoded = (UTF8ByteCompressedDataHolder) decoded; assertEquals(s.getBytes("UTF-8").length, compressedDecoded.getUncompressedStringLength()); System.err.println("Compressed String length = " + compressedDecoded.getBytes().length); assertEquals(s.length(), compressedDecoded.getStringLength()); assertEquals(s.hashCode(), compressedDecoded.getStringHash()); }// w w w . ja va2s. c o m assertEquals(s, decoded.asString()); // Encode UTF8ByteDataHolder into data2 using storage encoding output = new TCByteBufferOutputStream(); storageEncoding.encode(decoded, output); final TCByteBuffer[] data2 = output.toArray(); // Decode UTF8ByteDataHolder from data2 into decoded2 using storage encoding input = new TCByteBufferInputStream(data2); final UTF8ByteDataHolder decoded2 = (UTF8ByteDataHolder) storageEncoding.decode(input); assertEquals(decoded, decoded2); // Decode from original data using applicator encoding into str input = new TCByteBufferInputStream(data); final String str = (String) applicatorEncoding.decode(input); assertEquals(s, str); // Decode from data2 using applicator encoding into str2 input = new TCByteBufferInputStream(data2); final String str2 = (String) applicatorEncoding.decode(input); assertEquals(s, str2); }
From source file:com.lastorder.pushnotifications.data.ImageDownloader.java
/** * @param url The URL of the image that will be retrieved from the cache. * @return The cached bitmap or null if it was not found. *//*from ww w .ja va2s .c o m*/ private Bitmap getBitmapFromCache(String url) { // First try the hard reference cache try { synchronized (sHardBitmapCache) { final Bitmap bitmap = sHardBitmapCache.get(url); if (bitmap != null) { // Bitmap found in hard cache // Move element to first position, so that it is removed last sHardBitmapCache.remove(url); sHardBitmapCache.put(url, bitmap); return bitmap; } } // Then try the soft reference cache SoftReference<Bitmap> bitmapReference = sSoftBitmapCache.get(url); if (bitmapReference != null) { final Bitmap bitmap = bitmapReference.get(); if (bitmap != null) { // Bitmap found in soft cache return bitmap; } else { // Soft reference has been Garbage Collected sSoftBitmapCache.remove(url); } } final String pathName = cacheDir + "/" + url.hashCode() + "-t.jpg"; final Bitmap bitmap = BitmapFactory.decodeFile(pathName); if (bitmap != null) { return bitmap; } return null; } catch (OutOfMemoryError e) { return null; } }
From source file:fuse.okuyamafs.OkuyamaFilesystem.java
public int read(String path, Object fh, ByteBuffer buf, long offset) throws FuseException { /*long start1 = 0L;/* ww w . j a v a 2 s. com*/ long start2 = 0L; long start3 = 0L; long start4 = 0L; long start5 = 0L; long end2 = 0L; long end3 = 0L; long end4 = 0L; long end5 = 0L; */ //start1 = System.nanoTime(); //start2 = System.nanoTime(); log.info("read:" + path + " offset:" + offset + " buf.limit:" + buf.limit()); if (fh == null) return Errno.EBADE; try { String trimToPath = path.trim(); 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 = (String) client.getPathDetail(trimToPath); String[] pathInfo = pathInfoStr.split("\t"); long nowSize = Long.parseLong(pathInfo[4]); int readLen = client.readValue(trimToPath, offset, buf.limit(), pathInfo[pathInfo.length - 2], buf); if (readLen == -1 || readLen < 1) { log.info("read data nothing read=" + "read:" + path + " offset:" + offset + " buf.limit:" + buf.limit()); } } } catch (FuseException fe) { throw fe; } catch (Exception e) { new FuseException(e); } return 0; }
From source file:cm.aptoide.pt.DownloadQueueService.java
private void setFinishedNotification(int apkidHash, String localPath) { String apkid = notifications.get(apkidHash).get("apkid"); int size = Integer.parseInt(notifications.get(apkidHash).get("intSize")); String version = notifications.get(apkidHash).get("version"); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification); contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification); contentView.setTextViewText(R.id.download_notification_name, getString(R.string.finished_download_message) + " " + apkid + " v." + version); contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, size * KBYTES_TO_BYTES, false); Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid)); onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab"); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.putExtra("localPath", localPath); onClick.putExtra("apkid", apkid); onClick.putExtra("apkidHash", apkidHash); onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate"))); /*Changed by Rafael Campos*/ onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version")); Log.d("Aptoide-DownloadQueuService", "finished notification apkidHash: " + apkidHash + " localPath: " + localPath); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0); Notification notification = new Notification(R.drawable.ic_notification, getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.contentView = contentView; // Set the info for the notification panel. notification.contentIntent = onClickAction; // notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Send the notification. // We use the position because it is a unique number. We use it later to cancel. notificationManager.notify(apkidHash, notification); // Log.d("Aptoide-DownloadQueueService", "Notification Set"); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.soapextensions.PendingChange.java
@Override public int hashCode() { if (!hashCodeValid) { int result = 17; /*/*from www . j av a2 s . co m*/ * Lock level is excluded because equals can be told to ignore it, * and we would violate the equals contract if two APendingChange * objects were equal but did not have the same hash code. */ // Fetch fields once for speed final String sourceServerItem = getSourceServerItem(); final ChangeType changeType = getChangeType(); final ItemType itemType = getItemType(); final String localItem = getLocalItem(); final String serverItem = getServerItem(); result = 37 * result + ((sourceServerItem == null) ? 0 : sourceServerItem.hashCode()); result = 37 * result + ((changeType == null) ? 0 : changeType.hashCode()); result = 37 * result + getDeletionID(); result = 37 * result + ((itemType == null) ? 0 : itemType.hashCode()); result = 37 * result + getItemID(); result = 37 * result + ((localItem == null) ? 0 : localItem.hashCode()); result = 37 * result + ((serverItem == null) ? 0 : serverItem.hashCode()); result = 37 * result + getVersion(); hashCode = result; hashCodeValid = true; } return hashCode; }
From source file:com.ikanow.infinit.e.data_model.store.config.source.SourcePojo.java
/** * generateSourceKey//from ww w . j a v a 2 s .c om * Strips out http://, smb:// /, :, etc. from the URL field to generate * Example: http://www.ikanow.com/rss -> www.ikanow.com.rss */ public String generateSourceKey() { String s = getRepresentativeUrl(); // (supports all cases - note we are guaranteed to have a URL by this point) if (null == s) { return null; } int nIndex = s.indexOf('?'); final int nMaxLen = 64; // (+24 for the object id, + random other stuff, keeps it in the <100 range) if (nIndex >= 0) { if (nIndex > nMaxLen) { nIndex = nMaxLen; // (ie max length) } StringBuffer sb = new StringBuffer(s.substring(0, nIndex)); sb.append(".").append(s.length() - nIndex).append('.').append(Math.abs(s.hashCode()) % 100); s = sb.toString(); } else if (s.length() > nMaxLen) { s = s.substring(0, nMaxLen); } //TESTED (urls with and without ?) s = s.replaceAll("http://|https://|smb://|ftp://|ftps://|file://|[^a-zA-Z0-9_.]", "."); if (s.startsWith(".")) s = s.substring(1); return s; }