List of usage examples for java.util.stream Collectors collectingAndThen
public static <T, A, R, RR> Collector<T, A, RR> collectingAndThen(Collector<T, A, R> downstream, Function<R, RR> finisher)
From source file:org.keycloak.models.jpa.JpaRealmProvider.java
@Override public List<GroupModel> getGroups(RealmModel realm) { RealmEntity ref = em.getReference(RealmEntity.class, realm.getId()); return ref.getGroups().stream().map(g -> session.realms().getGroupById(g.getId(), realm)) .sorted(Comparator.comparing(GroupModel::getName)) .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); }
From source file:org.keycloak.models.jpa.JpaRealmProvider.java
@Override public List<GroupModel> getTopLevelGroups(RealmModel realm) { RealmEntity ref = em.getReference(RealmEntity.class, realm.getId()); return ref.getGroups().stream().filter(g -> g.getParent() == null) .map(g -> session.realms().getGroupById(g.getId(), realm)) .sorted(Comparator.comparing(GroupModel::getName)) .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); }
From source file:org.kuali.rice.core.impl.security.PropertySuppressionServiceImpl.java
private static <T, K, U> Collector<T, ?, Map<K, U>> nullSafeToMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) { return Collectors.collectingAndThen(Collectors.toList(), list -> { Map<K, U> result = new HashMap<>(); for (T item : list) { K key = keyMapper.apply(item); if (result.putIfAbsent(key, valueMapper.apply(item)) != null) { throw new IllegalStateException(String.format("Duplicate key %s", key)); }// w w w .j a v a 2s .c om } return result; }); }