List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:com.haulmont.cuba.core.config.AppPropertiesLocator.java
protected Set<Class> findConfigInterfaces() { if (interfacesCache == null) { synchronized (this) { if (interfacesCache == null) { log.trace("Locating config interfaces"); Set<String> cache = new HashSet<>(); for (String rootPackage : metadata.getRootPackages()) { String packagePrefix = rootPackage.replace(".", "/") + "/**/*.class"; String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + packagePrefix; Resource[] resources; try { resources = resourcePatternResolver.getResources(packageSearchPath); for (Resource resource : resources) { if (resource.isReadable()) { MetadataReader metadataReader = metadataReaderFactory .getMetadataReader(resource); ClassMetadata classMetadata = metadataReader.getClassMetadata(); if (classMetadata.isInterface()) { for (String intf : classMetadata.getInterfaceNames()) { if (Config.class.getName().equals(intf)) { cache.add(classMetadata.getClassName()); break; } }/*from w w w .ja v a 2s . c o m*/ } } } } catch (IOException e) { throw new RuntimeException("Error searching for Config interfaces", e); } } log.trace("Found config interfaces: {}", cache); interfacesCache = cache; } } } return interfacesCache.stream().map(ReflectionHelper::getClass).collect(Collectors.toSet()); }
From source file:com.thinkbiganalytics.metadata.modeshape.user.JcrUserGroup.java
@Override public Set<UserGroup> getAllContainingGroups() { return streamAllContainingGroupNodes(this.node) .map(node -> JcrUtil.toJcrObject(node, JcrUserGroup.NODE_TYPE, JcrUserGroup.class)) .collect(Collectors.toSet()); }
From source file:com.netflix.spinnaker.fiat.permissions.DefaultPermissionsResolver.java
private Set<Resource> getResources(Set<Role> roles) { return resourceProviders.stream().flatMap(provider -> { try {//ww w. ja v a2 s.c om return provider.getAllRestricted(roles).stream(); } catch (ProviderException pe) { throw new PermissionResolutionException(pe); } }).collect(Collectors.toSet()); }
From source file:delfos.dataset.util.DatasetPrinter.java
public static <Node> String printWeightedGraph(WeightedGraph<Node> weightedGraph, Collection<Node> nodes) { return weightedGraph.toStringTable(nodes.stream().collect(Collectors.toSet())); }
From source file:com.hortonworks.streamline.registries.dashboard.service.DashboardCatalogService.java
public Set<Long> getWidgetDatasourceMapping(Widget widget) { List<QueryParam> queryParams = Collections .singletonList(new QueryParam(WidgetDatasourceMapping.WIDGET_ID, widget.getId().toString())); Collection<WidgetDatasourceMapping> mappings = dao.find(WIDGET_DATASOURCE_MAPPING_NAMESPACE, queryParams); if (mappings != null) { return mappings.stream().map(WidgetDatasourceMapping::getWidgetId).collect(Collectors.toSet()); }/*ww w .ja v a 2s . c o m*/ return Collections.emptySet(); }
From source file:org.artifactory.ui.rest.service.admin.configuration.repositories.replication.ReplicationConfigService.java
private void updateAddedAndRemovedReplications(Set<LocalReplicationDescriptor> replications, String repoKey, MutableCentralConfigDescriptor configDescriptor) { log.info("Updating replication configurations for repo {}", repoKey); // Remove all replication configs for this repo and re-add all newly received ones and do cleanup for // descriptors that had their url changed Set<String> newUrls = replications.stream().map(LocalReplicationDescriptor::getUrl) .collect(Collectors.toSet()); List<LocalReplicationDescriptor> currentLocalReplications = configDescriptor .getMultiLocalReplications(repoKey); cleanupLocalReplications(currentLocalReplications.stream() .filter(replication -> !newUrls.contains(replication.getUrl())).collect(Collectors.toList())); currentLocalReplications.forEach(configDescriptor::removeLocalReplication); replications.forEach(configDescriptor::addLocalReplication); }
From source file:eu.itesla_project.online.tools.RunWcaOnStateTool.java
@Override public void run(CommandLine line) throws Exception { String workflowId = line.getOptionValue("workflow"); Integer stateId = Integer.valueOf(line.getOptionValue("state")); System.out.println("loading state " + stateId + " of workflow " + workflowId + " from the online db ..."); OnlineConfig config = OnlineConfig.load(); OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create(); // load the network Network network = onlinedb.getState(workflowId, stateId); if (network != null) { OnlineWorkflowParameters parameters = onlinedb.getWorkflowParameters(workflowId); String offlineWorkflowId = parameters.getOfflineWorkflowId(); if (line.hasOption("offline-workflow")) offlineWorkflowId = line.getOptionValue("offline-workflow"); Interval histoInterval = parameters.getHistoInterval(); if (line.hasOption("history-interval")) histoInterval = Interval.parse(line.getOptionValue("history-interval")); double purityThreshold = parameters.getRulesPurityThreshold(); if (line.hasOption("purity-threshold")) purityThreshold = Double.parseDouble(line.getOptionValue("purity-threshold")); Set<SecurityIndexType> securityIndexTypes = parameters.getSecurityIndexes(); if (line.hasOption("security-index-types")) { securityIndexTypes = Arrays.stream(line.getOptionValue("security-index-types").split(",")) .map(SecurityIndexType::valueOf).collect(Collectors.toSet()); }// www .j a v a 2 s. c o m boolean stopWcaOnViolations = DEFAULT_STOP_WCA_ON_VIOLATIONS; if (line.hasOption("stop-on-violations")) { stopWcaOnViolations = Boolean.parseBoolean(line.getOptionValue("stop-on-violations")); } ComputationManager computationManager = new LocalComputationManager(); network.getStateManager().allowStateMultiThreadAccess(true); WCAParameters wcaParameters = new WCAParameters(histoInterval, offlineWorkflowId, securityIndexTypes, purityThreshold, stopWcaOnViolations); ContingenciesAndActionsDatabaseClient contingenciesDb = config.getContingencyDbClientFactoryClass() .newInstance().create(); LoadFlowFactory loadFlowFactory = config.getLoadFlowFactoryClass().newInstance(); try (HistoDbClient histoDbClient = config.getHistoDbClientFactoryClass().newInstance().create(); RulesDbClient rulesDbClient = config.getRulesDbClientFactoryClass().newInstance() .create("rulesdb")) { UncertaintiesAnalyserFactory uncertaintiesAnalyserFactory = config .getUncertaintiesAnalyserFactoryClass().newInstance(); WCA wca = config.getWcaFactoryClass().newInstance().create(network, computationManager, histoDbClient, rulesDbClient, uncertaintiesAnalyserFactory, contingenciesDb, loadFlowFactory); WCAResult result = wca.run(wcaParameters); Table table = new Table(7, BorderStyle.CLASSIC_WIDE); table.addCell("Contingency", new CellStyle(CellStyle.HorizontalAlign.center)); table.addCell("Cluster 1", new CellStyle(CellStyle.HorizontalAlign.center)); table.addCell("Cluster 2", new CellStyle(CellStyle.HorizontalAlign.center)); table.addCell("Cluster 3", new CellStyle(CellStyle.HorizontalAlign.center)); table.addCell("Cluster 4", new CellStyle(CellStyle.HorizontalAlign.center)); table.addCell("Undefined", new CellStyle(CellStyle.HorizontalAlign.center)); table.addCell("Cause", new CellStyle(CellStyle.HorizontalAlign.center)); for (WCACluster cluster : result.getClusters()) { table.addCell(cluster.getContingency().getId()); int[] clusterIndexes = new int[] { 1, 2, 3, 4, -1 }; for (int k = 0; k < clusterIndexes.length; k++) { if (clusterIndexes[k] == cluster.getNum().toIntValue()) { table.addCell("X", new CellStyle(CellStyle.HorizontalAlign.center)); } else { table.addCell("-", new CellStyle(CellStyle.HorizontalAlign.center)); } } table.addCell(Objects.toString(cluster.getCauses(), ""), new CellStyle(CellStyle.HorizontalAlign.center)); } System.out.println(table.render()); } } }
From source file:cz.afrosoft.whattoeat.cookbook.recipe.gui.dialog.RecipeViewDialog.java
private void prefillDialog(final Recipe recipe, final float servings) { Validate.notNull(recipe);/*from w ww . ja va 2 s. c o m*/ typeLabel.setText(StringUtils.join(recipe.getRecipeTypes().stream() .map(recipeType -> I18n.getText(recipeType.getLabelKey())).collect(Collectors.toSet()), ", ")); tasteLabel.setText(I18n.getText(recipe.getTaste().getLabelKey())); timeLabel.setText(I18n.getText(recipe.getTotalPreparationTime().getLabelKey())); ratingLabel.setText(String.valueOf(recipe.getRating())); keywordField.setSelectedKeywords(recipe.getKeywords()); preparation.setText(recipe.getPreparation()); servingsField.setFloat(servings); recipeIngredients = recipeService.loadRecipeIngredients(recipe.getIngredients()); ingredientQuantityTable.addRecipeIngredients(servings, recipeIngredients); updatePriceLabel(); // pre-fill side dishes links boolean hasSideDishes = !recipe.getSideDishes().isEmpty(); sideDishesLinks.setVisible(hasSideDishes);// TODO replace visibility with removal so it does not take space of layout sideDishesLinks.setRecipes(recipe.getSideDishes()); }
From source file:com.devicehive.dao.NetworkDaoTest.java
@Test public void shouldGetNetworksByIdsSet() throws Exception { Set<Long> networkIds = new HashSet<>(); for (int i = 0; i < 100; i++) { NetworkVO network = new NetworkVO(); network.setKey(RandomStringUtils.randomAlphabetic(10)); networkDao.persist(network);// www . jav a 2 s. c o m if (i % 2 == 0) { networkIds.add(network.getId()); } } List<NetworkWithUsersAndDevicesVO> networks = networkDao.getNetworksByIdsAndUsers(null, networkIds, null); assertNotNull(networks); assertThat(networks, hasSize(networkIds.size())); Set<Long> returnedIds = networks.stream().map(NetworkWithUsersAndDevicesVO::getId) .collect(Collectors.toSet()); assertThat(networkIds, equalTo(returnedIds)); }