List of usage examples for java.util Set stream
default Stream<E> stream()
From source file:com.baidu.rigel.biplatform.ma.report.utils.QueryUtils.java
/** * measuremeasuremeasurecube/*www .j av a2s . c o m*/ * @param measures * @param oriCube */ private static void modifyMeasures(Map<String, Measure> measures, Cube oriCube) { Set<String> refMeasuers = Sets.newHashSet(); measures.values().stream().filter(m -> { return m.getType() == MeasureType.CAL || m.getType() == MeasureType.RR || m.getType() == MeasureType.SR; }).forEach(m -> { ExtendMinicubeMeasure tmp = (ExtendMinicubeMeasure) m; if (m.getType() == MeasureType.CAL) { refMeasuers.addAll(PlaceHolderUtils.getPlaceHolderKeys(tmp.getFormula())); } else { final String refName = m.getName().substring(0, m.getName().length() - 3); refMeasuers.add(refName); if (m.getType() == MeasureType.RR) { tmp.setFormula("rRate(${" + refName + "})"); } else if (m.getType() == MeasureType.SR) { tmp.setFormula("sRate(${" + refName + "})"); } } tmp.setAggregator(Aggregator.CALCULATED); }); refMeasuers.stream().filter(str -> { return !measures.containsKey(str); }).map(str -> { Set<Map.Entry<String, Measure>> entry = oriCube.getMeasures().entrySet(); for (Map.Entry<String, Measure> tmp : entry) { if (str.equals(tmp.getValue().getName())) { return tmp.getValue(); } } return null; }).forEach(m -> { if (m != null) { measures.put(m.getName(), m); } }); }
From source file:com.nike.cerberus.service.SafeDepositBoxService.java
private Optional<String> extractOwner(Set<UserGroupPermission> userGroupPermissions) { final Optional<Role> ownerRole = roleService.getRoleByName(RoleRecord.ROLE_OWNER); if (!ownerRole.isPresent()) { throw ApiException.newBuilder().withApiErrors(DefaultApiError.MISCONFIGURED_APP) .withExceptionMessage("Owner role doesn't exist!").build(); }// ww w.j av a 2s . c o m final Optional<UserGroupPermission> ownerPermission = userGroupPermissions.stream() .filter(perm -> StringUtils.equals(perm.getRoleId(), ownerRole.get().getId())).findFirst(); if (!ownerPermission.isPresent()) { return Optional.empty(); } userGroupPermissions.remove(ownerPermission.get()); return Optional.of(ownerPermission.get().getName()); }
From source file:ddf.catalog.definition.impl.DefinitionParser.java
private List<Callable<Boolean>> parseValidators(Changeset changeset, Map<String, List<Outer.Validator>> validators) { List<Callable<Boolean>> staged = new ArrayList<>(); for (Map.Entry<String, List<Outer.Validator>> entry : validators.entrySet()) { Set<ValidatorWrapper> validatorWrappers = validatorFactory(entry.getKey(), entry.getValue()); Set<AttributeValidator> attributeValidators = validatorWrappers.stream() .map(ValidatorWrapper::getAttributeValidators).flatMap(Collection::stream) .collect(Collectors.toSet()); String attributeName = entry.getKey(); staged.add(() -> {// w w w . j a va2 s. co m attributeValidatorRegistry.registerValidators(attributeName, attributeValidators); changeset.attributeValidators.put(attributeName, attributeValidators); return true; }); validatorWrappers.stream().map(ValidatorWrapper::getMetacardValidators).flatMap(Collection::stream) .collect(Collectors.toSet()).forEach(validator -> staged.add(() -> { ServiceRegistration<MetacardValidator> registration = getBundleContext() .registerService(MetacardValidator.class, validator, null); changeset.metacardValidatorServices.add(registration); return registration != null; })); validatorWrappers.stream().map(ValidatorWrapper::getReportingMetacardValidators) .flatMap(Collection::stream).collect(Collectors.toSet()).forEach(validator -> staged.add(() -> { ServiceRegistration<ReportingMetacardValidator> registration = getBundleContext() .registerService(ReportingMetacardValidator.class, validator, null); changeset.reportingMetacardValidatorServices.add(registration); return registration != null; })); } return staged; }
From source file:io.gravitee.management.service.impl.ApiServiceImpl.java
@Override public boolean isAPISynchronized(String apiId) { try {/*w w w . j a v a 2 s .com*/ ApiEntity api = findById(apiId); Set<EventEntity> events = eventService .findByType(Arrays.asList(EventType.PUBLISH_API, EventType.UNPUBLISH_API)); List<EventEntity> eventsSorted = events.stream() .sorted((e1, e2) -> e1.getCreatedAt().compareTo(e2.getCreatedAt())) .collect(Collectors.toList()); Collections.reverse(eventsSorted); for (EventEntity event : eventsSorted) { JsonNode node = objectMapper.readTree(event.getPayload()); Api payloadEntity = objectMapper.convertValue(node, Api.class); if (api.getId().equals(payloadEntity.getId())) { if (api.getUpdatedAt().compareTo(payloadEntity.getUpdatedAt()) <= 0) { return true; } else { // API is synchronized if API required deployment fields are the same as the event payload return apiSynchronizationProcessor.processCheckSynchronization(convert(payloadEntity), api); } } } } catch (Exception e) { LOGGER.error("An error occurs while trying to check API synchronization state {}", apiId, e); return false; } return false; }
From source file:com.hp.autonomy.frontend.configuration.authentication.CommunityAuthenticationProvider.java
@Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { final com.hp.autonomy.frontend.configuration.authentication.Authentication<?> authenticationConfig = configService .getConfig().getAuthentication(); final String authenticationMethod = authenticationConfig.getMethod(); if (!(authenticationConfig instanceof CommunityAuthentication) || LoginTypes.DEFAULT.equals(authenticationMethod)) { return null; }//from w ww . ja v a 2s .c o m final String username = authentication.getName(); final String password = authentication.getCredentials().toString(); try { final boolean isAuthenticated = userService.authenticateUser(username, password, authenticationMethod); if (!isAuthenticated) { throw new BadCredentialsException("Bad credentials"); } final UserRoles userRoles = userService.getUser(username, true); Set<String> roleNames = new HashSet<>(userRoles.getRoles()); if (!roles.areRolesAuthorized(roleNames, loginPrivileges)) { // if we have default roles, grant the user the default roles if (!defaultRoles.isEmpty()) { roleNames = defaultRoles; // check that the default role names make sense if (!roles.areRolesAuthorized(roleNames, loginPrivileges)) { throw new BadCredentialsException("Bad credentials"); } } else { throw new BadCredentialsException("Bad credentials"); } } final Collection<GrantedAuthority> grantedAuthorities = roleNames.stream() .map(SimpleGrantedAuthority::new).collect(Collectors.toList()); final Collection<? extends GrantedAuthority> mappedAuthorities = authoritiesMapper .mapAuthorities(grantedAuthorities); return new UsernamePasswordAuthenticationToken( new CommunityPrincipal(userRoles.getUid(), username, userRoles.getSecurityInfo(), roleNames), password, mappedAuthorities); } catch (final AciErrorException aciError) { // This should not happen throw new InternalAuthenticationServiceException( "An ACI error occurred while attempting to authenticate", aciError); } catch (final AciServiceException serviceError) { // This will happen if community is down throw new InternalAuthenticationServiceException("An error occurred while contacting community", serviceError); } }
From source file:se.uu.it.cs.recsys.service.resource.impl.RecommendationGenerator.java
Set<Integer> filterOnPlanYear(Set<Integer> courseId) { if (courseId.isEmpty()) { return Collections.emptySet(); }/*from w w w . ja v a 2 s . co m*/ Set<se.uu.it.cs.recsys.persistence.entity.Course> filteredCourse = this.courseRepository .findByAutoGenIds(courseId).stream() .filter(ConstraintSolverPreferenceBuilder .inPlanYearPredicate(this.constraintPref.getIndexedScheduleInfo())) .sorted((se.uu.it.cs.recsys.persistence.entity.Course one, se.uu.it.cs.recsys.persistence.entity.Course two) -> Integer.compare(one.getAutoGenId(), two.getAutoGenId())) .collect(Collectors.toSet()); filteredCourse.forEach(course -> LOGGER.debug("Filtered course: {}", course)); return filteredCourse.stream().map(course -> course.getAutoGenId()).collect(Collectors.toSet()); }
From source file:org.outofbits.sesame.schemagen.SchemaGeneration.java
/** * Gets the root resource of the given vocabulary, or null if n such reosurce could be found. * * @param vocabulary {@link Model} containing all statements of the vocabulary. * @return the root {@link Resource} or null, if no such resource could be found. * @throws SchemaGenerationException if there are more than one root resource. *//*from w w w . j av a 2 s .c o m*/ private Resource getRootResource(Model vocabulary) throws SchemaGenerationException { assert vocabulary != null; Resource vocabularyRootResource = null; // Using Namespace for getting the root resource. if (vocabularyOptions.baseNamespace() != null) { Optional<Resource> optionalVocabRootResource = vocabulary .filter(valueFactory.createIRI(vocabularyOptions.baseNamespace()), null, null).subjects() .stream().findFirst(); if (optionalVocabRootResource.isPresent()) { vocabularyRootResource = optionalVocabRootResource.get(); } } if (vocabularyRootResource == null) { // Getting the root resource that is an instance of a known vocabulary class. for (IRI clazz : VOCAB_CLASSES) { Set<Resource> vocabRootResources = vocabulary.filter(null, RDF.TYPE, clazz).subjects(); if (vocabRootResources.size() > 1) { throw new SchemaGenerationException(String.format("Ambiguous root resources (%s).", String.join( ", ", vocabRootResources.stream().map(Resource::stringValue).collect(Collectors.toList())))); } else if (vocabRootResources.size() == 1) { Resource currentVocabularyRootResource = vocabRootResources.iterator().next(); if (vocabularyRootResource == null) { vocabularyRootResource = currentVocabularyRootResource; } else if (!currentVocabularyRootResource.equals(vocabularyRootResource)) { throw new SchemaGenerationException(String.format("Ambiguous root resources (%s, %s).", vocabularyRootResource, currentVocabularyRootResource)); } } } } return vocabularyRootResource; }
From source file:com.sri.tasklearning.ui.core.term.ExerciseStepParameter.java
public boolean isRangeParameter() { if (vc != null) { String min = this.getCurrentValueConstraintMinLiteral() != null ? this.getCurrentValueConstraintMinLiteral().getString() : null;//from w w w .j av a2 s.c o m String max = this.getCurrentValueConstraintMaxLiteral() != null ? this.getCurrentValueConstraintMaxLiteral().getString() : null; if (min != null || max != null) return true; Set<String> types = getPossibleEnumTypes(false); Stream<String> stream = types.stream(); // Stream<String> stream2 = types.stream(); // stream2.map(x -> TypeUtilities.getUnqualifiedTypeName(x)).forEach(x -> System.out.println("Element " + x)); return stream.map(x -> TypeUtilities.getUnqualifiedTypeName(x)) .anyMatch(x -> NUMERIC_RANGE_TYPES.contains(x)); } return false; }
From source file:com.ggvaidya.scinames.summary.NameStabilityView.java
private Set<TaxonConcept> getBinomialTaxonConceptsIntersection(Project p, Dataset ds1, Dataset ds2) { Set<TaxonConcept> clusters1 = getTaxonConceptsForDataset(p, ds1); Set<TaxonConcept> clusters2 = getTaxonConceptsForDataset(p, ds2); return clusters1.stream().filter(c -> clusters2.contains(c)).collect(Collectors.toSet()); }
From source file:com.netflix.spinnaker.clouddriver.cloudfoundry.client.ServiceInstances.java
private Set<CloudFoundrySpace> vetSharingOfServicesArgumentsAndGetSharingSpaces(String sharedFromRegion, @Nullable String serviceInstanceName, @Nullable Set<String> sharingRegions, String gerund) { if (isBlank(serviceInstanceName)) { throw new CloudFoundryApiException("Please specify a name for the " + gerund + " service instance"); }//w ww .ja v a 2s .c o m sharingRegions = Optional.ofNullable(sharingRegions).orElse(Collections.emptySet()); if (sharingRegions.size() == 0) { throw new CloudFoundryApiException( "Please specify a list of regions for " + gerund + " '" + serviceInstanceName + "'"); } return sharingRegions.stream().map(r -> { if (sharedFromRegion.equals(r)) { throw new CloudFoundryApiException( "Cannot specify 'org > space' as any of the " + gerund + " regions"); } return orgs.findSpaceByRegion(r).orElseThrow( () -> new CloudFoundryApiException("Cannot find region '" + r + "' for " + gerund)); }).collect(toSet()); }