/** * 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))); }
/** * Returns a sequential, ordered {@link StreamEx} created from given * {@link Enumeration}. * * <p> * Use this method only if you cannot provide better Stream source (like * {@code Collection} or {@code Spliterator}). * * @param <T> the type of enumeration elements * @param enumeration an enumeration to create the stream from. * @return the new stream * @since 0.5.1 */ public static <T> StreamEx<T> of(Enumeration<? extends T> enumeration) { return of(new Iterator<T>() { @Override public boolean hasNext() { return enumeration.hasMoreElements(); } @Override public T next() { return enumeration.nextElement(); } }); }
private static <R> List<R> filter(final String query, final boolean inherited, final long limit, final Function<Logger, R> logMapper) { final String patternString = MessageFormat.format(QUERY_FORMAT, CAMEL_CASE_P03.matcher(CAMEL_CASE_P02.matcher(CAMEL_CASE_P01.matcher(query).replaceAll(CAMEL_CASE_R01)).replaceAll(CAMEL_CASE_R02)).replaceAll(CAMEL_CASE_R03)); final Pattern queryPattern = Pattern.compile(patternString, Pattern.UNICODE_CHARACTER_CLASS); return StreamEx.of(Logs.getLoggers()).parallel().filter(l -> inherited || l.getLevel() != null).filter(l -> queryPattern.matcher(l.getName()).matches()).limit(limit).map(logMapper).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 a sequential {@code StreamEx} containing a single element, if * non-null, otherwise returns an empty {@code StreamEx}. * * @param element the single element * @param <T> the type of stream elements * @return a stream with a single element if the specified element is * non-null, otherwise an empty stream * @since 0.1.1 */ public static <T> StreamEx<T> ofNullable(T element) { return element == null ? empty() : of(element); }
@Override public List<IRoleMetaInfo> getUserRoles(final String userId) { return StreamEx.of(modelRegistry.getModels()).flatCollection(m -> getUserRoles(userId, m.getId())).toList(); }
return new EntryStream<>(Spliterators.emptySpliterator(), context); if (other.length == 1) return mapToEntry(e -> other[0]); return cross(t -> of(other));
/** * Returns a {@link String} which is the concatenation of the results * of calling {@link String#valueOf(Object)} on each element of this stream * in encounter order. * * <p> * This is a <a href="package-summary.html#StreamOps">terminal</a> * operation. * * @return the result of concatenation. For empty input stream empty String * is returned. */ public String joining() { return map(String::valueOf).rawCollect(Collectors.joining()); }
/** * short-circuiting operation; limits the stream to the first element that fulfills the predicate */ public S limit(Predicate<T> predicate) { // #takeWhile comes with Java >= 9 return supply(StreamEx.of(this).takeWhileInclusive(predicate.negate())); }
/** * Returns a collection created by provided supplier function which contains * all the elements of the collections generated by provided mapper from * each element of this stream. * * <p> * This is a <a href="package-summary.html#StreamOps">terminal</a> * operation. * * <p> * This method is equivalent to * {@code flatCollection(mapper).toCollection(supplier)}, but may work * faster. * * @param <U> the type of the elements of the resulting collection * @param <C> the type of the resulting collection * @param mapper a <a * href="package-summary.html#NonInterference">non-interfering </a>, * <a href="package-summary.html#Statelessness">stateless</a> * function to apply to each element which produces a * {@link Collection} of new values * @param supplier a supplier for the resulting collection * @return the new collection. * @since 0.3.7 */ public <U, C extends Collection<U>> C toFlatCollection(Function<? super T, ? extends Collection<U>> mapper, Supplier<C> supplier) { return map(mapper).collect(supplier, Collection::addAll, Collection::addAll); }
/** * Performs a cross product of current stream with specified * {@link Collection} of elements. As a result the {@link EntryStream} is * created whose keys are elements of current stream and values are elements * of the specified collection. * * <p> * The resulting stream contains all the possible combinations of keys and * values. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate</a> * operation. * * @param <V> the type of collection elements * @param other the collection to perform a cross product with * @return the new {@code EntryStream} * @throws NullPointerException if other is null * @since 0.2.3 */ public <V> EntryStream<T, V> cross(Collection<? extends V> other) { if (other.isEmpty()) return new EntryStream<>(Spliterators.emptySpliterator(), context); return cross(t -> of(other)); }