List of usage examples for java.util Set stream
default Stream<E> stream()
From source file:com.vsct.dt.strowgr.admin.gui.mapping.json.EntryPointWithPortsMappingJson.java
@JsonCreator public EntryPointWithPortsMappingJson(@JsonProperty("haproxy") String haproxy, @JsonProperty("hapUser") String hapUser, @JsonProperty("haproxyVersion") String haproxyVersion, @JsonProperty("bindingId") int bindingId, @JsonProperty("syslogPort") Integer syslogPort, @JsonProperty("frontends") Set<EntryPointFrontendWithPortMappingJson> frontends, @JsonProperty("backends") Set<EntryPointBackendMappingJson> backends, @JsonProperty("context") Map<String, String> context) { super(haproxy, hapUser, haproxyVersion, bindingId, frontends.stream().map(identity()).collect(Collectors.toSet()), backends.stream().map(identity()).collect(Collectors.toSet()), context); this.syslogPort = syslogPort; }
From source file:com.netflix.spinnaker.echo.artifacts.GitHubArtifactExtractor.java
@Override public List<Artifact> getArtifacts(String source, Map payload) { PushEvent pushEvent = objectMapper.convertValue(payload, PushEvent.class); String sha = pushEvent.after; Set<String> affectedFiles = pushEvent.commits.stream().map(c -> { List<String> fs = new ArrayList<>(); fs.addAll(c.added);//from w ww .ja va 2s. c o m fs.addAll(c.modified); return fs; }).flatMap(Collection::stream).collect(Collectors.toSet()); return affectedFiles.stream() .map(f -> Artifact.builder().name(f).version(sha).type("github/file") .reference(pushEvent.repository.contentsUrl.replace("{+path}", f)).build()) .collect(Collectors.toList()); }
From source file:kuona.processor.JenkinsProcessor.java
public void collectMetrics(BuildMetrics metrics) { try {//from w w w . ja v a2s . c o m puts("Updating " + getURI()); final int[] jobCount = { 0 }; final int[] buildCount = { 0 }; Set<String> jobNames = getJobs().keySet(); jobCount[0] = jobNames.size(); jobNames.stream().forEach(key -> { try { JobWithDetails job = getJob(key); puts("Updating " + key); final List<Build> builds = job.details().getBuilds(); buildCount[0] += builds.size(); builds.stream().forEach(buildDetails -> { try { final BuildWithDetails details = buildDetails.details(); Timestamp timestamp = new Timestamp(details.getTimestamp()); Date buildDate = new Date(timestamp.getTime()); int year = buildDate.getYear() + 1900; if (!metrics.activity.containsKey(year)) { metrics.activity.put(year, new int[12]); } int[] yearMap = metrics.activity.get(year); yearMap[buildDate.getMonth()] += 1; if (details.getResult() == null) { metrics.buildCountsByResult.put(BuildResult.UNKNOWN, metrics.buildCountsByResult.get(BuildResult.UNKNOWN) + 1); } else { metrics.buildCountsByResult.put(details.getResult(), metrics.buildCountsByResult.get(details.getResult()) + 1); } metrics.byDuration.collect(details.getDuration()); final List<Map> actions = details.getActions(); actions.stream().filter(action -> action != null).forEach(action -> { if (action.containsKey("causes")) { List<HashMap> causes = (List<HashMap>) action.get("causes"); causes.stream().filter(cause -> cause.containsKey("shortDescription")) .forEach(cause -> { metrics.triggers.add((String) cause.get("shortDescription")); }); } }); metrics.completedBuilds.add(details); } catch (IOException e) { e.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } }); metrics.dashboardServers.add(new HashMap<String, Object>() { { MainView serverInfo = getServerInfo(); put("name", serverInfo.getName()); put("description", serverInfo.getDescription()); put("uri", getURI().toString()); put("jobs", jobCount[0]); put("builds", buildCount[0]); } }); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.epam.ta.reportportal.events.handler.TicketActivitySubscriber.java
private String issuesIdsToString(Set<TestItemIssue.ExternalSystemIssue> externalSystemIssues, String separator) {//from ww w . j a v a 2s . co m if (null != externalSystemIssues && !externalSystemIssues.isEmpty()) { return externalSystemIssues.stream().map(externalSystemIssue -> externalSystemIssue.getTicketId() .concat(":").concat(externalSystemIssue.getUrl())).collect(Collectors.joining(separator)); } return null; }
From source file:dk.dma.ais.abnormal.analyzer.analysis.CloseEncounterAnalysisTest.java
@Test public void closeEncounterEventContainsTwoVesselBehaviours() throws Exception { analysis.clearTrackPairsAnalyzed();/* w ww. j a v a 2 s.c o m*/ final ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class); context.checking(new Expectations() { { ignoring(statisticsService).incAnalysisStatistics( with(CloseEncounterAnalysis.class.getSimpleName()), with(any(String.class))); ignoring(statisticsService).setAnalysisStatistics( with(CloseEncounterAnalysis.class.getSimpleName()), with(any(String.class)), with(any(Long.class))); oneOf(eventRepository).findOngoingEventByVessel(track.getMmsi(), CloseEncounterEvent.class); oneOf(eventRepository).save(with(eventCaptor.getMatcher())); } }); analysis.analyseCloseEncounter(track, closeTrack); Event event = eventCaptor.getCapturedObject(); Set<Behaviour> behaviours = event.getBehaviours(); assertEquals(2, behaviours.size()); assertEquals(1, behaviours.stream().filter(t -> t.getVessel().getMmsi() == track.getMmsi()).count()); assertEquals(1, behaviours.stream().filter(t -> t.getVessel().getMmsi() == closeTrack.getMmsi()).count()); behaviours.forEach(b -> { if (b.getVessel().getMmsi() == track.getMmsi()) { assertEquals(1, b.getTrackingPoints().size()); // No. of previous tracking points in event } else if (b.getVessel().getMmsi() == closeTrack.getMmsi()) { assertEquals(5, b.getTrackingPoints().size()); // No. of previous tracking points in event } }); }
From source file:com.thinkbiganalytics.metadata.modeshape.security.role.JcrAbstractRoleMembership.java
@Override public void setMemebers(GroupPrincipal... principals) { Set<GroupPrincipal> newMembers = Arrays.stream(principals).collect(Collectors.toSet()); Set<GroupPrincipal> oldMembers = streamGroups().collect(Collectors.toSet()); newMembers.stream().filter(u -> !oldMembers.contains(u)).forEach(this::addMember); oldMembers.stream().filter(u -> !newMembers.contains(u)).forEach(this::removeMember); }
From source file:se.uu.it.cs.recsys.constraint.util.ConstraintResultConverter.java
public List<Course> convert(Domain[] solution) { List<Course> result = new ArrayList<>(); if (solution == null || solution.length == 0) { LOGGER.debug("Input result is empty!"); return result; }/*from ww w.j a v a 2s . c o m*/ for (Domain var : solution) { LOGGER.debug("Solution domain to be converted: " + var.toString()); SetDomainValueEnumeration ve = (SetDomainValueEnumeration) (var.valueEnumeration()); Set<Integer> courseIds = new HashSet<>(); while (ve.hasMoreElements()) { int[] elemArray = ve.nextSetElement().toIntArray(); for (int elem : elemArray) { courseIds.add(elem); } } Set<se.uu.it.cs.recsys.persistence.entity.Course> courseEntities = this.courseRepository .findByAutoGenIds(courseIds); Set<Course> courseInfoSet = courseEntities.stream().map(course -> CourseConverter.convert(course)) .collect(Collectors.toSet()); result.addAll(courseInfoSet); } return result; }
From source file:com.netflix.genie.core.jpa.specifications.JpaClusterSpecs.java
/** * Generate a specification given the parameters. * * @param name The name of the cluster to find * @param statuses The statuses of the clusters to find * @param tags The tags of the clusters to find * @param minUpdateTime The minimum updated time of the clusters to find * @param maxUpdateTime The maximum updated time of the clusters to find * @return The specification/*ww w. j av a 2 s. c o m*/ */ public static Specification<ClusterEntity> find(final String name, final Set<ClusterStatus> statuses, final Set<String> tags, final Date minUpdateTime, final Date maxUpdateTime) { return (final Root<ClusterEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ClusterEntity_.name), name)); } if (minUpdateTime != null) { predicates.add(cb.greaterThanOrEqualTo(root.get(ClusterEntity_.updated), minUpdateTime)); } if (maxUpdateTime != null) { predicates.add(cb.lessThan(root.get(ClusterEntity_.updated), maxUpdateTime)); } if (tags != null && !tags.isEmpty()) { predicates .add(cb.like(root.get(ClusterEntity_.tags), JpaSpecificationUtils.getTagLikeString(tags))); } if (statuses != null && !statuses.isEmpty()) { //Could optimize this as we know size could use native array final List<Predicate> orPredicates = statuses.stream() .map(status -> cb.equal(root.get(ClusterEntity_.status), status)) .collect(Collectors.toList()); predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
From source file:com.controller.schedule.ScheduleSocialPostActionsServlet.java
private List<String> validateJsonData(String jsonDataString, String errorMsgSuffix, Supplier<Set<String>> requiredKeysBuilder) { List<String> errorMsgs = new ArrayList<>(); Map<String, Object> jsonDataMap = AppConstants.GSON.fromJson(jsonDataString, Map.class); Set<String> requiredKeys = requiredKeysBuilder.get(); Set<String> keySet = jsonDataMap.keySet(); requiredKeys.stream().filter((key) -> (!keySet.contains(key))).forEach((key) -> { errorMsgs.add(key + errorMsgSuffix); });//from w w w. j av a 2 s. com return errorMsgs; }
From source file:com.thinkbiganalytics.metadata.modeshape.security.role.JcrAbstractRoleMembership.java
@Override public void setMemebers(UsernamePrincipal... principals) { Set<UsernamePrincipal> newMembers = Arrays.stream(principals).collect(Collectors.toSet()); Set<UsernamePrincipal> oldMembers = streamUsers().collect(Collectors.toSet()); newMembers.stream().filter(u -> !oldMembers.contains(u)).forEach(this::addMember); oldMembers.stream().filter(u -> !newMembers.contains(u)).forEach(this::removeMember); }