List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:com.netflix.spinnaker.fiat.controllers.AuthorizeController.java
@RequestMapping(value = "/{userId:.+}/accounts", method = RequestMethod.GET) public Set<Account.View> getUserAccounts(@PathVariable String userId) { return permissionsRepository.get(ControllerSupport.convert(userId)).orElseThrow(NotFoundException::new) .getView().getAccounts().stream().collect(Collectors.toSet()); }
From source file:com.vsct.dt.hesperides.resources.HesperidesModuleResource.java
@GET @Timed/* www .ja v a 2 s.c om*/ @ApiOperation("Get all module names") public Collection<String> getModuleNames(@Auth final User user) { return modules.getAllModules().stream().map(Module::getName).collect(Collectors.toSet()); }
From source file:ch.ifocusit.plantuml.utils.ClassUtils.java
public static Set<Class> getGenericTypes(ParameterizedType type) { return Stream.of(type.getActualTypeArguments()).filter(Class.class::isInstance).map(Class.class::cast) .collect(Collectors.toSet()); }
From source file:com.onyxscheduler.domain.Job.java
public static Job fromQuartzJobDetailAndTriggers(JobDetail jobDetail, Set<? extends org.quartz.Trigger> triggers) { try {/* w ww. j a v a2 s . c o m*/ Job job = (Job) jobDetail.getJobClass().newInstance(); org.quartz.JobKey jobKey = jobDetail.getKey(); job.setId(UUID.fromString((String) jobDetail.getJobDataMap().remove(ID_DATAMAP_KEY))); job.setName(jobKey.getName()); job.setGroup(jobKey.getGroup()); job.setTriggers(triggers.stream().map(Trigger::fromQuartzTrigger).collect(Collectors.toSet())); job.initFromDataMap(jobDetail.getJobDataMap()); return job; } catch (InstantiationException | IllegalAccessException e) { throw Throwables.propagate(e); } }
From source file:ddf.catalog.validation.impl.validator.RequiredAttributesMetacardValidator.java
/** * Creates a {@code RequiredAttributesMetacardValidator} with the given metacard type name and * set of attribute names representing the required attributes. * <p>/* www .ja v a 2 s. com*/ * This validator will only validate {@link Metacard}s that have the type name specified by * {@code metacardTypeName} (case-sensitive). * <p> * Any missing required attributes will be flagged as metacard-level validation errors. * * @param metacardTypeName the name of the metacard type this validator can validate, cannot * be null * @param requiredAttributes the names of the attributes this validator will check for, cannot * be null or empty * @throws IllegalArgumentException if {@code metacardTypeName} is null or if * {@code requiredAttributes} is null or empty */ public RequiredAttributesMetacardValidator(final String metacardTypeName, final Set<String> requiredAttributes) { Preconditions.checkArgument(metacardTypeName != null, "The metacard type name cannot be null."); Preconditions.checkArgument(CollectionUtils.isNotEmpty(requiredAttributes), "Must specify at least one required attribute."); this.metacardTypeName = metacardTypeName; this.requiredAttributes = requiredAttributes.stream().filter(Objects::nonNull).collect(Collectors.toSet()); }
From source file:se.uu.it.cs.recsys.constraint.util.ConstraintResultConverter.java
public Map<Integer, Set<Course>> convert(SetVar[] in) { Map<Integer, Set<Course>> result = new HashMap<>(); if (in == null || in.length == 0) { LOGGER.debug("Input result is empty!"); return result; }//from ww w . ja va 2 s. c om int i = 1; for (SetVar var : in) { LOGGER.debug("SetVar to be converted: " + var.toString()); if (var.dom() == null || var.dom().isEmpty()) { LOGGER.debug("The {}th var domain is empty.", i); i++; continue; } SetDomainValueEnumeration ve = (SetDomainValueEnumeration) (var.dom().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 -> { Course courseInfo = new Course.Builder().setName(course.getName()) .setCredit(course.getCredit().getCredit()).setCode(course.getCode()) .setLevel(CourseLevel.ofDBString(course.getLevel().getLevel())) .setTaughtYear(Integer.valueOf(course.getTaughtYear())) .setStartPeriod(Integer.valueOf(course.getStartPeriod())) .setEndPeriod(Integer.valueOf(course.getEndPeriod())).build(); return courseInfo; }).collect(Collectors.toSet()); result.put(i, courseInfoSet); i++; } return result; }
From source file:com.onyxscheduler.domain.Job.java
public Set<org.quartz.Trigger> buildQuartzTriggers() { return triggers.stream().map(Trigger::buildQuartzTrigger).collect(Collectors.toSet()); }
From source file:com.devicehive.auth.rest.providers.JwtTokenAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String token = (String) authentication.getPrincipal(); try {/*from ww w .j av a 2 s . c o m*/ JwtPayload jwtPayload = jwtClientService.getPayload(token); if (jwtPayload == null || (jwtPayload.getExpiration() != null && jwtPayload.getExpiration().before(timestampService.getDate())) || jwtPayload.getTokenType().equals(TokenType.REFRESH)) { throw new BadCredentialsException("Unauthorized"); } logger.debug("Jwt token authentication successful"); HivePrincipal principal = new HivePrincipal(); if (jwtPayload.getUserId() != null) { UserVO userVO = userService.findById(jwtPayload.getUserId()); principal.setUser(userVO); } Set<String> networkIds = jwtPayload.getNetworkIds(); if (networkIds != null) { if (networkIds.contains("*")) { principal.setAllNetworksAvailable(true); } else { principal.setNetworkIds(networkIds.stream().map(Long::valueOf).collect(Collectors.toSet())); } } Set<String> deviceGuids = jwtPayload.getDeviceGuids(); if (deviceGuids != null) { if (deviceGuids.contains("*")) { principal.setAllDevicesAvailable(true); } else { principal.setDeviceGuids(deviceGuids); } } Set<String> availableActions = jwtPayload.getActions(); if (availableActions != null) { if (availableActions.contains("*")) { principal.setActions(AvailableActions.getAllHiveActions()); } else if (availableActions.isEmpty()) { principal.setActions(AvailableActions.getClientHiveActions()); } else { principal.setActions( availableActions.stream().map(HiveAction::fromString).collect(Collectors.toSet())); } } return new HiveAuthentication(principal, AuthorityUtils.createAuthorityList(HiveRoles.JWT)); } catch (Exception e) { throw new BadCredentialsException("Unauthorized"); } }
From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java
private static void countRecvCallSites(Collection<ICoReTypeName> types, ProjectUsageStore store) throws IOException { DescriptiveStatistics statistics = new DescriptiveStatistics(); for (ICoReTypeName type : types) { if (store.getProjects(type).size() < 10) { continue; }//from w ww . j a v a 2s . co m int numDistinctRecvCallsite = store.load(type, new PointsToUsageFilter()).stream() .flatMap(usage -> usage.getReceiverCallsites().stream()).map(CallSite::getMethod) .collect(Collectors.toSet()).size(); if (numDistinctRecvCallsite > 0) { statistics.addValue(numDistinctRecvCallsite); System.out.printf(Locale.US, "%s: %d\n", CoReNames.vm2srcQualifiedType(type), numDistinctRecvCallsite); } } System.out.println(); System.out.printf(Locale.US, "mean: %.3f, stddev: %.3f, median: %.1f\n", statistics.getMean(), statistics.getStandardDeviation(), statistics.getPercentile(50)); }
From source file:com.publictransitanalytics.scoregenerator.output.NetworkAccessibility.java
public NetworkAccessibility(final int taskCount, final ScoreCard scoreCard, final Grid grid, final Set<Sector> centerSectors, final LocalDateTime startTime, final LocalDateTime endTime, final Duration tripDuration, final Duration samplingInterval, final boolean backward, final Duration inServiceTime) throws InterruptedException { type = AccessibilityType.NETWORK_ACCESSIBILITY; direction = backward ? Direction.INBOUND : Direction.OUTBOUND; mapBounds = new Bounds(grid.getBounds()); boundsCenter = new Point(grid.getBounds().getCenter()); this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss")); this.endTime = endTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss")); this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true); this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true); this.taskCount = taskCount; final Set<Sector> sectors = grid.getAllSectors(); totalSectors = grid.getReachableSectors().size(); final ImmutableMap.Builder<Bounds, Integer> countBuilder = ImmutableMap.builder(); for (final Sector sector : sectors) { if (scoreCard.hasPath(sector)) { final Bounds bounds = new Bounds(sector); countBuilder.put(bounds, scoreCard.getReachedCount(sector)); }/*from ww w . ja v a 2s .c o m*/ } sectorCounts = countBuilder.build(); this.centerPoints = centerSectors.stream().map(sector -> new Point(sector.getBounds().getCenter())) .collect(Collectors.toSet()); sampleCount = centerPoints.size(); inServiceSeconds = inServiceTime.getSeconds(); }