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/*from ww w .jav a 2 s .com*/ * * Chapter.1 Chapter.2 Chapter.3 * - strand.1 - X X * - strand.2 - X * - strand.3 - X X * */ public static Map<String, List<Boolean>> getStrandsChaptersPresence() { Map<String, List<Boolean>> lMapStrandChapterPresence = new HashMap<String, List<Boolean>>(); mLog.debug("Start getStrandsChaptersDistribution()"); List<com.bibisco.bean.StrandDTO> lListStrandDTO = StrandManager.loadAll(); List<ChapterDTO> lListChapters = ChapterManager.loadAll(); if (CollectionUtils.isEmpty(lListStrandDTO) || CollectionUtils.isEmpty(lListChapters)) { mLog.debug("End getStrandsChaptersDistribution()"); return lMapStrandChapterPresence; } SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { VSceneTagsMapper lVSceneTagsMapper = lSqlSession.getMapper(VSceneTagsMapper.class); VSceneTagsExample lVSceneTagsExample = new VSceneTagsExample(); lVSceneTagsExample.setOrderByClause("chapter_position, id_strand"); List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample); if (lListVSceneTags != null && lListVSceneTags.size() > 0) { Map<Integer, Set<Integer>> lMapStrandsChaptersDistribution = new HashMap<Integer, Set<Integer>>(); int lIntLastChapter = -1; Set<Integer> lSetChapterStrands = null; // filter duplicate items using a set for (VSceneTags lVSceneTags : lListVSceneTags) { if (lVSceneTags.getChapterPosition().intValue() != lIntLastChapter) { lSetChapterStrands = new HashSet<Integer>(); lMapStrandsChaptersDistribution.put(lVSceneTags.getChapterPosition(), lSetChapterStrands); lIntLastChapter = lVSceneTags.getChapterPosition(); } if (lVSceneTags.getIdStrand() != null) { lSetChapterStrands.add(lVSceneTags.getIdStrand().intValue()); } } // populate result map for (StrandDTO lStrandDTO : lListStrandDTO) { List<Boolean> lListStrandChapterPresence = new ArrayList<Boolean>(); lMapStrandChapterPresence.put(lStrandDTO.getIdStrand().toString(), lListStrandChapterPresence); for (ChapterDTO lChapterDTO : lListChapters) { Set<Integer> lSetStrands = lMapStrandsChaptersDistribution.get(lChapterDTO.getPosition()); if (lSetStrands != null && !lSetStrands.isEmpty() && lSetStrands.contains(lStrandDTO.getIdStrand())) { lListStrandChapterPresence.add(Boolean.TRUE); } else { lListStrandChapterPresence.add(Boolean.FALSE); } } } } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End getStrandsChaptersDistribution()"); return lMapStrandChapterPresence; }
From source file:com.doculibre.constellio.search.SolrFacetUtils.java
public static List<FacetValue> getPossibleValues(SearchableFacet searchableFacet, FacetsDataProvider dataProvider, String solrCoreName, ConstellioUser user) { List<FacetValue> possibleValues = new ArrayList<FacetValue>(); QueryResponse queryResponse = dataProvider.getQueryResponse(); if (queryResponse != null) { if (searchableFacet.isQuery()) { Map<String, Integer> facetQuery = queryResponse.getFacetQuery(); Map<String, Map<Locale, String>> possibleValueLabels = searchableFacet.getPossibleValuesLabels(); for (String queryName : possibleValueLabels.keySet()) { int queryCount = facetQuery.get(queryName); if (queryCount > 0) { possibleValues.add(new FacetValue(searchableFacet, queryName, queryCount)); }//from w ww .j a v a 2 s. c om } } else if (searchableFacet.isCluster()) { SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices(); String collectionName = simpleSearch.getCollectionName(); RecordCollection collection = collectionServices.get(collectionName); CollectionFacet collectionFacet = collection .getCollectionFacet(new Long(searchableFacet.getName())); ClusteringServices clusteringServices = ConstellioSpringUtils.getClusteringServices(); List<SimpleOrderedMap<Object>> clusters = clusteringServices.cluster(simpleSearch, collectionFacet, 0, ClusteringServices.maxResultsToConsider, user); List<FacetValue> facetValues = searchableFacet.getValues(); for (SimpleOrderedMap<Object> cluster : clusters) { FacetValue facetValue = getFacetValue(cluster, searchableFacet, collection.getLocales()); facetValues.add(facetValue); } // if (!facetValues.isEmpty()) { // searchableFacets.add(clusterFacet); // } possibleValues.addAll(searchableFacet.getValues()); } else if (searchableFacet.isCloudKeyword()) { // No values } else if (queryResponse != null) { FacetField facetField = queryResponse.getFacetField(searchableFacet.getName()); List<Count> facetCounts = facetField != null ? facetField.getValues() : null; if (facetCounts != null) { RecordCollectionServices collectionServices = ConstellioSpringUtils .getRecordCollectionServices(); FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); String collectionName = simpleSearch.getCollectionName(); RecordCollection collection = collectionServices.get(collectionName); CollectionFacet collectionFacet = collection.getFieldFacet(searchableFacet.getName()); // Special cases Set<String> ignoredValues = new HashSet<String>(); if (IndexField.COLLECTION_ID_FIELD.equals(searchableFacet.getName())) { ignoredValues.add("" + collection.getId()); } Set<String> notEmptyFacetValues = new HashSet<String>(); for (Count facetCount : facetCounts) { String facetCountName = facetCount.getName(); if (!ignoredValues.contains(facetCountName) && StringUtils.isNotEmpty(facetCountName)) { possibleValues.add( new FacetValue(searchableFacet, facetCountName, (int) facetCount.getCount())); notEmptyFacetValues.add(facetCountName); } } if (!collectionFacet.isHideEmptyValues()) { List<String> allFacetValues = facetServices.getValues(collectionFacet); for (String facetValue : allFacetValues) { if (!ignoredValues.contains(facetValue) && !notEmptyFacetValues.contains(facetValue)) { possibleValues.add(new FacetValue(searchableFacet, facetValue, 0)); } } } } } } return possibleValues; }
From source file:com.smartsheet.api.internal.http.RequestAndResponseData.java
/** * factory method for creating a RequestAndResponseData object from request and response data with the specifid trace fields *///w w w .ja v a2 s . com public static RequestAndResponseData of(HttpRequestBase request, HttpEntitySnapshot requestEntity, HttpResponse response, HttpEntitySnapshot responseEntity, Set<Trace> traces) throws IOException { RequestData.Builder requestBuilder = new RequestData.Builder(); ResponseData.Builder responseBuilder = new ResponseData.Builder(); if (request != null) { requestBuilder.withCommand(request.getMethod() + " " + request.getURI()); boolean binaryBody = false; if (traces.contains(Trace.RequestHeaders) && request.getAllHeaders() != null) { requestBuilder.withHeaders(); for (Header header : request.getAllHeaders()) { String headerName = header.getName(); String headerValue = header.getValue(); if ("Authorization".equals(headerName) && headerValue.length() > 0) { headerValue = "Bearer ****" + headerValue.substring(Math.max(0, headerValue.length() - 4)); } else if ("Content-Disposition".equals(headerName)) { binaryBody = true; } requestBuilder.addHeader(headerName, headerValue); } } if (requestEntity != null) { if (traces.contains(Trace.RequestBody)) { requestBuilder .setBody(binaryBody ? binaryBody(requestEntity) : getContentAsText(requestEntity)); } else if (traces.contains(Trace.RequestBodySummary)) { requestBuilder.setBody(binaryBody ? binaryBody(requestEntity) : truncateAsNeeded(getContentAsText(requestEntity), TRUNCATE_LENGTH)); } } } if (response != null) { boolean binaryBody = false; responseBuilder.withStatus(response.getStatusText()); if (traces.contains(Trace.ResponseHeaders) && response.getHeaders() != null) { responseBuilder.withHeaders(); for (Map.Entry<String, String> header : response.getHeaders().entrySet()) { String headerName = header.getKey(); String headerValue = header.getValue(); if ("Content-Disposition".equals(headerName)) { binaryBody = true; } responseBuilder.addHeader(headerName, headerValue); } } if (responseEntity != null) { if (traces.contains(Trace.ResponseBody)) { responseBuilder .setBody(binaryBody ? binaryBody(responseEntity) : getContentAsText(responseEntity)); } else if (traces.contains(Trace.ResponseBodySummary)) { responseBuilder.setBody(binaryBody ? binaryBody(responseEntity) : truncateAsNeeded(getContentAsText(responseEntity), TRUNCATE_LENGTH)); } } } return new RequestAndResponseData(requestBuilder.build(), responseBuilder.build()); }
From source file:maltcms.ui.fileHandles.properties.tools.SceneParser.java
private static List<PipelineElementWidget> getPipeline(Widget connectionLayer, Widget pipelinesLayer) { List<PipelineElementWidget> pipeline = new ArrayList<>(); List<Widget> connectionWidgetList = new ArrayList<>(); if (connectionLayer != null) { connectionWidgetList.addAll(connectionLayer.getChildren()); }//from w ww.j a va 2s. c om System.out.println("Number of children in pipeline layer: " + pipelinesLayer.getChildren().size()); for (Widget w : pipelinesLayer.getChildren()) { if (w instanceof PipelineElementWidget) { pipeline.add((PipelineElementWidget) w); } } if (pipeline.size() == 1) { return pipeline; } // System.out.println("Trying to find starting Widget"); Widget startingW = null; for (Widget w : pipelinesLayer.getChildren()) { if (w instanceof PipelineElementWidget) { if (getConnectionWidgetWhereTargetEquals(connectionWidgetList, w) == null) { if (startingW == null) { // System.out.println("Setting starting Widget to" + ((PipelineElementWidget) w).getLabelWidget().getLabel()); startingW = w; } else { Logger.getLogger(SceneParser.class.getName()).info("ERROR"); } } } } Set<Widget> nodes = new HashSet<>(); for (Widget cw : connectionWidgetList) { if (cw instanceof ConnectionWidget) { Widget source = ((ConnectionWidget) cw).getSourceAnchor().getRelatedWidget(); nodes.add(source); Widget target = ((ConnectionWidget) cw).getTargetAnchor().getRelatedWidget(); if (nodes.contains(target)) { throw new IllegalArgumentException("Cycle detected on component: " + target); } } } // System.out.println("Following Connections to get pipeline direction"); ConnectionWidget cw = null; while (connectionWidgetList.size() > 0) { // System.out.println("WIDGET: " + ((PipelineElementWidget) startingW).getLabelWidget().getLabel()); pipeline.add((PipelineElementWidget) startingW); cw = getConnectionWidgetWhereSourceEquals(connectionWidgetList, startingW); if (cw != null) { startingW = cw.getTargetAnchor().getRelatedWidget(); //connectionWidgetList.remove(cw); } else { if (pipelinesLayer.getChildren().size() - 1 == pipeline.size()) { return pipeline; } Logger.getLogger(SceneParser.class.getName()).info("ERROR"); break; } } return pipeline; }
From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java
public static <V extends Node> Set<Edge<V>> removeNodelessEdges(Set<Edge<V>> edges, Set<V> nodes) { Set<Edge<V>> removed = edges.stream() .filter(e -> !nodes.contains(e.getFrom()) || !nodes.contains(e.getTo())) .collect(Collectors.toCollection(LinkedHashSet::new)); edges.removeAll(removed);//from w w w . j a v a2 s . c o m return removed; }
From source file:Main.java
/** * Implements <em>equals</em> per the contract defined by {@link Set#equals(Object)}. * /*from w w w . jav a 2 s . c o m*/ * @param set the set * @param o an object to compare to the list * @return true if {@code o} equals {@code list} */ public static boolean equals(Set<?> set, Object o) { if (!(o instanceof Set)) { return false; } if (set == o) { return true; } Set<?> other = (Set<?>) o; if (set.size() != other.size()) { return false; } // The spec for interface Set says a set should never contain itself, but most implementations // do not explicitly block this. So the paranoid code below handles this case. boolean containsItself = false; for (Object element : set) { if (element == set || element == other) { // don't test using contains(...) since that could cause infinite recursion containsItself = true; } else { if (!other.contains(element)) { return false; } } } if (containsItself) { // safely check that other also contains itself for (Object element : other) { if (element == set || element == other) { return true; } } return false; } return true; }
From source file:com.hpe.application.automation.tools.octane.executor.UFTTestDetectionService.java
private static void removeTestDuplicated(List<AutomatedTest> tests) { Set<String> keys = new HashSet<>(); List<AutomatedTest> testsToRemove = new ArrayList<>(); for (AutomatedTest test : tests) { String key = test.getPackage() + "_" + test.getName(); if (keys.contains(key)) { testsToRemove.add(test);// www. j a v a 2s . co m } keys.add(key); } tests.removeAll(testsToRemove); }
From source file:com.netflix.config.util.ConfigurationUtils.java
static void loadFromPropertiesFile(AbstractConfiguration config, String baseUrl, Set<String> loaded, String... nextLoadKeys) { String nextLoad = getNextLoad(config, nextLoadKeys); if (nextLoad == null) { return;/*from ww w . j ava 2 s . c o m*/ } String[] filesToLoad = nextLoad.split(","); for (String fileName : filesToLoad) { fileName = fileName.trim(); try { URL url = new URL(baseUrl + "/" + fileName); // avoid circle if (loaded.contains(url.toExternalForm())) { logger.warn(url + " is already loaded"); continue; } loaded.add(url.toExternalForm()); PropertiesConfiguration nextConfig = new OverridingPropertiesConfiguration(url); copyProperties(nextConfig, config); logger.info("Loaded properties file " + url); loadFromPropertiesFile(config, baseUrl, loaded, nextLoadKeys); } catch (Throwable e) { logger.warn("Unable to load properties file", e); } } }
From source file:gobblin.writer.initializer.JdbcWriterInitializer.java
/** * 1. User should not define same destination table across different branches. * 2. User should not define same staging table across different branches. * 3. If commit policy is not full, Gobblin will try to write into final table even there's a failure. This will let Gobblin to write in task level. * However, publish data at job level is true, it contradicts with the behavior of Gobblin writing in task level. Thus, validate publish data at job level is false if commit policy is not full. * @param state//from ww w . j ava 2s . c o m */ private static void validateInput(State state) { int branches = state.getPropAsInt(ConfigurationKeys.FORK_BRANCHES_KEY, 1); Set<String> publishTables = Sets.newHashSet(); for (int branchId = 0; branchId < branches; branchId++) { String publishTable = Preconditions.checkNotNull( getProp(state, JdbcPublisher.JDBC_PUBLISHER_FINAL_TABLE_NAME, branches, branchId), JdbcPublisher.JDBC_PUBLISHER_FINAL_TABLE_NAME + " should not be null."); if (publishTables.contains(publishTable)) { throw new IllegalArgumentException("Duplicate " + JdbcPublisher.JDBC_PUBLISHER_FINAL_TABLE_NAME + " is not allowed across branches"); } publishTables.add(publishTable); } Set<String> stagingTables = Sets.newHashSet(); for (int branchId = 0; branchId < branches; branchId++) { String stagingTable = getProp(state, ConfigurationKeys.WRITER_STAGING_TABLE, branches, branchId); if (!StringUtils.isEmpty(stagingTable) && stagingTables.contains(stagingTable)) { throw new IllegalArgumentException( "Duplicate " + ConfigurationKeys.WRITER_STAGING_TABLE + " is not allowed across branches"); } stagingTables.add(stagingTable); } JobCommitPolicy policy = JobCommitPolicy.getCommitPolicy(state); boolean isPublishJobLevel = state.getPropAsBoolean(ConfigurationKeys.PUBLISH_DATA_AT_JOB_LEVEL, ConfigurationKeys.DEFAULT_PUBLISH_DATA_AT_JOB_LEVEL); if (JobCommitPolicy.COMMIT_ON_FULL_SUCCESS.equals(policy) ^ isPublishJobLevel) { throw new IllegalArgumentException( "Job commit policy should be only " + JobCommitPolicy.COMMIT_ON_FULL_SUCCESS + " when " + ConfigurationKeys.PUBLISH_DATA_AT_JOB_LEVEL + " is true." + " Or Job commit policy should not be " + JobCommitPolicy.COMMIT_ON_FULL_SUCCESS + " and " + ConfigurationKeys.PUBLISH_DATA_AT_JOB_LEVEL + " is false."); } }
From source file:it.unibo.alchemist.language.protelis.util.ProtelisLoader.java
private static void recursivelyInitFunctions(final Program module, final Map<FasterString, FunctionDefinition> nameToFun, final Map<FunctionDef, FunctionDefinition> funToFun, final Set<Program> completed, final boolean initPrivate) { if (!completed.contains(module)) { completed.add(module);//from w w w . j a va 2s. c o m /* * Init imports functions, in reverse order */ final EList<Import> imports = module.getProtelisImport(); for (int i = imports.size() - 1; i >= 0; i--) { final Import protelisImport = imports.get(i); recursivelyInitFunctions(protelisImport.getModule(), nameToFun, funToFun, completed, false); } /* * Init local functions */ for (FunctionDef fd : module.getDefinitions()) { if (initPrivate || fd.isPublic()) { final String fname = fd.getName(); final String fullName = module.getName() + ":" + fname; final FasterString ffname = new FasterString(fname); final FasterString ffullName = new FasterString(fullName); final FunctionDefinition def = new FunctionDefinition(ffullName, extractArgs(fd)); nameToFun.put(ffullName, def); nameToFun.put(ffname, def); funToFun.put(fd, def); } } } }