List of usage examples for java.lang String hashCode
public int hashCode()
From source file:cm.aptoide.pt.ManageRepos.java
private boolean isRepoManaged(String uri) { if (repos.getHashMap().containsKey(uri.hashCode())) { Log.d("Aptoide-ManageRepo", "Repo already exists"); return true; } else {/* ww w . j a v a2s .c o m*/ String existingUri; for (ViewDisplayRepo existingRepo : repos.getHashMap().values()) { existingUri = existingRepo.getUri(); if (uri.length() == (existingUri.length() - 1)) { if (uri.equals(existingUri.substring(0, existingUri.length() - 1))) { Log.d("Aptoide-ManageRepo", "Repo equal to existant one but without final forward slash"); return true; } } else if (uri.length() == (existingUri.length() - 8)) { if (uri.equals(existingUri.substring(7, existingUri.length() - 1))) { Log.d("Aptoide-ManageRepo", "Repo equal to existant one but without initial http:// and the final forward slash"); return true; } } else { uri = uri + ".bazaarandroid.com/"; if (uri.equals(existingUri.substring(7, existingUri.length()))) { Log.d("Aptoide-ManageRepo", "Repo equal to existant one but without initial http:// and without .bazaarandroid.com extension"); return true; } if (uri.equals(existingUri.substring(7, existingUri.length() - 1))) { Log.d("Aptoide-ManageRepo", "Repo equal to existant one but without initial http:// , without .bazaarandroid.com extension, and the final forward slash"); return true; } } } } Log.d("Aptoide-ManageRepo", "Repo is new"); return false; }
From source file:com.streamreduce.util.JiraClient.java
public SOAPMessage invokeSoap(JiraStudioApp app, String soapBody) throws SOAPException { String cacheKey = (app + "-SOAP-" + soapBody.hashCode()); Object objectFromCache = requestCache.getIfPresent(cacheKey); if (objectFromCache != null) { debugLog(LOGGER, " (From cache)"); return (SOAPMessage) objectFromCache; }/* w ww.j ava 2 s. com*/ // Wrap the SOAP body content in an envelope/body container StringBuilder sb = new StringBuilder(); String soapBaseURL = getBaseUrl(); String soapNamespaceURL; sb.append("<soapenv:Envelope ").append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ") .append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ") .append("xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "); switch (app) { case CONFLUENCE: soapNamespaceURL = "http://soap.rpc.confluence.atlassian.com"; soapBaseURL += "/wiki/rpc/soap-axis/confluenceservice-v1"; break; case JIRA: soapNamespaceURL = "http://soap.rpc.jira.atlassian.com"; soapBaseURL += "/rpc/soap/jirasoapservice-v2"; break; default: throw new SOAPException("Unknown Jira Studio application: " + app); } sb.append("xmlns:soap=\"" + soapNamespaceURL + "\">\n"); sb.append("<soapenv:Body>\n"); sb.append(soapBody); sb.append("</soapenv:Body></soapenv:Envelope>"); String rawResponse; List<Header> requestHeaders = new ArrayList<>(); requestHeaders.add(new BasicHeader("SOAPAction", "")); try { rawResponse = HTTPUtils.openUrl(soapBaseURL, "POST", sb.toString(), MediaType.TEXT_XML, null, null, requestHeaders, null); } catch (Exception e) { LOGGER.error(String.format("Unable to make SOAP call to %s: %s", soapBaseURL, e.getMessage()), e); throw new SOAPException(e); } Source response = new StreamSource(new StringReader(rawResponse)); MessageFactory msgFactory = MessageFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); SOAPPart env = message.getSOAPPart(); env.setContent(response); if (message.getSOAPBody().hasFault()) { SOAPFault fault = message.getSOAPBody().getFault(); LOGGER.error("soap fault in jira soap response: " + fault.getFaultString()); } requestCache.put(cacheKey, message); return message; }
From source file:pt.aptoide.backupapps.ManageRepos.java
private boolean isRepoManaged(String uri) { if (repos.getHashMap().containsKey(uri.hashCode())) { Log.d("Aptoide-ManageRepo", "Repo already exists"); return true; } else {//from w w w. j a v a 2 s . c o m String existingUri; for (ViewDisplayRepo existingRepo : repos.getHashMap().values()) { existingUri = existingRepo.getUri(); if (uri.length() == (existingUri.length() - 1)) { if (uri.equals(existingUri.substring(0, existingUri.length() - 1))) { Log.d("Aptoide-ManageRepo", "Repo equal to existant one but without final forward slash"); return true; } } else if (uri.length() == (existingUri.length() - 8)) { if (uri.equals(existingUri.substring(7, existingUri.length() - 1))) { Log.d("Aptoide-ManageRepo", "Repo equal to existant one but without initial http:// and the final forward slash"); return true; } } else { uri = uri + Constants.DOMAIN_APTOIDE_STORE; if (uri.equals(existingUri.substring(7, existingUri.length()))) { Log.d("Aptoide-ManageRepo", "Repo equal to existant one but without initial http:// and without " + Constants.DOMAIN_APTOIDE_STORE + " extension"); return true; } if (uri.equals(existingUri.substring(7, existingUri.length() - 1))) { Log.d("Aptoide-ManageRepo", "Repo equal to existant one but without initial http:// , without " + Constants.DOMAIN_APTOIDE_STORE + ", and the final forward slash"); return true; } } } } Log.d("Aptoide-ManageRepo", "Repo is new"); return false; }
From source file:com.dianping.cat.system.page.router.config.RouterConfigManager.java
public List<Server> queryServersByDomain(String group, String domain) { Domain domainConfig = m_routerConfig.findDomain(domain); List<Server> result = new ArrayList<Server>(); boolean noExist = notCustomizedDomains(group, domainConfig); if (noExist) { List<Server> servers = new ArrayList<Server>(); Map<String, Server> enables = queryEnableServers(); ServerGroup serverGroup = m_routerConfig.getServerGroups().get(group); if (serverGroup != null) { for (GroupServer s : serverGroup.getGroupServers().values()) { servers.add(enables.get(s.getId())); }//from w ww . jav a 2 s . c om } if (servers.isEmpty()) { servers = new ArrayList<Server>(enables.values()); } int length = servers.size(); int hashCode = domain.hashCode(); for (int i = 0; i < 2; i++) { int index = Math.abs((hashCode + i)) % length; addServerList(result, servers.get(index)); } addServerList(result, queryBackUpServer()); } else { result.addAll(domainConfig.findGroup(group).getServers()); } return result; }
From source file:edu.umass.cs.gigapaxos.PaxosInstanceStateMachine.java
private static int getCPI(int cpi, String paxosID) { return (int) (cpi * (1 - CPI_NOISE) + (Math.abs(paxosID.hashCode()) % cpi) * 2 * CPI_NOISE); }
From source file:com.jaspersoft.jasperserver.war.common.HeartbeatBean.java
private void initHeartbeat() { osName = System.getProperty("os.name"); osVersion = System.getProperty("os.version"); javaVendor = System.getProperty("java.vendor"); javaVersion = System.getProperty("java.version"); serverInfo = servletContext.getServerInfo(); location = servletContext.getRealPath("/"); dbName = null;//w w w. jav a 2s. c o m dbVersion = null; Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); dbName = metaData.getDatabaseProductName(); dbVersion = metaData.getDatabaseProductVersion(); } catch (SQLException e) { if (log.isDebugEnabled()) log.debug("Getting database metadata failed.", e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { } } } String idSource = //javaVendor + "|" //+ javaVersion + "|" serverInfo + "|" + productName + "|" //+ productVersion + "|" + (location == null ? "" : location); MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { //heartbeat is always silent } if (messageDigest == null) { localId = String.valueOf(idSource.hashCode()); } else { byte[] idBytes = messageDigest.digest(idSource.getBytes()); StringBuffer idBuffer = new StringBuffer(2 * idBytes.length); for (int i = 0; i < idBytes.length; i++) { String hexa = Integer.toHexString(128 + idBytes[i]).toUpperCase(); hexa = ("00" + hexa).substring(hexa.length()); idBuffer.append(hexa); } localId = idBuffer.toString(); } /* */ File localIdFile = getLocalIdFile(); if (localIdFile.exists() && localIdFile.isFile()) { localIdProperties = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(localIdFile); localIdProperties.load(fis); } catch (IOException e) { if (log.isDebugEnabled()) log.debug("Loading heartbeat local ID properties file failed.", e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { } } } } heartbeatId = localIdProperties.getProperty(PROPERTY_HEARTBEAT_ID); /* */ File clientInfoCacheFile = getClientInfoCacheFile(); if (clientInfoCacheFile.exists() && clientInfoCacheFile.isFile()) { try { clientInfoCache = (HeartbeatInfoCache) JRLoader.loadObject(clientInfoCacheFile); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Loading heartbeat cache from serialized file failed.", e); } } lastCacheSaveTime = System.currentTimeMillis(); }
From source file:net.demilich.metastone.game.behaviour.decicionTreeBheavior.DecisionDataBase.java
public int getFeatureIndex(String name, boolean enemy, boolean board) { String featureName; if (enemy) {/*ww w. j a v a 2s. co m*/ if (board) { featureName = "EB:"; } else { featureName = "EH:"; } } else { if (board) { featureName = "MB:"; } else { featureName = "MH:"; } } featureName += name; return this.featureHashToIndex.get(featureName.hashCode()); }
From source file:com.github.jknack.handlebars.Handlebars.java
/** * Compile a handlebars template.//from www .j a v a 2 s . co m * * @param input The input text. Required. * @param startDelimiter The start delimiter. Required. * @param endDelimiter The end delimiter. Required. * @return A compiled template. * @throws IOException If the resource cannot be loaded. */ public Template compileInline(final String input, final String startDelimiter, final String endDelimiter) throws IOException { notNull(input, "The input is required."); String filename = "inline@" + Integer.toHexString(Math.abs(input.hashCode())); return compile(new StringTemplateSource(filename, input), startDelimiter, endDelimiter); }
From source file:fuse.okuyamafs.OkuyamaFilesystem.java
public int getattr(String path, FuseGetattrSetter getattrSetter) throws FuseException { log.info("getattr " + path); String[] pathInfo = null;// w ww.j a v a2 s . c o m try { String[] setInfo = new String[11]; 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); } } } if (path.trim().equals("/")) { setInfo[1] = new Integer(FuseFtypeConstants.TYPE_DIR | 0777).toString(); pathInfo = new String[9]; pathInfo[1] = "0"; pathInfo[2] = "0"; pathInfo[3] = "0"; pathInfo[4] = "0"; pathInfo[5] = "0"; pathInfo[6] = "0"; pathInfo[8] = "0"; } else { String pathInfoStr = client.getPathDetail(path.trim()); if (pathInfoStr == null || pathInfoStr.trim().equals("")) { return Errno.ENOENT; } pathInfo = pathInfoStr.split("\t"); if (pathInfo[0].equals("file")) { setInfo[1] = new Integer(FuseFtypeConstants.TYPE_FILE | new Integer(pathInfo[7]).intValue()) .toString(); } else if (pathInfo[0].equals("dir")) { setInfo[1] = new Integer(FuseFtypeConstants.TYPE_DIR | new Integer(pathInfo[7]).intValue()) .toString(); } else { // ? client.removePathDetail(path.trim()); return Errno.ENOENT; //throw new FuseException("No such entry entry name =[" + pathInfoStr + "]").initErrno(FuseException.ENOENT); } } /* stat.nlink = 1; stat.uid = 0; stat.gid = 0; stat.size = 1000; stat.atime = 0; stat.blocks = 2; */ setInfo[0] = new Integer(path.hashCode()).toString(); // inode setInfo[2] = pathInfo[1]; //stat.nlink = Integer.parseInt(pathInfo[1]); setInfo[3] = pathInfo[2]; ///stat.uid = Integer.parseInt(pathInfo[2]); setInfo[4] = pathInfo[3]; //stat.gid = Integer.parseInt(pathInfo[3]); setInfo[5] = pathInfo[8]; // rdev setInfo[6] = pathInfo[4]; //stat.size = Integer.parseInt(pathInfo[4]); long blockCnt = Long.parseLong(setInfo[6]) / 512; if (Long.parseLong(setInfo[6]) % 512 > 0) blockCnt++; //setInfo[7] = Long.parseLong(setInfo[6]) % 512; //stat.blocks = Integer.parseInt(pathInfo[6]); setInfo[8] = pathInfo[5]; //stat.atime = Integer.parseInt(pathInfo[5]); setInfo[9] = pathInfo[5]; // mtime setInfo[10] = pathInfo[5]; // ctime getattrSetter.set(new Long(setInfo[0]).longValue(), new Integer(setInfo[1]).intValue(), new Integer(setInfo[2]).intValue(), new Integer(setInfo[3]).intValue(), new Integer(setInfo[4]).intValue(), new Integer(setInfo[5]).intValue(), new Long(setInfo[6]).longValue(), blockCnt, new Integer(setInfo[8]).intValue(), new Integer(setInfo[9]).intValue(), new Integer(setInfo[10]).intValue()); } catch (FuseException fe) { fe.printStackTrace(); throw fe; } catch (Exception e) { e.printStackTrace(); new FuseException(e).initErrno(FuseException.EACCES); } return 0; }