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(); }
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); }
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()); } }
/** * 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 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)); }
/** * 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)); }
/** * 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))); }
/** * Returns a sequential {@code EntryStream} containing four 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 * @param k4 the key of the fourth element * @param v4 the value of the fourth element * @return a sequential stream * @since 0.5.2 */ public static <K, V> EntryStream<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { return of(Stream.of(new SimpleImmutableEntry<>(k1, v1), new SimpleImmutableEntry<>(k2, v2), new SimpleImmutableEntry<>(k3, v3), new SimpleImmutableEntry<>(k4, v4))); }
/** * Returns a sequential {@code EntryStream} containing five 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 * @param k4 the key of the fourth element * @param v4 the value of the fourth element * @param k5 the key of the fifth element * @param v5 the value of the fifth element * @return a sequential stream * @since 0.5.2 */ public static <K, V> EntryStream<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { return of(Stream.of(new SimpleImmutableEntry<>(k1, v1), new SimpleImmutableEntry<>(k2, v2), new SimpleImmutableEntry<>(k3, v3), new SimpleImmutableEntry<>(k4, v4), new SimpleImmutableEntry<>(k5, v5))); }
/** * Returns a sequential {@code EntryStream} containing six 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 * @param k4 the key of the fourth element * @param v4 the value of the fourth element * @param k5 the key of the fifth element * @param v5 the value of the fifth element * @param k6 the key of the sixth element * @param v6 the value of the sixth element * @return a sequential stream * @since 0.5.2 */ public static <K, V> EntryStream<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) { return of(Stream.of(new SimpleImmutableEntry<>(k1, v1), new SimpleImmutableEntry<>(k2, v2), new SimpleImmutableEntry<>(k3, v3), new SimpleImmutableEntry<>(k4, v4), new SimpleImmutableEntry<>(k5, v5), new SimpleImmutableEntry<>(k6, v6))); }
/** * Returns an {@code EntryStream} object whose keys are indices of given * list and the values are the corresponding list elements. * * <p> * The list elements are accessed using {@link List#get(int)}, so the list * should provide fast random access. The list is assumed to be unmodifiable * during the stream operations. * * @param <V> list element type * @param list list to create the stream from * @return a new {@code EntryStream} * @since 0.2.3 */ public static <V> EntryStream<Integer, V> of(List<V> list) { return EntryStream.of(new RangeBasedSpliterator.AsEntry<>(list)); }
/** * Returns a sequential, ordered {@link EntryStream} created from given * {@link Iterator}. * * <p> * This method is roughly equivalent to * {@code EntryStream.of(Spliterators.spliteratorUnknownSize(iterator, ORDERED))} * , but may show better performance for parallel processing. * * <p> * Use this method only if you cannot provide better Stream source (like * {@code Collection} or {@code Spliterator}). * * @param <K> the type of stream keys * @param <V> the type of stream values * @param iterator an iterator to create the stream from. * @return the new stream * @since 0.5.1 */ public static <K, V> EntryStream<K, V> of(Iterator<? extends Entry<K, V>> iterator) { return of(new UnknownSizeSpliterator.USOfRef<>(iterator)); }
public static Map<?, Long> id(final Map<?, ? extends DomainJpa> objects) { return objects == null ? ImmutableMap.of() : EntryStream.of(objects).mapValues(DomainJpa::getId).toMap(); }
/** * Returns a sequential {@code EntryStream} containing {@code Entry} objects * composed from corresponding key and value in given two lists. * * <p> * The keys and values are accessed using {@link List#get(int)}, so the * lists should provide fast random access. The lists are assumed to be * unmodifiable during the stream operations. * * @param <K> the type of stream element keys * @param <V> the type of stream element values * @param keys the list of keys, assumed to be unmodified during use * @param values the list of values, assumed to be unmodified during use * @return a new {@code EntryStream} * @throws IllegalArgumentException if length of the lists differs. * @see StreamEx#zip(List, List, BiFunction) * @since 0.2.1 */ public static <K, V> EntryStream<K, V> zip(List<K> keys, List<V> values) { return of(new RangeBasedSpliterator.ZipRef<>(0, checkLength(keys.size(), values.size()), SimpleImmutableEntry::new, keys, values)); }
/** * 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(); }
/** * 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(); }
@Override public List<IRoleMetaInfo> getRoles() { return EntryStream.of(getAllRoles()).flatCollection(e -> map(e)).toList(); }