List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:io.gravitee.management.service.impl.EventServiceImpl.java
private Set<EventEntity> convert(Set<Event> events) { return events.stream().map(this::convert).collect(Collectors.toSet()); }
From source file:org.sardineproject.sbyod.rest.AppWebUser.java
/** * Ask if a user with userIp has a access to the service with serviceId. * * @param userIp_ the IP address of the user * @param serviceId_ the ID of the service * @return PRECONDITION_FAILED if some parameter was wrong * "enabled : false" if service is disabled * "enabled : true" if service is enabled *//* w ww . jav a2s .c o m*/ @GET @Path("/{userIp}/service/{serviceId}") public Response getUserServices(@PathParam("userIp") String userIp_, @PathParam("serviceId") String serviceId_) { log.debug("AppWebUser: Getting rules for userIp = {} and serviceId = {}", userIp_, serviceId_); if (userIp_ == null || serviceId_ == null) return Response.status(Response.Status.PRECONDITION_FAILED).build(); Set<Host> users; ServiceId serviceId; try { users = get(HostService.class).getHostsByIp(Ip4Address.valueOf(userIp_)); serviceId = ServiceId.serviceId(serviceId_); } catch (Exception e) { return Response.status(Response.Status.PRECONDITION_FAILED).build(); } // get all connections a user has activated Set<Connection> connections = Sets.newHashSet(); users.forEach(u -> connections.addAll(get(ConnectionStore.class).getConnections(u))); // check if the connections contain a service with given service id if (connections.stream().map(Connection::getService).map(Service::id).collect(Collectors.toSet()) .contains(serviceId)) { return Response.ok(ENABLED_TRUE).build(); } return Response.ok(ENABLED_FALSE).build(); }
From source file:de.thingweb.servient.impl.MultiBindingThingServer.java
@Override public Set<Thing> getThings() { Set<Thing> things = this.things.values().stream().map(thing -> thing.getThingModel()) .collect(Collectors.toSet()); return things; }
From source file:org.openlmis.fulfillment.web.util.BasicOrderDtoBuilder.java
private Map<UUID, UserDto> getUsers(List<Order> orders) { Set<UUID> userIds = orders.stream().map(Order::getCreatedById).collect(Collectors.toSet()); return userReferenceDataService.findByIds(userIds).stream() .collect(Collectors.toMap(BaseDto::getId, Function.identity())); }
From source file:org.openlmis.fulfillment.web.util.StockEventBuilder.java
private List<StockEventLineItemDto> getLineItems(ProofOfDelivery proofOfDelivery, Profiler profiler) { profiler.start("GET_ORDERABLE_IDS"); Set<UUID> orderableIds = proofOfDelivery.getLineItems().stream() .map(ProofOfDeliveryLineItem::getOrderableId).collect(Collectors.toSet()); profiler.start("GET_ORDERABLES_BY_IDS"); Map<UUID, OrderableDto> orderables = getOrderables(orderableIds); profiler.start("GET_SOURCE_ID"); UUID sourceId = getSourceId(proofOfDelivery.getReceivingFacilityId(), proofOfDelivery.getSupplyingFacilityId(), proofOfDelivery.getProgramId()); profiler.start("CREATE_STOCK_EVENT_LINE_ITEMS"); return proofOfDelivery.getLineItems().stream() .map(lineItem -> createLineItem(proofOfDelivery, lineItem, orderables, sourceId)) .collect(Collectors.toList()); }
From source file:org.fenixedu.academic.thesis.ui.service.StudentCandidaciesService.java
public Set<ThesisProposalsConfiguration> getStudentConfigurations(Student student) { return student.getActiveRegistrations().stream() .flatMap(reg -> getConfigurationsForRegistration(reg).stream()).collect(Collectors.toSet()); }
From source file:com.github.mrstampy.gameboot.web.WebProcessor.java
@Override public void cleanup(AbstractRegistryKey<?> key) { if (!(key instanceof SystemIdKey)) return;//w w w .ja v a2 s. c om systemIds.entrySet().stream().filter(e -> e.getValue().equals(key)).collect(Collectors.toSet()) .forEach(e -> systemIds.remove(e.getKey())); }
From source file:se.uu.it.cs.recsys.constraint.util.ConstraintResultConverter.java
public Map<Integer, Set<Course>> convertToMap(Domain[] solution) { Map<Integer, Set<Course>> result = new HashMap<>(); if (solution == null || solution.length == 0) { LOGGER.debug("Input result is empty!"); return result; }/*from w w w .j a v a2 s .c o m*/ int i = 1; 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 -> { 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.thoughtworks.go.server.service.AdminsConfigService.java
private Set<CaseInsensitiveString> caseInsensitive(List<String> list) { return list.stream().map(CaseInsensitiveString::new).collect(Collectors.toSet()); }
From source file:com.hortonworks.streamline.streams.security.service.SecurityCatalogResource.java
private Response getRoleUsers(Long roleId) { Role role = catalogService.getRole(roleId); Set<Role> rolesToQuery = new HashSet<>(); if (role != null) { rolesToQuery.add(role);//from ww w . ja v a2 s . c o m rolesToQuery.addAll(catalogService.getChildRoles(roleId)); Set<User> res = rolesToQuery.stream().flatMap(r -> catalogService.listUsers(r).stream()) .collect(Collectors.toSet()); return WSUtils.respondEntities(res, OK); } throw EntityNotFoundException.byId(roleId.toString()); }