List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:com.actelion.research.spiritcore.services.SampleListValidator.java
private boolean columnHasDuplicates(String[][] data, int col) { HashMap<String, Integer> values = new HashMap<String, Integer>(); for (int i = 1; i < data.length; i++) { String val = data[i][col]; if (val == null || val.isEmpty()) { continue; }//from w w w . j a v a2 s . c o m if (values.containsKey(data[i][col])) { specificErrorMessage = "Value '" + val + "' has been found at lines " + (values.get(val) + 1) + " and " + (i + 1); return true; } else { values.put(val, i); } } return false; }
From source file:de.uni_potsdam.hpi.bpt.promnicat.persistenceApi.orientdbObj.index.IndexIntersection.java
/** * Load the intersecting referenced objects from the specified indices. * First load the database ids from all indices, intersect them, and load the remaining ids. * /*from www.j a va2s . co m*/ * @return the resulting {@link IndexCollectionElement}s */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Collection<IndexCollectionElement<V>> load() { //load dbIds only and sort them by result set size TreeList rawResults = new TreeList(); //no generics possible int maxSize = 0; for (AbstractIndex index : indices) { ResultSet<V> oneResultSet = new ResultSet<V>(index.loadIdsOnly(), index.getName()); rawResults.add(oneResultSet); maxSize = Math.max(maxSize, oneResultSet.getSize()); } // create a list of intersecting dbIds // start with the smallest result set and intersect with the second smallest, intersect this result with the third smallest a.s.o. HashSet<String> intersectingDbIds = new HashSet<String>(maxSize); for (Object r : rawResults) { ResultSet<V> aResult = (ResultSet<V>) r; if (intersectingDbIds.isEmpty()) { intersectingDbIds.addAll(aResult.getDbIds()); } else { intersectingDbIds.retainAll(aResult.getDbIds()); } if (intersectingDbIds.isEmpty()) { break; } } //create Map of IndexElements each, i.e. group by referenced id. Every group is stored in a IndexCollectedElement HashMap<String, IndexCollectionElement<V>> finalElements = new HashMap<String, IndexCollectionElement<V>>( indices.size()); for (Object r : rawResults) { ResultSet<V> aResult = (ResultSet<V>) r; for (IndexElement indexElement : aResult.getList()) { String currentString = indexElement.getDbId(); if (intersectingDbIds.contains(currentString)) { if (!finalElements.containsKey(currentString)) { finalElements.put(currentString, new IndexCollectionElement<V>(currentString)); } finalElements.get(currentString).addIndexElements(indexElement); } } } //load pojos for (IndexCollectionElement<V> collectionElement : finalElements.values()) { collectionElement.loadPojo(papi); } return finalElements.values(); }
From source file:com.propelics.pdfcreator.PdfcreatorModule.java
private void generateiTextPDFfunction(HashMap args) { Log.d(PROXY_NAME, "generateiTextPDFfunction()"); String filename = ""; TiUIView webview = null;/* w w w . jav a 2s. co m*/ int quality = 100; try { if (args.containsKey("filename")) { filename = (String) args.get("filename"); Log.d(PROXY_NAME, "filename: " + filename); } else return; if (args.containsKey("webview")) { TiViewProxy viewProxy = (TiViewProxy) args.get("webview"); webview = viewProxy.getOrCreateView(); Log.d(PROXY_NAME, "webview: " + webview.toString()); } else return; if (args.containsKey("quality")) { quality = TiConvert.toInt(args.get("quality")); } TiBaseFile file = TiFileFactory.createTitaniumFile(filename, true); Log.d(PROXY_NAME, "file full path: " + file.nativePath()); OutputStream outputStream = file.getOutputStream(); final int MARGIN = 0; final float PDF_WIDTH = PageSize.LETTER.getWidth() - MARGIN * 2; // A4: 595 //Letter: 612 final float PDF_HEIGHT = PageSize.LETTER.getHeight() - MARGIN * 2; // A4: 842 //Letter: 792 final int DEFAULT_VIEW_WIDTH = 980; final int DEFAULT_VIEW_HEIGHT = 1384; int viewWidth = DEFAULT_VIEW_WIDTH; int viewHeight = DEFAULT_VIEW_HEIGHT; Document pdfDocument = new Document(PageSize.LETTER, MARGIN, MARGIN, MARGIN, MARGIN); PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream); Log.d(PROXY_NAME, "PDF_WIDTH: " + PDF_WIDTH); Log.d(PROXY_NAME, "PDF_HEIGHT: " + PDF_HEIGHT); WebView view = (WebView) webview.getNativeView(); if (TiApplication.isUIThread()) { viewWidth = view.capturePicture().getWidth(); viewHeight = view.capturePicture().getHeight(); if (viewWidth <= 0) { viewWidth = DEFAULT_VIEW_WIDTH; } if (viewHeight <= 0) { viewHeight = DEFAULT_VIEW_HEIGHT; } } else { Log.e(PROXY_NAME, "NO UI THREAD"); viewWidth = DEFAULT_VIEW_WIDTH; viewHeight = DEFAULT_VIEW_HEIGHT; } view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); Log.d(PROXY_NAME, "viewWidth: " + viewWidth); Log.d(PROXY_NAME, "viewHeight: " + viewHeight); float scaleFactorWidth = 1 / (viewWidth / PDF_WIDTH); float scaleFactorHeight = 1 / (viewHeight / PDF_HEIGHT); Log.d(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth); Log.d(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight); Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888); Canvas viewCanvas = new Canvas(viewBitmap); // Paint paintAntialias = new Paint(); // paintAntialias.setAntiAlias(true); // paintAntialias.setFilterBitmap(true); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(viewCanvas); } else { viewCanvas.drawColor(Color.WHITE); } view.draw(viewCanvas); TiBaseFile pdfImg = createTempFile(filename); viewBitmap.compress(Bitmap.CompressFormat.PNG, quality, pdfImg.getOutputStream()); FileInputStream pdfImgInputStream = new FileInputStream(pdfImg.getNativeFile()); byte[] pdfImgBytes = IOUtils.toByteArray(pdfImgInputStream); pdfImgInputStream.close(); pdfDocument.open(); float yFactor = viewHeight * scaleFactorWidth; int pageNumber = 1; do { if (pageNumber > 1) { pdfDocument.newPage(); } pageNumber++; yFactor -= PDF_HEIGHT; Image pageImage = Image.getInstance(pdfImgBytes, true); // Image pageImage = Image.getInstance(buffer.array()); pageImage.scalePercent(scaleFactorWidth * 100); pageImage.setAbsolutePosition(0f, -yFactor); pdfDocument.add(pageImage); Log.d(PROXY_NAME, "yFactor: " + yFactor); } while (yFactor > 0); pdfDocument.close(); sendCompleteEvent(filename); } catch (Exception exception) { sendErrorEvent(exception); } }
From source file:africastalkinggateway.AfricasTalkingGateway.java
public JSONArray sendMessage(String to_, String message_, String from_, int bulkSMSMode_, HashMap<String, String> options_) throws Exception { HashMap<String, String> data = new HashMap<String, String>(); data.put("username", _username); data.put("to", to_); data.put("message", message_); if (from_.length() > 0) data.put("from", from_); data.put("bulkSMSMode", Integer.toString(bulkSMSMode_)); if (options_.containsKey("enqueue")) data.put("enqueue", options_.get("enqueue")); if (options_.containsKey("keyword")) data.put("keyword", options_.get("keyword")); if (options_.containsKey("linkId")) data.put("linkId", options_.get("linkId")); if (options_.containsKey("retryDurationInHours")) data.put("retryDurationInHours", options_.get("retryDurationInHours")); return sendMessageImpro(to_, message_, data); }
From source file:datafu.test.pig.sessions.SessionTests.java
@Test public void sessionizeTest() throws Exception { PigTest test = createPigTestFromString(sessionizeTest, "TIME_WINDOW=30m", "TIME_TYPE=chararray"); this.writeLinesToFile("input", inputData); test.runScript();//from w w w .j a v a 2s . c o m HashMap<Integer, HashMap<Integer, Boolean>> userValues = new HashMap<Integer, HashMap<Integer, Boolean>>(); for (Tuple t : this.getLinesForAlias(test, "max_value")) { Integer userId = (Integer) t.get(0); Integer max = (Integer) t.get(1); if (!userValues.containsKey(userId)) { userValues.put(userId, new HashMap<Integer, Boolean>()); } userValues.get(userId).put(max, true); } assertEquals(userValues.get(1).size(), 2); assertEquals(userValues.get(2).size(), 5); assertEquals(userValues.get(3).size(), 1); assertTrue(userValues.get(1).containsKey(20)); assertTrue(userValues.get(1).containsKey(30)); assertTrue(userValues.get(2).containsKey(10)); assertTrue(userValues.get(2).containsKey(20)); assertTrue(userValues.get(2).containsKey(30)); assertTrue(userValues.get(2).containsKey(40)); assertTrue(userValues.get(2).containsKey(50)); assertTrue(userValues.get(3).containsKey(50)); }
From source file:gwap.game.quiz.tools.QuizQuestionBean.java
private HashMap<String, Integer> cleanUpAndGetTaggins(Set<Tagging> taggings) { HashMap<String, Integer> tagMap = new HashMap<String, Integer>(); for (Tagging tagging : taggings) { Tag tag = tagging.getTag();//from w w w . j a v a 2 s .com if (tag != null && tag.getLanguage() != null && tag.getBlacklisted() != null) { if (!tag.getBlacklisted() && tag.getLanguage().equals("de")) { String name = tag.getName(); if (tagMap.containsKey(name)) { tagMap.put(name, tagMap.get(name) + 1); } else { tagMap.put(tag.getName(), 1); } } } } return tagMap; }
From source file:WebCategorizer.java
public void getWebCategories(HashSet<String> urlSet, HashMap<String, String> websiteCategoryMap, MongoCollection<org.bson.Document> websiteCategoryCollection) { try {//from w w w . j a v a 2 s. co m File file = new File(categoriesFile); JSONObject webCatList = new JSONObject(); if (file.exists() && file.length() != 0) { webCatList = loadCategories(); } else { webCatList = fetchCategories(); } for (String url : urlSet) { if (websiteCategoryMap.containsKey(url)) continue; org.bson.Document urlDoc = websiteCategoryCollection.find(eq("URLDomain", url)).first(); if (urlDoc == null) { String host = ""; String port = ""; if (url.indexOf(':') > -1) { String[] urlAddr = url.split(":"); host = urlAddr[0]; port = urlAddr[1]; } else { host = url; port = "80"; } StringBuilder remoteUrl = new StringBuilder("http://sp.cwfservice.net/1/R/"); remoteUrl.append(k9License); remoteUrl.append("/K9-00006/0/GET/HTTP/"); remoteUrl.append(host); remoteUrl.append("/"); remoteUrl.append(port); remoteUrl.append("///"); //Fetch Key for URL URL obj = new URL(remoteUrl.toString()); URLConnection connection = obj.openConnection(); Document doc = parseXML(connection.getInputStream()); NodeList descNodes = doc.getElementsByTagName("DomC"); if (descNodes.getLength() != 0) { String cat = (String) webCatList .get(breakString(descNodes.item(0).getTextContent().toLowerCase())); websiteCategoryMap.put(url, cat); websiteCategoryCollection.insertOne(new org.bson.Document("URLId", url.hashCode()) .append("URLDomain", url.toString()).append("URLCategory", cat)); } else { descNodes = doc.getElementsByTagName("DirC"); String cat = (String) webCatList .get(breakString(descNodes.item(0).getTextContent().toLowerCase())); websiteCategoryMap.put(url, cat); websiteCategoryCollection.insertOne(new org.bson.Document("URLId", url.hashCode()) .append("URLDomain", url.toString()).append("URLCategory", cat)); } } else { websiteCategoryMap.put(url, new JSONObject(urlDoc.toJson()).get("URLCategory").toString()); } } } catch (Exception ex) { System.out.println(ex.getClass().getName()); System.out.println("Not working"); } }
From source file:com.redhat.jenkins.plugins.ci.CIBuildTrigger.java
private List<ParameterValue> getUpdatedParameters(Map<String, String> messageParams, List<ParameterValue> definedParams) { // Update any build parameters that may have values from the triggering message. HashMap<String, ParameterValue> newParams = new HashMap<String, ParameterValue>(); for (ParameterValue def : definedParams) { newParams.put(def.getName(), def); }/* w w w .j a va 2s.c om*/ for (String key : messageParams.keySet()) { if (newParams.containsKey(key)) { StringParameterValue spv = new StringParameterValue(key, messageParams.get(key)); newParams.put(key, spv); } } return new ArrayList<ParameterValue>(newParams.values()); }
From source file:datafu.test.pig.sessions.SessionTests.java
@Test public void sessionizeLongTest() throws Exception { PigTest test = createPigTestFromString(sessionizeTest, "TIME_WINDOW=30m", "TIME_TYPE=long"); List<String> lines = new ArrayList<String>(); for (String line : inputData) { String[] parts = line.split("\t"); Assert.assertEquals(3, parts.length); parts[0] = Long.toString(dateFormat.parse(parts[0]).getTime()); lines.add(StringUtils.join(parts, "\t")); }//from w w w .j ava 2 s . c o m this.writeLinesToFile("input", lines.toArray(new String[] {})); test.runScript(); HashMap<Integer, HashMap<Integer, Boolean>> userValues = new HashMap<Integer, HashMap<Integer, Boolean>>(); for (Tuple t : this.getLinesForAlias(test, "max_value")) { Integer userId = (Integer) t.get(0); Integer max = (Integer) t.get(1); if (!userValues.containsKey(userId)) { userValues.put(userId, new HashMap<Integer, Boolean>()); } userValues.get(userId).put(max, true); } assertEquals(userValues.get(1).size(), 2); assertEquals(userValues.get(2).size(), 5); assertTrue(userValues.get(1).containsKey(20)); assertTrue(userValues.get(1).containsKey(30)); assertTrue(userValues.get(2).containsKey(10)); assertTrue(userValues.get(2).containsKey(20)); assertTrue(userValues.get(2).containsKey(30)); assertTrue(userValues.get(2).containsKey(40)); assertTrue(userValues.get(2).containsKey(50)); }
From source file:edu.umass.cs.gigapaxos.PaxosPacketBatcher.java
private boolean enqueueImpl(BatchedCommit commit) { if (!this.commits.containsKey(commit.getPaxosID())) this.commits.put(commit.getPaxosID(), new HashMap<Ballot, BatchedCommit>()); HashMap<Ballot, BatchedCommit> cMap = this.commits.get(commit.getPaxosID()); boolean added = false; if (cMap.isEmpty()) added = (cMap.put(commit.ballot, (commit)) != null); else if (cMap.containsKey(commit.ballot)) added = cMap.get(commit.ballot).addBatchedCommit(commit); else//from w w w.j a va2 s . c o m added = (cMap.put(commit.ballot, (commit)) != null); return added; }