List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:com.bibisco.manager.SceneTagsManager.java
/** * @return a Map as/* w ww. j a v a 2 s . c o m*/ * * Chapter.1 Chapter.2 Chapter.3 * - pointOfView.1 - X X * - pointOfView.2 - X * - pointOfView.3 - X X * */ public static Map<String, List<Boolean>> getPointOfViewsChaptersPresence() { Map<String, List<Boolean>> lMapPointOfViewChapterPresence = new HashMap<String, List<Boolean>>(); mLog.debug("Start getPointOfViewsChaptersDistribution()"); List<PointOfView4AnalysisDTO> lListPointOfViewDTO = getPointOfView4AnalysisList(); List<ChapterDTO> lListChapters = ChapterManager.loadAll(); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { VSceneTagsMapper lVSceneTagsMapper = lSqlSession.getMapper(VSceneTagsMapper.class); VSceneTagsExample lVSceneTagsExample = new VSceneTagsExample(); lVSceneTagsExample.setOrderByClause("chapter_position, point_of_view, point_of_view_id_character"); List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample); if (lListVSceneTags != null && lListVSceneTags.size() > 0) { Map<Integer, Set<String>> lMapPointOfViewsChaptersDistribution = new HashMap<Integer, Set<String>>(); int lIntLastChapter = -1; Set<String> lSetChapterPointOfViews = null; // filter duplicate items using a set for (VSceneTags lVSceneTags : lListVSceneTags) { if (lVSceneTags.getChapterPosition().intValue() != lIntLastChapter) { lSetChapterPointOfViews = new HashSet<String>(); lMapPointOfViewsChaptersDistribution.put(lVSceneTags.getChapterPosition(), lSetChapterPointOfViews); lIntLastChapter = lVSceneTags.getChapterPosition(); } if (lVSceneTags.getPointOfView() != null) { lSetChapterPointOfViews.add(lVSceneTags.getIdPointOfView4Analysis()); } } // populate result map for (PointOfView4AnalysisDTO lPointOfView4AnalysisDTO : lListPointOfViewDTO) { List<Boolean> lListPointOfViewChapterPresence = new ArrayList<Boolean>(); lMapPointOfViewChapterPresence.put(lPointOfView4AnalysisDTO.getIdPointOfView4Analysis(), lListPointOfViewChapterPresence); for (ChapterDTO lChapterDTO : lListChapters) { Set<String> lSetPointOfViews = lMapPointOfViewsChaptersDistribution .get(lChapterDTO.getPosition()); if (lSetPointOfViews != null && !lSetPointOfViews.isEmpty() && lSetPointOfViews .contains(lPointOfView4AnalysisDTO.getIdPointOfView4Analysis())) { lListPointOfViewChapterPresence.add(Boolean.TRUE); } else { lListPointOfViewChapterPresence.add(Boolean.FALSE); } } } } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End getPointOfViewsChaptersDistribution()"); return lMapPointOfViewChapterPresence; }
From source file:com.zenoss.jmx.ValueExtractor.java
private static Object getTableRowData(CompositeData cData, String[] index) throws JmxException { Object result = null;/*from w w w . java 2 s .co m*/ // This gets the data with a key not in index Set<String> keys = new HashSet<String>(Arrays.asList(index)); for (String key : keys) { if (!cData.values().contains(key)) { _logger.warn(key + " not found in composite data row for tabular data"); throw new JmxException(key + " not found in composite data row for tabular data"); } } // find the first value that isn't a part of the index for (Object value : cData.values()) { if (!keys.contains(value)) { result = value; } } return result; }
From source file:com.ms.commons.test.tool.GenerateTestCase.java
private static List<MethodDeclaration> addMember(CompilationUnit unit, List<String> testMethodNames) { List<MethodDeclaration> addedMethods = new ArrayList<MethodDeclaration>(); List<BodyDeclaration> unitMembers = unit.getTypes().get(0).getMembers(); unitMembers = (unitMembers == null) ? new ArrayList<BodyDeclaration>() : unitMembers; Set<String> oldMethods = new HashSet<String>(); for (BodyDeclaration declaration : unitMembers) { if (declaration instanceof MethodDeclaration) { oldMethods.add(((MethodDeclaration) declaration).getName().toLowerCase()); }// w ww . jav a2 s .co m } for (String met : new LinkedHashSet<String>(testMethodNames)) { if (!oldMethods.contains(met.toLowerCase())) { addedMethods.add(makeEmptyTestMethodDeclaration(met)); unitMembers.add(makeEmptyTestMethodDeclaration(met)); } } unit.getTypes().get(0).setMembers(unitMembers); return addedMethods; }
From source file:com.facebook.presto.geospatial.GeoFunctions.java
private static void validateType(String function, OGCGeometry geometry, Set<GeometryTypeName> validTypes) { GeometryTypeName type = GeometryUtils.valueOf(geometry.geometryType()); if (!validTypes.contains(type)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, function + " only applies to " + StringUtils.join(validTypes, " or ") + ". Input type is: " + type); }//from w ww .j av a 2 s . c om }
From source file:ca.mcgill.cs.crown.data.WiktionaryReader.java
private static List<LexicalEntry> convertToEntries(List<JSONObject> rawEntries) { // Avoid the potential for duplicates in the entries Set<String> alreadyIncluded = new HashSet<String>(); int excluded = 0; List<LexicalEntry> entries = new ArrayList<LexicalEntry>(); for (JSONObject jo : rawEntries) { try {//from w ww .ja v a2 s.c om String posStr = jo.getString("pos").toUpperCase(); String lemma = jo.getString("lemma"); String id = jo.getString("id"); // Check for duplicates if (alreadyIncluded.contains(lemma + "." + posStr + ":" + id)) { excluded++; continue; } alreadyIncluded.add(lemma + ":" + id); LexicalEntry e = new LexicalEntryImpl(lemma, id, POS.valueOf(posStr)); Set<String> glosses = new LinkedHashSet<String>(); Map<String, String> rawGlossToCleaned = new LinkedHashMap<String, String>(); JSONArray glossArr = jo.getJSONArray("glosses"); for (int i = 0; i < glossArr.length(); ++i) { String rawGloss = glossArr.getString(i); String cleaned = WiktionaryUtils.cleanGloss(rawGloss); glosses.add(cleaned); rawGlossToCleaned.put(rawGloss, cleaned); } String combinedGloss = String.join(" ", glosses); List<Relation> relations = new ArrayList<Relation>(); JSONArray relationsArr = jo.getJSONArray("relations"); for (int i = 0; i < relationsArr.length(); ++i) { JSONObject relObj = relationsArr.getJSONObject(i); Relation rel = new RelationImpl(relObj.getString("targetLemma"), relObj.optString("targetSense"), Relation.RelationType.valueOf(relObj.getString("type"))); relations.add(rel); } CoreMap m = e.getAnnotations(); m.set(CrownAnnotations.Gloss.class, combinedGloss); m.set(CrownAnnotations.Glosses.class, glosses); m.set(CrownAnnotations.RawGlosses.class, rawGlossToCleaned); m.set(CrownAnnotations.Relations.class, relations); entries.add(e); } catch (JSONException je) { throw new IOError(je); } } CrownLogger.verbose("Excluded %d duplicate entries", excluded); return entries; }
From source file:Main.java
public static boolean isShootingStatus(String currentStatus) { Set<String> shootingStatus = new HashSet<>(); shootingStatus.add("IDLE"); shootingStatus.add("StillCapturing"); shootingStatus.add("StillSaving"); shootingStatus.add("MovieWaitRecStart"); shootingStatus.add("MovieRecording"); shootingStatus.add("MovieWaitRecStop"); shootingStatus.add("MovieSaving"); shootingStatus.add("IntervalWaitRecStart"); shootingStatus.add("IntervalRecording"); shootingStatus.add("IntervalWaitRecStop"); shootingStatus.add("AudioWaitRecStart"); shootingStatus.add("AudioRecording"); shootingStatus.add("AudioWaitRecStop"); shootingStatus.add("AudioSaving"); return shootingStatus.contains(currentStatus); }
From source file:com.github.itoshige.testrail.store.SyncManager.java
/** * delete not existed method in testrail and caseStore. * //from w ww. ja v a2 s. co m * @param sectionId * @param testClass */ private static void deleteNotExistedMethod(String sectionId, final Class<?> testClass) { Set<String> junitMethodNames = new HashSet<String>(); for (final Method junitMethod : TestRailUnitUtil.getDeclaredTestMethods(testClass.getDeclaredMethods())) { junitMethodNames.add(junitMethod.getName()); } // find not existed titles in testrail. List<CaseStoreKey> notExistedTitles = new ArrayList<CaseStoreKey>(); for (CaseStoreKey key : CaseStore.getIns().getSectionId2Tiltes()) { if (key.getProjectId().equals(sectionId) && !junitMethodNames.contains(key.getTitle())) notExistedTitles.add(key); } for (CaseStoreKey key : notExistedTitles) { // delete testrail TestRailClient.deleteCase(CaseStore.getIns().getCaseId(key)); // remove store CaseStore.getIns().remove(key); } }
From source file:net.sf.morph.util.TransformerUtils.java
private static Class[] getClassIntersection(Transformer[] transformers, ClassStrategy strategy) { Set s = ContainerUtils.createOrderedSet(); s.addAll(Arrays.asList(strategy.get(transformers[0]))); for (int i = 1; i < transformers.length; i++) { Set survivors = ContainerUtils.createOrderedSet(); Class[] c = strategy.get(transformers[i]); for (int j = 0; j < c.length; j++) { if (s.contains(c[j])) { survivors.add(c[j]);//from w w w.j ava2s . c o m break; } if (c[j] == null) { break; } for (Iterator it = s.iterator(); it.hasNext();) { Class next = (Class) it.next(); if (next != null && next.isAssignableFrom(c[j])) { survivors.add(c[j]); break; } } } if (!survivors.containsAll(s)) { for (Iterator it = s.iterator(); it.hasNext();) { Class next = (Class) it.next(); if (survivors.contains(next) || next == null) { break; } for (int j = 0; j < c.length; j++) { if (c[j] != null && c[j].isAssignableFrom(next)) { survivors.add(next); break; } } } } s = survivors; } return s.isEmpty() ? CLASS_NONE : (Class[]) s.toArray(new Class[s.size()]); }
From source file:org.apache.jena.sparql.engine.http.Service.java
/** * Executes a service operator/*from www . j a v a2s . c o m*/ * * @param op * Service * @param context * Context * @return Query iterator of service results */ public static QueryIterator exec(OpService op, Context context) { if (context != null && context.isFalse(serviceAllowed)) throw new QueryExecException("SERVICE execution disabled"); if (!op.getService().isURI()) throw new QueryExecException("Service URI not bound: " + op.getService()); // This relies on the observation that the query was originally correct, // so reversing the scope renaming is safe (it merely restores the // algebra expression). // Any variables that reappear should be internal ones that were hidden // by renaming in the first place. // Any substitution is also safe because it replaced variables by // values. Op opRemote = Rename.reverseVarRename(op.getSubOp(), true); // JENA-494 There is a bug here that the renaming means that if this is // deeply nested and joined to other things at the same level of you end // up with the variables being disjoint and the same results // The naive fix for this is to map the variables visible in the inner // operator to those visible in the rewritten operator // There may be some cases where the re-mapping is incorrect due to // deeply nested SERVICE clauses Map<Var, Var> varMapping = new HashMap<>(); Set<Var> originalVars = OpVars.visibleVars(op); Set<Var> remoteVars = OpVars.visibleVars(opRemote); boolean requiresRemapping = false; for (Var v : originalVars) { if (v.getName().contains("/")) { // A variable which was scope renamed so has a different name String origName = v.getName().substring(v.getName().lastIndexOf('/') + 1); Var remoteVar = Var.alloc(origName); if (remoteVars.contains(remoteVar)) { varMapping.put(remoteVar, v); requiresRemapping = true; } } else { // A variable which does not have a different name if (remoteVars.contains(v)) varMapping.put(v, v); } } // Explain.explain("HTTP", opRemote, context) ; Query query; //@formatter:off // Comment (for the future?) // if ( false ) // { // // ***** Interacts with substitution. // Element el = op.getServiceElement().getElement() ; // if ( el instanceof ElementSubQuery ) // query = ((ElementSubQuery)el).getQuery() ; // else // { // query = QueryFactory.create() ; // query.setQueryPattern(el) ; // query.setResultVars() ; // } // } // else //@formatter:on query = OpAsQuery.asQuery(opRemote); Explain.explain("HTTP", query, context); String uri = op.getService().getURI(); HttpQuery httpQuery = configureQuery(uri, context, query); InputStream in = httpQuery.exec(); // Read the whole of the results now. // Avoids the problems with calling back into the same system e.g. // Fuseki+SERVICE <http://localhost:3030/...> ResultSet rs = ResultSetFactory.fromXML(in); QueryIterator qIter = QueryIter.materialize(new QueryIteratorResultSet(rs)); // And close connection now, not when qIter is closed. IO.close(in); // In some cases we may need to apply a re-mapping // This solves JENA-494 the naive way and may be brittle for complex // nested SERVICE clauses if (requiresRemapping) { qIter = QueryIter.map(qIter, varMapping); } return qIter; }
From source file:com.tech.utils.CustomCollectionUtil.java
/** * Method to calculate standard set intersection operation. Example * :Consider set1 = {1,2,3,4,5} set2 = {2,4,5,6,7} then, the output of this * method will be setIntersection = {2,4,5} * //from w ww. j a v a 2 s .co m * @param set1 * @param set2 * @return setIntersection */ public static Set<Long> setIntersection(Set<Long> ietmSet1, Set<Long> itemSet2) { Set<Long> setIntersection = new HashSet<Long>(); /* * Perform set intersection operation only if both the set are not * empty. */ if (ietmSet1 != null && !ietmSet1.isEmpty() && itemSet2 != null && !itemSet2.isEmpty()) { for (Long item : ietmSet1) { if (itemSet2.contains(item)) { setIntersection.add(item); } } } return setIntersection; }