List of usage examples for java.lang String hashCode
public int hashCode()
From source file:hudson.plugins.plot.PlotData.java
/** * Generates the plot and stores it in the plot instance variable. * /*from w w w . java 2 s .co m*/ * @param forceGenerate if true, force the plot to be re-generated * even if the on-disk data hasn't changed */ private void generatePlot(boolean forceGenerate) { class Label implements Comparable<Label> { final private Integer buildNum; final private String buildDate; final private String text; public Label(String buildNum, String buildTime, String text) { this.buildNum = Integer.parseInt(buildNum); synchronized (DATE_FORMAT) { this.buildDate = DATE_FORMAT.format(new Date(Long.parseLong(buildTime))); } this.text = text; } public int compareTo(Label that) { return this.buildNum - that.buildNum; } @Override public boolean equals(Object o) { return o instanceof Label && ((Label) o).buildNum.equals(buildNum); } @Override public int hashCode() { return buildNum.hashCode(); } public String numDateString() { return "#" + buildNum + " (" + buildDate + ")"; } @Override public String toString() { return text != null ? text : numDateString(); } } LOGGER.fine("Generating plot from file: " + csvFilePath.getName()); PlotCategoryDataset dataset = new PlotCategoryDataset(); for (String[] record : rawPlotData) { // record: series y-value, series label, build number, build date, url int buildNum; try { buildNum = Integer.valueOf(record[2]); if (project.getBuildByNumber(buildNum) == null || buildNum > getRightBuildNum()) { continue; // skip this record } } catch (NumberFormatException nfe) { continue; // skip this record all together } Number value = null; try { value = Integer.valueOf(record[0]); } catch (NumberFormatException nfe) { try { value = Double.valueOf(record[0]); } catch (NumberFormatException nfe2) { continue; // skip this record all together } } String series = record[1]; Label xlabel = getUrlUseDescr() ? new Label(record[2], record[3], descriptionForBuild(buildNum)) : new Label(record[2], record[3], getBuildName(buildNum)); String url = null; if (record.length >= 5) url = record[4]; dataset.setValue(value, url, series, xlabel); } int numBuilds; try { numBuilds = Integer.parseInt(getURLNumBuilds()); } catch (NumberFormatException nfe) { numBuilds = DEFAULT_NUMBUILDS; } dataset.clipDataset(numBuilds); plot = createChart(dataset); CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot(); categoryPlot.setDomainGridlinePaint(Color.black); categoryPlot.setRangeGridlinePaint(Color.black); categoryPlot.setDrawingSupplier(PlotData.supplier); CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build()); categoryPlot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.03); domainAxis.setCategoryMargin(0.0); for (Object category : dataset.getColumnKeys()) { Label label = (Label) category; if (label.text != null) { domainAxis.addCategoryLabelToolTip(label, label.numDateString()); } else { domainAxis.addCategoryLabelToolTip(label, descriptionForBuild(label.buildNum)); } } AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) categoryPlot.getRenderer(); int numColors = dataset.getRowCount(); for (int i = 0; i < numColors; i++) { renderer.setSeriesPaint(i, new Color(Color.HSBtoRGB((1f / numColors) * i, 1f, 1f))); } renderer.setStroke(new BasicStroke(2.0f)); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator(Messages.Plot_Build() + " {1}: {2}", NumberFormat.getInstance())); renderer.setItemURLGenerator(new PointURLGenerator()); if (renderer instanceof LineAndShapeRenderer) { LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer; lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary } }
From source file:Verifier.java
/** * Verifies whether expectation is met based on the instance's values. * The values to compare are strings./* w w w. jav a 2s .c o m*/ * @throws Exception */ public void verifyStrings() throws Exception { String compareMode = getComp().toLowerCase(); String expected = getEv(); String actual = getAv(); // Special case - date-related components - these are strings but are derived from date values & manipulations if (expected.toLowerCase().startsWith("%date")) { // Convert the input to date components per the specs. // Expected value is string representation of date or its component(s) try { DDTDate dateParser = new DDTDate(getEv()); if (dateParser.hasException()) { addError(dateParser.getException().getMessage().toString()); return; } setEv(dateParser.getOutput()); expected = getEv(); } catch (Exception e) { addError("Exception in Date Parser: " + e.getCause().toString()); return; } } // Null protection if (isBlank(actual)) actual = ""; if (isBlank(expected)) expected = ""; if (getStripWhiteSpace()) { actual = Util.stripWhiteSpace(actual); expected = Util.stripWhiteSpace(expected); } // If comparison method not specified, get it from the settings. if (isBlank(compareMode)) compareMode = DDTSettings.Settings().defaultComparison().toLowerCase(); // Case sensitivity considerations if (getOpt().toLowerCase().equals("ignorecase") && compareMode != "islowercase" && compareMode != "isuppercase" && (isBlank(getCls()) || getCls().equalsIgnoreCase("string"))) { // convert both actual and expected values to lowercase expected = expected.toLowerCase(); actual = actual.toLowerCase(); } try { switch (compareMode.toLowerCase()) { // all booleans will be evaluated against the strings true/false case "equals": case "equal": case "is": case "eq": case "=": case "isenabled": case "isdisplayed": case "isselected": // NOTE: booleans are represented as string! { if (actual.equals(expected)) addComment(getStandardComment()); else addError(getStandardError()); break; } case "startswith": case "startwith": { if (actual.startsWith(expected)) addComment(getStandardComment()); else addError(getStandardError()); break; } case "endswith": case "endwith": { if (actual.endsWith(expected)) addComment(getStandardComment()); else addError(getStandardError()); break; } case "contains": case "contain": { if ((actual.contains(expected))) addComment(getStandardComment()); else addError(getStandardError()); break; } case "notcontains": case "notcontain": { if (actual.contains(expected)) addError(getStandardError()); else addComment(getStandardComment()); break; } case "islowercase": { if (actual.toLowerCase().equals(actual)) addComment(getStandardComment()); else addError(getStandardError()); break; } case "isuppercase": { if (actual.toUpperCase().equals(actual)) addComment(getStandardComment()); else addError(getStandardError()); break; } case "matches": case "match": { //@TODO case "matches" : the code below does not work when expression is evaluated in debugger - it does - WHY? //actual = ".*" + actual + ".*"; //if ((actual.matches(expected))) if (actual.matches(expected)) addComment(getStandardComment()); else addError(getStandardError()); break; } case "between": { String fromValue = null; String toValue = null; String blurb = ""; if (getValues().length == 2) { fromValue = values[0]; toValue = values[1]; if (fromValue.hashCode() > actual.hashCode() || toValue.hashCode() < actual.hashCode()) addError(getStandardError()); else addComment(getStandardComment()); } else addError("Invalid 'Between' String specifications."); break; } default: addError("Invalid comparison mode specified: " + Util.sq(getComp())); } // Switch } // Try catch (Exception e) { addError("Verifier generated general exception " + e.getCause().toString()); } }
From source file:github.daneren2005.dsub.service.RESTMusicService.java
private String getCachedIndexesFilename(Context context, String musicFolderId) { String s = Util.getRestUrl(context, null) + musicFolderId; return "indexes-" + Math.abs(s.hashCode()) + ".ser"; }
From source file:org.canova.api.conf.Configuration.java
/** * Get a local file name under a directory named in <i>dirsProp</i> with * the given <i>path</i>. If <i>dirsProp</i> contains multiple directories, * then one is chosen based on <i>path</i>'s hash code. If the selected * directory does not exist, an attempt is made to create it. * * @param dirsProp directory in which to locate the file. * @param path file-path./* w ww. java 2 s .c om*/ * @return local file under the directory with the given path. */ public File getFile(String dirsProp, String path) throws IOException { String[] dirs = getStrings(dirsProp); int hashCode = path.hashCode(); for (int i = 0; i < dirs.length; i++) { // try each local dir int index = (hashCode + i & Integer.MAX_VALUE) % dirs.length; File file = new File(dirs[index], path); File dir = file.getParentFile(); if (dir.exists() || dir.mkdirs()) { return file; } } throw new IOException("No valid local directories in property: " + dirsProp); }
From source file:cm.aptoide.pt.DownloadQueueService.java
public void startDownload(String localPath, DownloadNode downloadNode, String apkid, String[] login, Context context, boolean isUpdate) { this.context = context; HashMap<String, String> notification = new HashMap<String, String>(); notification.put("remotePath", downloadNode.repo + "/" + downloadNode.path); notification.put("md5hash", downloadNode.md5h); notification.put("apkid", apkid); notification.put("intSize", Integer.toString(downloadNode.size)); notification.put("intProgress", "0"); notification.put("localPath", localPath); notification.put("isUpdate", Boolean.toString(isUpdate)); /*Changed by Rafael Campos*/ notification.put("version", downloadNode.version); if (login != null) { notification.put("loginRequired", "true"); notification.put("username", login[0]); notification.put("password", login[1]); } else {//from ww w. j ava 2 s. c o m notification.put("loginRequired", "false"); } Log.d("Aptoide-DowloadQueueService", "download Started"); notifications.put(apkid.hashCode(), notification); setNotification(apkid.hashCode(), 0); downloadFile(apkid.hashCode()); }
From source file:com.igormaznitsa.zxpoly.MainForm.java
private RomData loadRom(final String romPath) throws IOException { if (romPath != null) { if (romPath.contains("://")) { try { final String cached = "loaded_" + Integer.toHexString(romPath.hashCode()).toUpperCase(Locale.ENGLISH) + ".rom"; final File cacheFolder = new File(AppOptions.getInstance().getAppConfigFolder(), "cache"); final File cachedRom = new File(cacheFolder, cached); RomData result = null;//from w w w. j a v a2s . c o m boolean load = true; if (cachedRom.isFile()) { log.info("Load cached ROM downloaded from '" + romPath + "' : " + cachedRom); result = new RomData(FileUtils.readFileToByteArray(cachedRom)); load = false; } if (load) { log.info("Load ROM from external URL: " + romPath); result = ROMLoader.getROMFrom(romPath); if (cacheFolder.isDirectory() || cacheFolder.mkdirs()) { FileUtils.writeByteArrayToFile(cachedRom, result.getAsArray()); log.info("Loaded ROM saved in cache as file : " + romPath); } } return result; } catch (Exception ex) { log.log(Level.WARNING, "Can't load ROM from '" + romPath + "\'", ex); } } else { log.info("Load ROM from embedded resource '" + romPath + "'"); return RomData.read(Utils.findResourceOrError("com/igormaznitsa/zxpoly/rom/" + romPath)); } } final String testRom = "zxpolytest.rom"; log.info("Load ROM from embedded resource '" + testRom + "'"); return RomData.read(Utils.findResourceOrError("com/igormaznitsa/zxpoly/rom/" + testRom)); }
From source file:de.innovationgate.wgpublisher.WGPDeployer.java
public synchronized DeployedLayout deployInlineTML(WGTMLModule tmlLib, String inlineName, String code, int codeOffset, ServletRequest req) throws DeployerException { if (tmlLib == null) { throw new DeployerException( "Tried to deploy tml module \"null\". Maybe a tml module is not accessible"); }/*from w ww . jav a 2 s . co m*/ DesignReference ref; try { ref = WGADesignManager.createDesignReference(tmlLib); } catch (WGAPIException e1) { throw new DeployerException("Error retrieving design reference for " + tmlLib.getDocumentKey(), e1); } String databaseKey = (String) tmlLib.getDatabase().getDbReference(); String resourceName = null; String mediaKey = null; try { String codeHash = String.valueOf(code.hashCode()); String layoutKey = ref.toString() + "///" + codeHash; if (tmlLib.isVariant()) { layoutKey = layoutKey + "//" + databaseKey; } DeployedLayout existingLayout = _layoutMappings.get(layoutKey); if (existingLayout != null) { return existingLayout; } req.setAttribute(REQATTRIB_TML_DEPLOYED, true); mediaKey = tmlLib.getMediaKey().toLowerCase(); if (_core.isMediaKeyDefined(mediaKey) == false) { _core.addMediaMapping(new MediaKey(mediaKey, "text/html", false, false), false); } String completeCode = buildTMLCode(tmlLib, "Inline " + inlineName + " of " + tmlLib.getName() + " (" + tmlLib.getMediaKey() + ")", layoutKey, code); resourceName = tmlLib.getName().toLowerCase(); LOG.debug("Deploying inline " + inlineName + " of tml " + mediaKey + "/" + resourceName + " (" + ref.getDesignProviderReference().toString() + ")"); return mapAndDeployLayout(tmlLib, layoutKey, completeCode); } catch (Exception e) { throw new DeployerException( "Error deploying tml " + databaseKey + "/" + resourceName + " (" + mediaKey + ")", e); } }
From source file:com.ery.dimport.daemon.TaskManager.java
public void runTask(final TaskInfo task) { List<LogHostRunInfoPO> allFiles = new ArrayList<LogHostRunInfoPO>(); try {//from w w w. j a va2 s. co m task.START_TIME = new Date(System.currentTimeMillis()); boolean needUpdate = false; TaskInfo exists = allTask.get(task.TASK_ID); if (exists == null) { needUpdate = true; } else { task.hosts = exists.hosts; } if (task.hosts == null || task.hosts.size() == 0) { task.hosts = new ArrayList<String>(master.getServerManager().getOnlineServers().keySet()); needUpdate = true; } if (ZKUtil.checkExists(watcher, watcher.dimportRunTaskNode + "/" + task.TASK_ID) == -1) { needUpdate = true; } if (needUpdate) { try { task.HOST_SIZE = task.hosts.size(); master.logWriter.writeLog(task); ZKUtil.createSetData(watcher, watcher.dimportRunTaskNode + "/" + task.TASK_ID, DImportConstant.Serialize(task)); } catch (Throwable e) { } } Thread thread = Thread.currentThread(); ProcessInfo procInfo = null; synchronized (taskInProgress) { procInfo = taskInProgress.get(task.getRunTaskId()); } procInfo.thread = thread; procInfo.startTime = System.currentTimeMillis(); procInfo.startTime = System.currentTimeMillis(); String filePath = task.FILE_PATH; boolean isInHdfs = false; final Map<String, Long> files = new HashMap<String, Long>(); String tmpPath = conf.get(DImportConstant.DIMPORT_PROCESS_TMPDATA_DIR, System.getProperty("user.home")); if (tmpPath.endsWith("/")) { tmpPath = tmpPath.substring(0, tmpPath.length() - 1); } if (filePath == null || filePath.equals("")) { files.put("", 0l); } else { if (task.fileNamePattern != null || (task.FILE_FILTER != null && !task.FILE_FILTER.equals(""))) { task.FILE_FILTER = DImportConstant.macroProcess(task.FILE_FILTER); task.FILE_FILTER = task.FILE_FILTER.replaceAll("\\{host\\}", this.master.hostName); task.fileNamePattern = Pattern.compile(task.FILE_FILTER); } Matcher m = hdfsUrlPattern.matcher(filePath); if (m.matches()) { isInHdfs = true; filePath = m.group(2); // for (String string : conf.getValByRegex(".*").keySet()) { // System.out.println(string + "=" + conf.get(string)); // } Path dirPath = new Path(filePath); FileSystem fs = FileSystem.get(HadoopConf.getConf(conf)); if (!fs.exists(dirPath) || !fs.isDirectory(dirPath)) { throw new IOException("HDFS? " + filePath + "?,?"); } FileStatus[] hFiles = fs.listStatus(dirPath, new PathFilter() { @Override public boolean accept(Path name) { if (task.fileNamePattern != null) { System.out.println("hdfs listStatus:" + name.getParent() + "/" + name.getName()); return task.fileNamePattern.matcher(name.getName()).matches(); } else { return true; } } }); for (int i = 0; i < hFiles.length; i++) { files.put(hFiles[i].getPath().toString(), hFiles[i].getLen()); } } else { java.io.File f = new File(filePath); if (!f.exists() || !f.isDirectory()) { throw new IOException( "? " + filePath + "? ,?"); } File[] lFiles = f.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { if (task.fileNamePattern != null) { System.out.println("local fs listStatus:" + dir + "/" + name); return task.fileNamePattern.matcher(name).matches(); } else { return true; } } }); for (int i = 0; i < lFiles.length; i++) { files.put(lFiles[i].getAbsolutePath(), lFiles[i].length()); } } } for (String fileName : files.keySet()) { LogHostRunInfoPO runInfo = new LogHostRunInfoPO(task); runInfo.RUN_LOG_ID = DImportConstant.shdf.format(task.SUBMIT_TIME) + "_" + allFiles.size() + "_" + fileName.hashCode(); runInfo.FILE_NAME = fileName; runInfo.RETURN_CODE = 255; runInfo.IS_RUN_SUCCESS = -1; runInfo.FILE_SIZE = files.get(fileName); runInfo.HOST_NAME = master.hostName; String localFile = fileName; if (isInHdfs) {// localFile = tmpPath + "/" + fileName.substring(fileName.lastIndexOf("/") + 1); } // String[] cmds = procInfo.task.getCommand(); for (int j = 0; j < cmds.length; j++) { cmds[j] = DImportConstant.macroProcess(cmds[j]); cmds[j] = cmds[j].replaceAll("\\{file\\}", localFile); cmds[j] = cmds[j].replaceAll("\\{host\\}", master.hostName); } runInfo.RUN_COMMAND = StringUtils.join(" ", cmds); master.logWriter.writeLog(runInfo); LOG.info("??" + runInfo); allFiles.add(runInfo); } ZKUtil.createSetData(watcher, watcher.dimportRunTaskNode + "/" + task.TASK_ID + "/" + master.hostName, DImportConstant.Serialize(allFiles)); for (LogHostRunInfoPO runInfo : allFiles) { if (procInfo.stoped) break; String fileName = runInfo.FILE_NAME; LOG.info("?:" + fileName); procInfo.RUN_LOG_ID = runInfo.RUN_LOG_ID; runInfo.START_TIME = new Date(System.currentTimeMillis()); procInfo.processFile = fileName; String localFile = fileName; try { if (isInHdfs) {// localFile = tmpPath + "/" + fileName.substring(fileName.lastIndexOf("/") + 1); } procInfo.task.TASK_COMMAND = runInfo.RUN_COMMAND; if (isInHdfs) {// File lf = new File(localFile); if (lf.exists()) lf.delete(); FileSystem fs = FileSystem.get(HadoopConf.getConf(conf)); LOG.info("HDFS:" + fileName + "===>" + localFile); long btime = System.currentTimeMillis(); fs.copyToLocalFile(new Path(fileName), new Path(localFile)); LOG.info("HDFS?:" + fileName + "===>" + localFile); runInfo.downTime = System.currentTimeMillis() - btime; fileName = localFile; } updateHostInfoLog(runInfo, allFiles); LOG.info(procInfo.task.TASK_NAME + " commandline: " + procInfo.task.TASK_COMMAND); procInfo.proc = execResult(runInfo.RUN_COMMAND); runInfo.IS_RUN_SUCCESS = 1; runInfo.RETURN_CODE = writeProcessLog(procInfo); LOG.info(procInfo.task.TASK_NAME + " return value: " + runInfo.RETURN_CODE); // runInfo.RETURN_CODE = procInfo.proc.exitValue(); } catch (Throwable e) { runInfo.ERROR_MSG = e.getMessage(); if (procInfo.proc != null) { try { procInfo.proc.destroy(); } catch (Exception ex) { } } procInfo.proc = null; LOG.error("", e); } finally { // runInfo.END_TIME = new Date(System.currentTimeMillis()); master.logWriter.updateLog(runInfo); updateHostInfoLog(runInfo, allFiles); ZKUtil.createSetData(watcher, watcher.dimportRunTaskNode + "/" + task.TASK_ID + "/" + master.hostName, DImportConstant.Serialize(allFiles)); if (isInHdfs) { File lf = new File(localFile); if (lf.exists()) lf.delete(); } } } } catch (Throwable e) { LOG.error("" + task, e); try { if (allFiles.size() > 0) { for (LogHostRunInfoPO logHostRunInfoPO : allFiles) { if (logHostRunInfoPO.END_TIME.getTime() < 10000) { logHostRunInfoPO.END_TIME = new Date(System.currentTimeMillis()); logHostRunInfoPO.IS_RUN_SUCCESS = 1; logHostRunInfoPO.RETURN_CODE = 2; } } ZKUtil.createSetData(watcher, watcher.dimportRunTaskNode + "/" + task.TASK_ID + "/" + master.hostName, DImportConstant.Serialize(allFiles)); } } catch (KeeperException e1) { LOG.error("update task run info on host :" + watcher.dimportRunTaskNode + "/" + task.TASK_ID + "/" + master.hostName, e); } catch (IOException e1) { LOG.error("update task run info on host " + watcher.dimportRunTaskNode + "/" + task.TASK_ID + "/" + master.hostName, e); } } finally { // synchronized (taskInProgress) { taskInProgress.remove(task.getRunTaskId()); } } }
From source file:com.clustercontrol.ws.collect.CollectEndpoint.java
/** * //from w ww . ja v a2s .c om * ID????ID?????HashMap???? * * CollectRead??? * * @param itemCode ? * @param displayName ??() * @param facilityIdList ID? * @return ID????ID?????HashMap * @throws InvalidRole * @throws InvalidUserPass * @throws HinemosUnknown */ public HashMapInfo getCollectId(String itemName, String displayName, String monitorId, List<String> facilityIdList) throws InvalidUserPass, InvalidRole, HinemosUnknown { m_log.debug("getCollectId"); ArrayList<SystemPrivilegeInfo> systemPrivilegeList = new ArrayList<SystemPrivilegeInfo>(); systemPrivilegeList.add(new SystemPrivilegeInfo(FunctionConstant.COLLECT, SystemPrivilegeMode.READ)); HttpAuthenticator.authCheck(wsctx, systemPrivilegeList); // ??? m_opelog.debug(HinemosModuleConstant.LOG_PREFIX_PERFORMANCE + " Get, Method=getCollectId, User=" + HttpAuthenticator.getUserAccountString(wsctx)); HashMap<String, Integer> map = new HashMap<>(); //? if (debug) { for (String facilityId : facilityIdList) { int id = 0; id += itemName.hashCode(); id *= 37; if (displayName != null) { id += displayName.hashCode(); } id *= 37; id += facilityId.hashCode(); map.put(facilityId, id); } } else { //???? for (String facilityId : facilityIdList) { m_log.debug("itemName:" + itemName + ", displayName:" + displayName + ", monitorId:" + monitorId + ", facilityId:" + facilityId); Integer id = null; try { id = new CollectControllerBean().getCollectId(itemName, displayName, monitorId, facilityId); } catch (Exception e) { m_log.debug(e.getClass().getName() + ", itemName:" + itemName + ", displayName:" + displayName + ", monitorId:" + monitorId + ", facilityId:" + facilityId); } map.put(facilityId, id); } } HashMapInfo ret = new HashMapInfo(); ret.setMap4(map); return ret; }
From source file:com.xpn.xwiki.plugin.invitationmanager.impl.InvitationManagerImpl.java
/** * @return the encoded email address to be used when naming the document (wiki page) storing the * invitation to the unregistered user with the given email address *///w ww .j a va2 s . co m private String encodeEmailAddress(String emailAddress) { return emailAddress.hashCode() + ""; }