List of usage examples for java.lang String hashCode
public int hashCode()
From source file:com.ge.predix.acs.policy.evaluation.cache.AbstractPolicyEvaluationCache.java
static String policySetKey(final String zoneId, final String policySetId) { return zoneId + ":set-id:" + Integer.toHexString(policySetId.hashCode()); }
From source file:com.adobe.acs.commons.rewriter.impl.StaticReferenceRewriteTransformerFactory.java
private static String getShardValue(final String filePath, final int shardCount, final ShardNameProvider sharder) { int result = 1; if (shardCount > 1) { final int fileHash = ((filePath.hashCode() & Integer.MAX_VALUE) % shardCount) + 1; String hostNumberString = Integer.toString(fileHash); if (hostNumberString.length() >= 2) { // get the 2nd digit as the 1st digit will not contain "0" Character c = hostNumberString.charAt(1); hostNumberString = c.toString(); // If there are more than 10 hosts, convert it back to base10 // so we do not have alpha hostNumberString = Integer.toString(Integer.parseInt(hostNumberString, shardCount)); result = Integer.parseInt(hostNumberString) + 1; } else {/*from w ww . j a va 2 s .c o m*/ result = fileHash; } } return sharder.lookup(result); }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash.java
/** * Make a hash based on individual, property, literal and (lang or datatype). * //from w ww . jav a2s.c om * @param stmt * @return a value between MIN_INTEGER and MAX_INTEGER */ public static int makeRdfLiteralHash(DataPropertyStatement stmt) { if ((stmt.getLanguage() != null && stmt.getLanguage().trim().length() > 0) && (stmt.getDatatypeURI() != null && stmt.getDatatypeURI().trim().length() > 0)) throw new Error("DataPropertyStatement should not have both a language " + "and a datatype; lang: '" + stmt.getLanguage() + "' datatype: '" + stmt.getDatatypeURI() + "'"); if (stmt.getIndividualURI() == null || stmt.getIndividualURI().trim().length() == 0) throw new Error("Cannot make a hash for a statement with no subject URI"); if (stmt.getDatapropURI() == null || stmt.getDatapropURI().trim().length() == 0) throw new Error("Cannot make a hash for a statement with no predicate URI"); String langOrDatatype = "9876NONE"; if (stmt.getLanguage() != null && stmt.getLanguage().trim().length() > 0) { langOrDatatype = stmt.getLanguage(); } else { if (stmt.getDatatypeURI() != null && stmt.getDatatypeURI().trim().length() > 0) { langOrDatatype = stmt.getDatatypeURI(); } } String hashMe = langOrDatatype + "_" + stmt.getIndividualURI() + "_" + stmt.getDatapropURI() + "_" + stmt.getData(); if (log.isDebugEnabled()) log.debug("got hash " + hashMe.hashCode() + " for String '" + hashMe + "'"); return hashMe.hashCode(); }
From source file:com.dc.tes.License.java
private static String Lisence(Core core, String license) { // ??//w w w . j a va 2s . c om boolean[] adapterFlag = new boolean[C_ADAPTER_LIST_SIZE]; // ? Date[] adapterDate = new Date[C_ADAPTER_LIST_SIZE]; // Date tesDate; // ?? int adapterNum; try { // ?License //String license = RuntimeUtils.ReadResource("license.dat", RuntimeUtils.utf8); byte[] _enData = new BASE64Decoder().decodeBuffer(license); byte[] _buffer = new byte[_enData.length - 8]; System.arraycopy(_enData, 0, _buffer, 0, _enData.length - 8); license = new String(decrypt(_buffer, "nuclearg".getBytes())); String[] segments = StringUtils.split(license, "\r"); for (int i = 0; i < C_ADAPTER_LIST_SIZE; i++) adapterFlag[i] = segments[0].charAt(i) == '1'; String[] _adapterDate = segments[1].split("\\|"); for (int i = 0; i < C_ADAPTER_LIST_SIZE; i++) if (adapterFlag[i]) adapterDate[i] = _adapterDate[i + 1].equals("00000000") ? null : new SimpleDateFormat("yyyyMMdd").parse(_adapterDate[i + 1]); tesDate = segments[2].equals("00000000") ? null : new SimpleDateFormat("yyyyMMdd").parse(segments[2]); adapterNum = Integer.parseInt(segments[3]); } catch (Exception ex) { throw new LicenseException("?License", ex); } if (tesDate != null && new Date().after(tesDate)) throw new LicenseException(""); int count = 0; StringBuffer buffer = new StringBuffer(); List<String> disabledChannelNames = new ArrayList<String>(); for (String name : core.channels.getChannelNames()) if (core.channels.getChannel(name) instanceof IAdapterChannel) { count++; Class<? extends IChannel> cls = core.channels.getChannel(name).getClass(); String pName = core.channels.getChannel(name).getClass().getPackage().getName(); pName = pName.substring(pName.lastIndexOf('.') + 1); int id = pName.hashCode() & 0x7fffffff % 64; if (ArrayUtils.contains(cls.getInterfaces(), IListenerChannel.class)) id += 64; if (!adapterFlag[id] || (adapterDate[id] != null && new Date().after(adapterDate[id]))) disabledChannelNames.add(name); } if (adapterNum > 0 && count > adapterNum) throw new LicenseException("??license?"); for (String disabledChannel : disabledChannelNames) { buffer.append("License?" + disabledChannel + "??") .append(SystemUtils.LINE_SEPARATOR); core.channels.getChannelNames().remove(disabledChannel); } return buffer.toString(); }
From source file:gov.nrel.util.Utility.java
public static String createCfName(String modelName) { int hashCode = modelName.hashCode(); int bucketNumber = Math.abs(hashCode % 10); if (bucketNumber > 9 || bucketNumber < 0) throw new RuntimeException( "bug, bucket number should be 0 to 9....hashCode=" + hashCode + " buckNum=" + bucketNumber); String realCf = "nreldata" + bucketNumber; return realCf; }
From source file:com.fluidops.iwb.deepzoom.ImageLoader.java
public static String filename(String imagefile) { try {//w w w . j a v a2s . c om return URLEncoder.encode( Integer.toString(imagefile.hashCode()) /*.substring(imagefile.lastIndexOf("/")+1)*/, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage(), e); } return null; }
From source file:com.google.enterprise.connector.sharepoint.wsclient.mock.MockClientFactory.java
/** * Generates a new Sharepoint ID.//from w ww.ja v a2s.c o m * * @param url the URL of the object * @param fixedId a flag inidicating whether to use fixed or random ID's * @return a valid string ID */ public static String generateId(final String url, Boolean fixedId) { String id; if (fixedId) { // This generates an ID from the URL that is passed in so that we get // the same ID for a URL. id = String.format("%032x", url.hashCode()); id = "{" + id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20) + "}"; } else { // This just generates a random ID. id = "{" + UUID.randomUUID().toString() + "}"; } return id; }
From source file:edu.illinois.cs.cogcomp.annotation.BasicAnnotatorService.java
/** * get a hash key based on the text value provided * * @param text a text that has been used as the basis of a TextAnnotation object * @param taBuilderName name of TextAnnotationBuilder that created the basic TextAnnotation * @return a key for this TextAnnotation *//*www . j a va 2 s .c o m*/ public static String getTextAnnotationCacheKey(String text, String taBuilderName) { return text.hashCode() * 13 + ":" + taBuilderName; }
From source file:com.beligum.core.utils.AssetPacker.java
private static int calcHash(String[] strings) { final int prime = 31; int result = 1; for (String s : strings) { result = result * prime + s.hashCode(); }//w w w . java2 s. c o m return result; }
From source file:Main.java
public static String get_device_id(Context ctx) { final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); String tmDevice = ""; String tmSerial = null;//from ww w . j a v a 2s . c o m String androidId = null; try { tmDevice = "" + tm.getDeviceId(); } catch (Exception ex) { } try { tmSerial = "" + tm.getSimSerialNumber(); } catch (Exception ex) { } try { androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); } catch (Exception ex) { } try { UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); String deviceId = deviceUuid.toString(); MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(deviceId.getBytes()); byte byteData[] = md.digest(); //convert the byte to hex format method 1 StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } deviceId = sb.toString(); return deviceId; } catch (Exception ex) { } return "nodeviceid"; }