static Event fromKeywordMap(Map<Keyword, ?> map) { Map<Keyword, ?> encodedMap = EventUtils.encodeNemesis(map); Map<String, Object> convertedMap = new HashMap<>(); EntryStream.of(encodedMap) .mapKeys(Keyword::getName) .mapValues(value -> value != null && value instanceof Keyword ? ((Keyword) value).getName() : value) .forKeyValue(convertedMap::put); return OBJECT_MAPPER.convertValue(convertedMap, Event.class); }
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(); }
/** * Returns an empty sequential {@code EntryStream}. * * @param <K> the type of stream element keys * @param <V> the type of stream element values * @return an empty sequential stream * @since 0.0.8 */ public static <K, V> EntryStream<K, V> empty() { return of(Stream.empty()); }
/** * Returns a sequential {@code StreamEx} of given {@link Map} keys which * corresponding values match the supplied filter. * * @param <T> the type of map keys and created stream elements * @param <V> the type of map values * @param map input map * @param valueFilter a predicate used to test values * @return a sequential {@code StreamEx} over the keys of given {@code Map} * which corresponding values match the supplied filter. * @throws NullPointerException if map is null * @see Map#keySet() */ public static <T, V> StreamEx<T> ofKeys(Map<T, V> map, Predicate<? super V> valueFilter) { return EntryStream.of(map).filterValues(valueFilter).keys(); }
/** * 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 a sequential {@code StreamEx} of given {@link Map} values which * corresponding keys match the supplied filter. * * @param <K> the type of map keys * @param <T> the type of map values and created stream elements * @param map input map * @param keyFilter a predicate used to test keys * @return a sequential {@code StreamEx} over the values of given * {@code Map} which corresponding keys match the supplied filter. * @throws NullPointerException if map is null * @see Map#values() */ public static <K, T> StreamEx<T> ofValues(Map<K, T> map, Predicate<? super K> keyFilter) { return EntryStream.of(map).filterKeys(keyFilter).values(); }
/** * 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); }
@Override public List<IRoleMetaInfo> getRoles() { return EntryStream.of(getAllRoles()).flatCollection(e -> map(e)).toList(); }
@PostConstruct protected void configure() { /* * Custom {@link ClassMap}s registration from spring application context */ classMaps.forEach(factory::registerClassMap); /* * Custom {@link ClassMapBuilder}s registration from spring application * context */ classMapBuilders.forEach(factory::registerClassMap); /* * Register custom interface/parent to implementation mappings from * spring application context */ StreamEx.of(classMappings).flatMapToEntry(c -> c.getClassMapping()).forKeyValue(factory::registerConcreteType); /* * Custom {@link Mapper}s registration from spring application context */ mappers.forEach(factory::registerMapper); /* * Custom {@link Converter) registration from spring application context */ converters.forEach(factory.getConverterFactory()::registerConverter); /* * Custom {@link ObjectFactory) registration from spring application */ objectFactoryDefenitions.forEach(this::registerObjectFactories); facade = factory.getMapperFacade(); }
/** * Returns a stream consisting of the elements of this stream which values * don't match the given predicate. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate</a> * operation. * * @param valuePredicate a non-interfering, stateless predicate to apply to * the value of each element to determine if it should be excluded * @return the new stream */ public EntryStream<K, V> removeValues(Predicate<? super V> valuePredicate) { return filterValues(valuePredicate.negate()); }
/** * Returns an {@code EntryStream} object whose keys are indices of given * array and the values are the corresponding array elements. * * @param <V> array element type * @param array array to create the stream from * @return a new {@code EntryStream} * @since 0.2.3 */ public static <V> EntryStream<Integer, V> of(V[] array) { return of(Arrays.asList(array)); }
/** * 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()); }
/** * Returns a sequential {@link EntryStream} created from given * {@link Spliterator}. * * @param <K> the type of stream keys * @param <V> the type of stream values * @param spliterator a spliterator to create the stream from. * @return the new stream * @since 0.3.4 */ public static <K, V> EntryStream<K, V> of(Spliterator<? extends Entry<K, V>> spliterator) { return of(StreamSupport.stream(spliterator, false)); }
private static List<Map<Keyword, ?>> getClojureMapFromFile(String resourcePath) throws IOException { List<Map<String, ?>> allEvents = new ObjectMapper().readValue(Resources.getResource(resourcePath), new TypeReference<List<Map<String, ?>>>() {}); return allEvents.stream() .map(singleEvent -> { Map<Keyword, Object> convertedEvent = new HashMap<>(); EntryStream.of(singleEvent) .mapKeys(Keyword::intern) .mapValues(value -> value instanceof String ? Keyword.intern((String) value) : value) .forKeyValue(convertedEvent::put); return convertedEvent; }) .collect(Collectors.toList()); } }
@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(); } }
/** * Returns an {@code EntryStream} object which contains the entries of * supplied {@code Map}. * * @param <K> the type of map keys * @param <V> the type of map values * @param map the map to create the stream from * @return a new {@code EntryStream} */ public static <K, V> EntryStream<K, V> of(Map<K, V> map) { return of(map.entrySet().stream()); }
/** * Returns a sequential {@code EntryStream} containing a single key-value * pair * * @param <K> the type of key * @param <V> the type of value * @param key the key of the single element * @param value the value of the single element * @return a singleton sequential stream */ public static <K, V> EntryStream<K, V> of(K key, V value) { return of(Stream.of(new SimpleImmutableEntry<>(key, value))); }
/** * Returns a sequential {@code EntryStream} containing two key-value pairs * * @param <K> the type of key * @param <V> the type of value * @param k1 the key of the first element * @param v1 the value of the first element * @param k2 the key of the second element * @param v2 the value of the second element * @return a sequential stream * @since 0.2.3 */ public static <K, V> EntryStream<K, V> of(K k1, V v1, K k2, V v2) { return of(Stream.of(new SimpleImmutableEntry<>(k1, v1), new SimpleImmutableEntry<>(k2, v2))); }
/** * Returns a sequential {@code EntryStream} containing three key-value pairs * * @param <K> the type of key * @param <V> the type of value * @param k1 the key of the first element * @param v1 the value of the first element * @param k2 the key of the second element * @param v2 the value of the second element * @param k3 the key of the third element * @param v3 the value of the third element * @return a sequential stream * @since 0.2.3 */ public static <K, V> EntryStream<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) { return of(Stream.of(new SimpleImmutableEntry<>(k1, v1), new SimpleImmutableEntry<>(k2, v2), new SimpleImmutableEntry<>(k3, v3))); }