List of usage examples for java.util HashSet contains
public boolean contains(Object o)
From source file:com.pinterest.deployservice.db.DBDAOTest.java
@Test public void testGroupDAO() throws Exception { groupDAO.addGroupCapacity("env-id3", "group3"); groupDAO.addGroupCapacity("env-id4", "group4"); groupDAO.addGroupCapacity("env-id5", "group3"); List<String> envids = groupDAO.getEnvsByGroupName("group3"); assertEquals(envids.size(), 2);//from w w w .ja v a2 s. co m HashSet<String> target_ids = new HashSet<>(); target_ids.addAll(envids); assertTrue(target_ids.contains("env-id3")); assertTrue(target_ids.contains("env-id5")); List<String> groups = groupDAO.getAllEnvGroups(); assertEquals(groups.size(), 2); }
From source file:com.sonicle.webtop.vfs.VfsManager.java
public List<StoreShareRoot> listIncomingStoreRoots() throws WTException { CoreManager core = WT.getCoreManager(getTargetProfileId()); ArrayList<StoreShareRoot> roots = new ArrayList(); HashSet<String> hs = new HashSet<>(); List<IncomingShareRoot> shares = core.listIncomingShareRoots(SERVICE_ID, GROUPNAME_STORE); for (IncomingShareRoot share : shares) { SharePermsRoot perms = core.getShareRootPermissions(share.getShareId()); StoreShareRoot root = new StoreShareRoot(share, perms); if (hs.contains(root.getShareId())) continue; // Avoid duplicates ?????????????????????? hs.add(root.getShareId());//from w ww. j av a 2 s . c o m roots.add(root); } return roots; }
From source file:edu.cens.loci.provider.LociDbUtils.java
public ArrayList<String> getSavedKeywords() { Cursor cursor = getPlaceData(Keyword.CONTENT_ITEM_TYPE); HashSet<String> keywordSet = new HashSet<String>(); if (cursor.moveToFirst()) { do {/*from ww w . j a v a2 s. c om*/ String keyword = cursor.getString(cursor.getColumnIndex(Keyword.TAG)); if (!keywordSet.contains(keyword)) { keywordSet.add(keyword); } } while (cursor.moveToNext()); } cursor.close(); Object[] keywordObjArray = keywordSet.toArray(); ArrayList<String> keywordArray = new ArrayList<String>(); for (Object keywordObj : keywordObjArray) { keywordArray.add((String) keywordObj); } Collections.sort(keywordArray); return keywordArray; }
From source file:org.jfree.data.xy.DefaultTableXYDataset.java
/** * Adds any unique x-values from 'series' to the dataset, and also adds any * x-values that are in the dataset but not in 'series' to the series. * * @param series the series (<code>null</code> not permitted). *//*from ww w . ja va 2s .c om*/ private void updateXPoints(XYSeries series) { ParamChecks.nullNotPermitted(series, "series"); HashSet seriesXPoints = new HashSet(); boolean savedState = this.propagateEvents; this.propagateEvents = false; for (int itemNo = 0; itemNo < series.getItemCount(); itemNo++) { Number xValue = series.getX(itemNo); seriesXPoints.add(xValue); if (!this.xPoints.contains(xValue)) { this.xPoints.add(xValue); int seriesCount = this.data.size(); for (int seriesNo = 0; seriesNo < seriesCount; seriesNo++) { XYSeries dataSeries = (XYSeries) this.data.get(seriesNo); if (!dataSeries.equals(series)) { dataSeries.add(xValue, null); } } } } Iterator iterator = this.xPoints.iterator(); while (iterator.hasNext()) { Number xPoint = (Number) iterator.next(); if (!seriesXPoints.contains(xPoint)) { series.add(xPoint, null); } } this.propagateEvents = savedState; }
From source file:edu.msu.cme.rdp.multicompare.MultiClassifier.java
/** * Input files are the classification results * printRank indicates which rank to filter by the confidence for the detail assignment output * taxonFilter indicates which taxon to match for the detail assignment output *//*from w w w. jav a 2 s . c o m*/ public MultiClassifierResult multiClassificationParser(List<MCSample> samples, float confidence, PrintWriter assign_out, ClassificationResultFormatter.FORMAT format, String printRank, HashSet<String> taxonFilter) throws IOException { HierarchyTree sampleTreeRoot = classifierFactory.getRoot(); ConcretRoot<MCTaxon> root = new ConcretRoot<MCTaxon>( new MCTaxon(sampleTreeRoot.getTaxid(), sampleTreeRoot.getName(), sampleTreeRoot.getRank())); List<String> badSequences = new ArrayList(); Map<String, Long> seqCountMap = new HashMap(); for (MCSample sample : samples) { ClassificationParser parser = ((MCSampleResult) sample).getClassificationParser(classifierFactory); ClassificationResult result; while ((result = parser.next()) != null) { processClassificationResult(result, sample, root, confidence, seqCountMap); List<RankAssignment> assignList = result.getAssignments(); if (printRank == null) { printRank = assignList.get(assignList.size() - 1).getRank(); } boolean match = false; if (taxonFilter == null) { match = true; } else { for (RankAssignment assign : assignList) { if (taxonFilter.contains(assign.getBestClass().getName())) { match = true; break; } } } if (match) { for (RankAssignment assign : assignList) { if (assign.getRank().equalsIgnoreCase(printRank) && assign.getConfidence() >= confidence) { printClassificationResult(result, assign_out, format, confidence); break; } } } } parser.close(); } return new MultiClassifierResult(root, samples, badSequences, seqCountMap); }
From source file:blusunrize.immersiveengineering.common.items.ItemRevolver.java
@SideOnly(Side.CLIENT) @Override// ww w.j a v a 2 s .c o m public boolean shouldRenderGroup(ItemStack stack, String group) { if (group.equals("frame") || group.equals("cylinder") || group.equals("barrel") || group.equals("cosmetic_compensator")) return true; HashSet<String> render = new HashSet<String>(); String tag = ItemNBTHelper.getString(stack, "elite"); String flavour = ItemNBTHelper.getString(stack, "flavour"); if (tag != null && !tag.isEmpty() && specialRevolversByTag.containsKey(tag)) { SpecialRevolver r = specialRevolversByTag.get(tag); if (r != null && r.renderAdditions != null) for (String ss : r.renderAdditions) render.add(ss); } else if (flavour != null && !flavour.isEmpty() && specialRevolversByTag.containsKey(flavour)) { SpecialRevolver r = specialRevolversByTag.get(flavour); if (r != null && r.renderAdditions != null) for (String ss : r.renderAdditions) render.add(ss); } NBTTagCompound upgrades = this.getUpgrades(stack); if (upgrades.getInteger("bullets") > 0 && !render.contains("dev_mag")) render.add("player_mag"); if (upgrades.getDouble("melee") > 0 && !render.contains("dev_bayonet")) { render.add("bayonet_attachment"); render.add("player_bayonet"); } if (upgrades.getBoolean("electro")) { render.add("player_electro_0"); render.add("player_electro_1"); } return render.contains(group); }
From source file:fr.openwide.talendalfresco.rest.client.RestAuthenticationTest.java
public void testRestLogin() { // create client and configure it HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); // instantiating a new method and configuring it GetMethod method = new GetMethod(restCommandUrlPrefix + "login"); method.setFollowRedirects(true); // ? // Provide custom retry handler is necessary (?) method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); NameValuePair[] params = new NameValuePair[] { new NameValuePair("username", "admin"), new NameValuePair("password", "admin") }; method.setQueryString(params);// w ww . ja v a 2 s.c om try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); // TODO rm HashSet<String> defaultElementSet = new HashSet<String>( Arrays.asList(new String[] { RestConstants.TAG_COMMAND, RestConstants.TAG_CODE, RestConstants.TAG_CONTENT, RestConstants.TAG_ERROR, RestConstants.TAG_MESSAGE })); HashMap<String, String> elementValueMap = new HashMap<String, String>(6); try { XMLEventReader xmlReader = XmlHelper.getXMLInputFactory() .createXMLEventReader(new ByteArrayInputStream(responseBody)); StringBuffer singleLevelTextBuf = null; while (xmlReader.hasNext()) { XMLEvent event = xmlReader.nextEvent(); switch (event.getEventType()) { case XMLEvent.CHARACTERS: case XMLEvent.CDATA: if (singleLevelTextBuf != null) { singleLevelTextBuf.append(event.asCharacters().getData()); } // else element not meaningful break; case XMLEvent.START_ELEMENT: StartElement startElement = event.asStartElement(); String elementName = startElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName) // TODO another command specific level || "ticket".equals(elementName)) { // reinit buffer at start of meaningful elements singleLevelTextBuf = new StringBuffer(); } else { singleLevelTextBuf = null; // not useful } break; case XMLEvent.END_ELEMENT: if (singleLevelTextBuf == null) { break; // element not meaningful } // TODO or merely put it in the map since the element has been tested at start EndElement endElement = event.asEndElement(); elementName = endElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName)) { String value = singleLevelTextBuf.toString(); elementValueMap.put(elementName, value); // TODO test if it is code and it is not OK, break to error handling } // TODO another command specific level else if ("ticket".equals(elementName)) { ticket = singleLevelTextBuf.toString(); } // singleLevelTextBuf = new StringBuffer(); // no ! in start break; } } } catch (XMLStreamException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Throwable t) { // TODO Auto-generated catch block t.printStackTrace(); //throw t; } String code = elementValueMap.get(RestConstants.TAG_CODE); assertTrue(RestConstants.CODE_OK.equals(code)); System.out.println("got ticket " + ticket); } catch (HttpException e) { // TODO e.printStackTrace(); } catch (IOException e) { // TODO e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } }
From source file:com.almarsoft.GroundhogReader.MessageListActivity.java
private void markUserMessagesAsRead(String from) { // Proxy stuff String msgId;/* www .jav a 2 s . co m*/ Article article; ArrayList<HeaderItemClass> proxyHeaderItems = mHeaderItemsList; HashSet<String> proxyReadSet = mReadSet; int headerItemsSize = proxyHeaderItems.size(); int proxyNumUnread = mNumUnread; // End proxy stuff for (int i = 0; i < headerItemsSize; i++) { article = proxyHeaderItems.get(i).getArticle(); if (from.equalsIgnoreCase(article.getFrom())) { msgId = article.getArticleId(); DBUtils.markAsRead(msgId, getApplicationContext()); if (!proxyReadSet.contains(msgId)) proxyNumUnread--; } } mNumUnread = proxyNumUnread; mTitleBar.setText(mGroup + ":" + mNumUnread); mReadSet = DBUtils.getReadMessagesSet(mGroup, getApplicationContext()); DBUtils.updateUnreadInGroupsTable(mNumUnread, mGroupID, getApplicationContext()); mMsgList.invalidateViews(); }
From source file:com.samsung.sjs.constraintsolver.TypeConstraintFixedPointSolver.java
/** * Substitutes type solutions for type variables where applicable. * Also, replaces appearances of the Any type with Integer, to * aid in code generation//from ww w . j av a 2s. c o m * @param type * @param inProgress */ public void substituteTypeVars(Type type) { logger.debug("substituting type variables in {}", type); final HashSet<Type> inProgress = HashSetFactory.make(); traverseAndUpdateType(type, inProgress, (t, context) -> { if (t instanceof TypeVar) { logger.trace("substituting for type variable {}", t); TypeVariableTerm tvarTerm = factory.findOrCreateTypeVariableTerm((TypeVar) t); Type result = tvarTerm.getType(); logger.trace("subst result: {}", result); return result; } else if (t instanceof ObjectType && !inProgress.contains(t)) { // This is subtle. In some cases, we have many ObjectType objects // representing equivalent types in the final solution. Performing // the same substitutions on these types repeatedly can be a performance // bottleneck. So here, if we detect an equivalent object type, we return // the representative type we already encountered, reducing the number of // substitutions performed. // TODO devise a more principled solution to this problem, likely involving // making ObjectTypes truly immutable for (Type t2 : inProgress) { if (Types.isEqual(t, t2)) { return t2; } } return t; } else { return t; } }); }
From source file:ch.dbs.actions.bestand.Stock.java
/** * Checks that each Bestand() has all necessary entries and belongs to the * account uploading the file./*from w w w . j a v a2s . c om*/ * * @param List <Bestand> * @param UserInfo * @param Connection * @return List<Message> */ private List<Message> checkBestandIntegrity(final List<Bestand> bestandList, final UserInfo ui, final Connection cn) { final List<Message> messageList = new ArrayList<Message>(); final HashSet<Long> uniqueSetStockID = new HashSet<Long>(); int lineCount = 1; // the header of the ArrayList<Bestand> is already omitted for (final Bestand b : bestandList) { lineCount++; if (b.getId() != null) { // check for unique Stock-ID if (uniqueSetStockID.contains(b.getId())) { final Message msg = new Message(); msg.setMessage("error.import.stid.notUnique"); msg.setSystemMessage(composeSystemMessage(lineCount, b.getId())); messageList.add(msg); } else { // if not found add Stock-ID uniqueSetStockID.add(b.getId()); } // check if Bestand is from account // internal holdings are visible final Bestand control = new Bestand(b.getId(), true, cn); // get control Bestand from specified ID // check if KID from Bestand matches KID from ui if (control.getHolding() != null && control.getHolding().getKid().equals(ui.getKonto().getId())) { // check if Holding-ID from control matches Holding-ID specified if (!control.getHolding().getId().equals(b.getHolding().getId())) { final Message msg = new Message(); msg.setMessage("error.import.hoid.doesNotMatchStid"); msg.setSystemMessage(composeSystemMessage(lineCount, b.getHolding().getId())); messageList.add(msg); } } else { // KID from Bestand does not match KID from ui! final Message msg = new Message(); msg.setMessage("error.import.stid.notFromAccount"); msg.setSystemMessage(composeSystemMessage(lineCount, b.getId())); messageList.add(msg); } } // check location-ID and location if (b.getStandort().getId() != null) { // check if location-ID is from account // get control location from specified ID final Text control = new Text(cn, b.getStandort().getId(), ui.getKonto().getId(), TextType.LOCATION); if (control.getId() == null) { // Location-ID does not belong to account final Message msg = new Message(); msg.setMessage("error.import.locationid"); msg.setSystemMessage(composeSystemMessage(lineCount, b.getStandort().getId())); messageList.add(msg); // Location-ID belongs to account, but do the locations match? } else if (!b.getStandort().getInhalt().equals("") && !b.getStandort().getInhalt().equals(control.getInhalt())) { // locations do not match... final Message msg = new Message(); msg.setMessage("error.import.locationsDoNotMatch"); if (b.getStandort().getId() != null) { msg.setSystemMessage(composeSystemMessage(lineCount, b.getStandort().getId().toString() + "/" + b.getStandort().getInhalt())); } else { msg.setSystemMessage( composeSystemMessage(lineCount, "null/" + b.getStandort().getInhalt())); } messageList.add(msg); } } else if (b.getStandort().getInhalt().equals("")) { // check if location is present final Message msg = new Message(); msg.setMessage("error.import.location"); msg.setSystemMessage(composeSystemMessage(lineCount, b.getStandort().getInhalt())); messageList.add(msg); } // if there is an endvolume or and endissue => there must be an endyear if ((!"".equals(b.getEndvolume()) || !"".equals(b.getEndissue())) && "".equals(b.getEndyear())) { final Message msg = new Message(); msg.setMessage("error.import.endyear"); msg.setSystemMessage(composeSystemMessage(lineCount, "")); messageList.add(msg); } } return messageList; }