List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:com.thinkbiganalytics.feedmgr.nifi.NifiFlowCache.java
/** * add processors to the cache// w w w . j av a2 s . co m * * @param templateName a template name * @param processors processors to add to the cache */ public void updateProcessorIdNames(String templateName, Collection<ProcessorDTO> processors) { Map<String, String> processorIdToProcessorName = new HashMap<>(); processors.stream().forEach(flowProcessor -> { processorIdToProcessorName.put(flowProcessor.getId(), flowProcessor.getName()); }); this.processorIdToProcessorName.putAll(processorIdToProcessorName); }
From source file:simx.profiler.info.actor.ActorTypeInfoTopComponent.java
@Override public void resultChanged(LookupEvent le) { Collection<? extends ActorType> allSelectedTypes = result.allInstances(); if (!allSelectedTypes.isEmpty()) { allSelectedTypes.stream().forEach((type) -> { this.setData(type); });//from www. j ava 2 s .co m } else { System.out.println("No selection"); } }
From source file:com.haulmont.cuba.gui.data.impl.AbstractCollectionDatasource.java
@Nullable protected String[] getSortPropertiesForPersistentAttribute(MetaPropertyPath propertyPath) { String[] sortProperties = null; if (!propertyPath.getMetaProperty().getRange().isClass()) { // a scalar persistent attribute sortProperties = new String[1]; sortProperties[0] = propertyPath.toString(); } else {//from w w w . jav a2 s .c o m // a reference attribute MetaClass metaClass = propertyPath.getMetaProperty().getRange().asClass(); if (!propertyPath.getMetaProperty().getRange().getCardinality().isMany()) { Collection<MetaProperty> properties = metadata.getTools().getNamePatternProperties(metaClass); if (!properties.isEmpty()) { sortProperties = properties.stream() .filter(metaProperty -> metadata.getTools().isPersistent(metaProperty)) .map(MetadataObject::getName) .map(propName -> propertyPath.toString().concat(".").concat(propName)) .toArray(String[]::new); } else { sortProperties = new String[1]; sortProperties[0] = propertyPath.toString(); } } } return sortProperties; }
From source file:com.ggvaidya.scinames.ui.DataReconciliatorController.java
private List<NameCluster> createSingleNameClusters(Dataset dt, Collection<Name> names) { // Convenience method: we create a set of NameClusters, each // consisting of a single name. return names.stream().sorted().map(n -> new NameCluster(dt, n)).collect(Collectors.toList()); }
From source file:com.hortonworks.registries.schemaregistry.avro.SchemaBranchLifeCycleTest.java
@Test public void addSchemaVersionToBranch() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException { SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), SchemaCompatibility.NONE); SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc"); SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId()); addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc"); addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-compat.avsc"); Collection<SchemaVersionInfo> schemaBranch1VersionInfos = schemaRegistryClient .getAllVersions(schemaBranch1.getName(), schemaMetadata.getName()); Collection<SchemaVersionInfo> masterSchemaVersionInfos = schemaRegistryClient .getAllVersions(schemaMetadata.getName()); Assert.assertTrue(masterSchemaVersionInfos.size() == 1); Assert.assertTrue(schemaBranch1VersionInfos.size() == 3); Long versionsInInitiatedState = schemaBranch1VersionInfos.stream() .filter(schemaVersionInfo -> schemaVersionInfo.getStateId() .equals(SchemaVersionLifecycleStates.INITIATED.getId())) .count();//from w w w.ja v a2 s .c o m Long versionsInEnabledState = schemaBranch1VersionInfos.stream() .filter(schemaVersionInfo -> schemaVersionInfo.getStateId() .equals(SchemaVersionLifecycleStates.ENABLED.getId())) .count(); Assert.assertTrue(versionsInInitiatedState == 2); Assert.assertTrue(versionsInEnabledState == 1); }
From source file:com.thoughtworks.go.server.domain.AgentInstances.java
public AgentInstance findElasticAgent(final String elasticAgentId, final String elasticPluginId) { Collection<AgentInstance> values = agentInstances.values().stream().filter(agentInstance -> { if (!agentInstance.isElastic()) { return false; }// ww w. j av a2 s . com ElasticAgentMetadata elasticAgentMetadata = agentInstance.elasticAgentMetadata(); return elasticAgentMetadata.elasticAgentId().equals(elasticAgentId) && elasticAgentMetadata.elasticPluginId().equals(elasticPluginId); }).collect(Collectors.toList()); if (values.size() == 0) { return null; } if (values.size() > 1) { Collection<String> uuids = values.stream().map(AgentInstance::getUuid).collect(Collectors.toList()); throw new IllegalStateException(String.format( "Found multiple agents with the same elastic agent id [%s]", StringUtils.join(uuids, ", "))); } return values.iterator().next(); }
From source file:com.hortonworks.registries.schemaregistry.avro.SchemaBranchLifeCycleTest.java
@Test public void mergeSchemaWithDefaultMergeStrategy() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException { SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.toString(), SchemaCompatibility.NONE); SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc"); SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId()); SchemaIdVersion schemaBranch1Version1 = addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc"); SchemaIdVersion schemaBranch1Version2 = addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-compat.avsc"); schemaRegistryClient.mergeSchemaVersion(schemaBranch1Version2.getSchemaVersionId()); Collection<SchemaVersionInfo> branchSchemaVersionInfos = schemaRegistryClient .getAllVersions(schemaBranch1.getName(), schemaMetadata.getName()); Collection<SchemaVersionInfo> masterSchemaVersionInfos = schemaRegistryClient .getAllVersions(schemaMetadata.getName()); Assert.assertTrue(masterSchemaVersionInfos.size() == 2); Assert.assertTrue(branchSchemaVersionInfos.size() == 3); Long branchVersionsInInitiatedState = branchSchemaVersionInfos.stream() .filter(schemaVersionInfo -> schemaVersionInfo.getStateId() .equals(SchemaVersionLifecycleStates.INITIATED.getId())) .count();// w w w. ja v a2 s . c om Long masterVersionsInEnabledState = masterSchemaVersionInfos.stream() .filter(schemaVersionInfo -> schemaVersionInfo.getStateId() .equals(SchemaVersionLifecycleStates.ENABLED.getId())) .count(); Assert.assertTrue(branchVersionsInInitiatedState == 2); Assert.assertTrue(masterVersionsInEnabledState == 2); }
From source file:com.seleniumtests.reporter.reporters.SeleniumTestsReporter2.java
/** * Generate summary report for all test methods * @param suites/*ww w . jav a2 s. com*/ * @param suiteName * @param map * @return map containing test results */ public Map<ITestContext, List<ITestResult>> generateSuiteSummaryReport(final List<ISuite> suites) { // build result list for each TestNG test Map<ITestContext, List<ITestResult>> methodResultsMap = new LinkedHashMap<>(); for (ISuite suite : suites) { Map<String, ISuiteResult> tests = suite.getResults(); for (ISuiteResult r : tests.values()) { ITestContext context = r.getTestContext(); List<ITestResult> resultList = new ArrayList<>(); Collection<ITestResult> methodResults = new ArrayList<>(); methodResults.addAll(context.getFailedTests().getAllResults()); methodResults.addAll(context.getPassedTests().getAllResults()); methodResults.addAll(context.getSkippedTests().getAllResults()); methodResults = methodResults.stream() .sorted((r1, r2) -> Long.compare(r1.getStartMillis(), r2.getStartMillis())) .collect(Collectors.toList()); for (ITestResult result : methodResults) { SeleniumTestsContext testContext = (SeleniumTestsContext) result .getAttribute(SeleniumRobotTestListener.TEST_CONTEXT); String fileName; if (testContext != null) { fileName = testContext.getRelativeOutputDir() + "/TestReport.html"; } else { fileName = getTestName(result) + "/TestReport.html"; } result.setAttribute(METHOD_RESULT_FILE_NAME, fileName); result.setAttribute(SeleniumRobotLogger.UNIQUE_METHOD_NAME, getTestName(result)); } resultList.addAll(methodResults); methodResultsMap.put(context, resultList); } } try { VelocityEngine ve = initVelocityEngine(); Template t = ve.getTemplate("/reporter/templates/report.part.suiteSummary.vm"); VelocityContext context = new VelocityContext(); context.put("tests", methodResultsMap); context.put("steps", TestLogging.getTestsSteps()); StringWriter writer = new StringWriter(); t.merge(context, writer); mOut.write(writer.toString()); } catch (Exception e) { generationErrorMessage = "generateSuiteSummaryReport error:" + e.getMessage(); logger.error("generateSuiteSummaryReport error: ", e); } return methodResultsMap; }
From source file:ch.wisv.areafiftylan.integration.TicketRestIntegrationTest.java
@Test public void testGetAvailableTickets() { Collection<TicketType> ticketTypes = ticketService.getAllTicketTypes().stream() .filter(TicketType::isBuyable).collect(Collectors.toList()); //@formatter:off given().when().get(TICKETS_ENDPOINT + "/available").then().statusCode(HttpStatus.SC_OK) .body("ticketTypes.ticketType", is(ticketTypes.stream().map(TicketType::getName).collect(Collectors.toList()))) .body("ticketTypes.price", is(ticketTypes.stream().map(TicketType::getPrice).collect(Collectors.toList()))) .body("ticketLimit", is(TICKET_LIMIT)); //@formatter:on }
From source file:com.hortonworks.streamline.streams.security.service.SecurityCatalogResource.java
private Collection<AclEntry> filter(Collection<AclEntry> aclEntries, SecurityContext securityContext) { User currentUser = getCurrentUser(securityContext); Set<Role> currentUserRoles = catalogService.getAllUserRoles(currentUser); boolean isSecurityAdmin = SecurityUtil.hasRole(authorizer, securityContext, ROLE_SECURITY_ADMIN); return aclEntries.stream() .filter(aclEntry -> isSecurityAdmin || matches(aclEntry, currentUser, currentUserRoles)) .collect(Collectors.toSet()); }