static Map<Keyword, Object> toKeywordMap(Event event) { Map<String, Object> rawStringMap = OBJECT_MAPPER.convertValue(event, new TypeReference<Map<String, ?>>() {}); return EntryStream.of(rawStringMap) .filterValues(Objects::nonNull) .mapKeys(Keyword::intern) .toMap(); }
/** * Drains the stream content into the supplied {@code Map}. * * <p> * This is a <a href="package-summary.html#StreamOps">terminal</a> * operation. * * @param <M> type of the resulting map * @param map a mutable map to put the stream elements into * @return the supplied map, updated from this stream * @throws IllegalStateException if this stream contains duplicate keys, or * the stream contains the key which was already present in the map * (according to {@link Object#equals(Object)}) * @since 0.6.3 */ public <M extends Map<K, V>> M into(M map) { Consumer<? super Entry<K, V>> cons = toMapConsumer(map); if (isParallel()) { if (map instanceof ConcurrentMap) forEach(cons); else toMap().entrySet().forEach(cons); } else { spliterator().forEachRemaining(cons); } return map; }
/** * Returns an immutable {@link Map} containing the elements of this stream. * There's no guarantees on exact type of the returned {@code Map}. In * particular, no specific element order in the resulting {@code Map} is * guaranteed. The returned {@code Map} is guaranteed to be serializable if * all its elements are serializable. * * <p> * This is a terminal operation. * * @return a {@code Map} containing the elements of this stream * @throws IllegalStateException if this stream contains duplicate keys * (according to {@link Object#equals(Object)}) * @see #toMap() * @since 0.6.3 */ public Map<K, V> toImmutableMap() { Map<K, V> map = toMap(); return map.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(map); }
/** * Creates a {@link Map} containing the elements of this stream, then * performs finishing transformation and returns its result. There are no * guarantees on the type or serializability of the {@code Map} created. * * <p> * This is a <a href="package-summary.html#StreamOps">terminal</a> * operation. * * <p> * Created {@code Map} is guaranteed to be modifiable. * * <p> * For parallel stream the concurrent {@code Map} is created. * * @param <R> the type of the result * @param finisher a function to be applied to the intermediate map * @return result of applying the finisher transformation to the {@code Map} * of the stream elements. * @throws IllegalStateException if this stream contains duplicate keys * (according to {@link Object#equals(Object)}) * @see #toMap() * @since 0.5.5 */ public <R> R toMapAndThen(Function<? super Map<K, V>, R> finisher) { if (context.fjp != null) return context.terminate(() -> finisher.apply(toMap())); return finisher.apply(toMap()); }
public static Map<?, Long> id(final Map<?, ? extends DomainJpa> objects) { return objects == null ? ImmutableMap.of() : EntryStream.of(objects).mapValues(DomainJpa::getId).toMap(); }
@SuppressWarnings("null") public Map<String, Collection<Role>> getAllRoles() { return StreamEx.of(modelRegistry.getModels()).parallel().filter(notNull()::apply).mapToEntry(m -> m.getId(), m -> getAllRoles(m)).toMap(); } }