/** * Checks if the editor is a primary editor in the main editing area. */ private boolean isPrimaryEditor(@NotNull Editor editor) { final Project project = editor.getProject(); if (project == null) return false; final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project); return StreamEx.of(fileEditorManager.getAllEditors()) .anyMatch(fileEditor -> editor.equals(EditorUtil.getEditorEx(fileEditor))); }
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); }
/** * Returns a sequential {@code StreamEx} containing a single element. * * @param <T> the type of stream element * @param element the single element * @return a singleton sequential stream * @see Stream#of(Object) */ public static <T> StreamEx<T> of(T element) { return of(new ConstSpliterator.OfRef<>(element, 1, true)); }
/** * Returns the stream which covers all the elements emitted by this * emitter. * * @return the new stream */ default StreamEx<T> stream() { return of(spliterator()); } }
/** * Returns a sequential {@code DoubleStreamEx} containing a single element. * * @param element the single element * @return a singleton sequential stream */ public static DoubleStreamEx of(double element) { return of(new ConstSpliterator.OfDouble(element, 1, true)); }
/** * Returns a sequential {@code IntStreamEx} containing a single element. * * @param element the single element * @return a singleton sequential stream */ public static IntStreamEx of(int element) { return of(new ConstSpliterator.OfInt(element, 1, true)); }
/** * Returns the stream which covers all the elements emitted by this * emitter. * * @return the new stream */ default DoubleStreamEx stream() { return of(spliterator()); } }
/** * Returns a {@code DoubleCollector} that converts the input numbers to * strings and concatenates them, separated by the specified delimiter, in * encounter order. * * @param delimiter the delimiter to be used between each element * @return A {@code DoubleCollector} which concatenates the input numbers, * separated by the specified delimiter, in encounter order */ static DoubleCollector<?, String> joining(CharSequence delimiter) { return PartialCollector.joining(delimiter, null, null, false).asDouble( StreamExInternals.joinAccumulatorDouble(delimiter)); }
/** * Returns a {@code LongCollector} that converts the input numbers to * strings and concatenates them, separated by the specified delimiter, in * encounter order. * * @param delimiter the delimiter to be used between each element * @return A {@code LongCollector} which concatenates the input numbers, * separated by the specified delimiter, in encounter order */ static LongCollector<?, String> joining(CharSequence delimiter) { return PartialCollector.joining(delimiter, null, null, false).asLong( StreamExInternals.joinAccumulatorLong(delimiter)); }
/** * Returns an {@code IntCollector} that converts the input numbers to * strings and concatenates them, separated by the specified delimiter, in * encounter order. * * @param delimiter the delimiter to be used between each element * @return An {@code IntCollector} which concatenates the input numbers, * separated by the specified delimiter, in encounter order */ static IntCollector<?, String> joining(CharSequence delimiter) { return PartialCollector.joining(delimiter, null, null, false).asInt( StreamExInternals.joinAccumulatorInt(delimiter)); }
private <R> StreamEx<R> collapseInternal(BiPredicate<? super T, ? super T> collapsible, Function<T, R> mapper, BiFunction<R, T, R> accumulator, BinaryOperator<R> combiner) { CollapseSpliterator<T, R> spliterator = new CollapseSpliterator<>(collapsible, mapper, accumulator, combiner, spliterator()); return new StreamEx<>(spliterator, context); }
/** * Returns a sequential {@code LongStreamEx} containing a single element. * * @param element the single element * @return a singleton sequential stream */ public static LongStreamEx of(long element) { return of(new ConstSpliterator.OfLong(element, 1, true)); }
/** * Returns the stream which covers all the elements emitted by this * emitter. * * @return the new stream */ default LongStreamEx stream() { return of(spliterator()); } }
@Override public boolean tryAdvance(Consumer<? super U> action) { if(!init()) return false; target = TailSpliterator.tryAdvanceWithTail(target, action); if(target == null) { context = null; return false; } return true; }
@Override public void forEachRemaining(Consumer<? super U> action) { if(!init()) return; TailSpliterator.forEachWithTail(target, action); target = null; context = null; }
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 a sequential unordered {@code DoubleStreamEx} of given length * which elements are equal to supplied value. * * @param value the constant value * @param length the length of the stream * @return a new {@code DoubleStreamEx} * @since 0.1.2 */ public static DoubleStreamEx constant(double value, long length) { return of(new ConstSpliterator.OfDouble(value, length, false)); }
/** * Returns a sequential unordered {@code IntStreamEx} of given length which * elements are equal to supplied value. * * @param value the constant value * @param length the length of the stream * @return a new {@code IntStreamEx} * @since 0.1.2 */ public static IntStreamEx constant(int value, long length) { return of(new ConstSpliterator.OfInt(value, length, false)); }
/** * Returns a sequential unordered {@code LongStreamEx} of given length which * elements are equal to supplied value. * * @param value the constant value * @param length the length of the stream * @return a new {@code LongStreamEx} * @since 0.1.2 */ public static LongStreamEx constant(long value, long length) { return of(new ConstSpliterator.OfLong(value, length, false)); }