/** * 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 an empty sequential {@code StreamEx}. * * @param <T> the type of stream elements * @return an empty sequential stream */ public static <T> StreamEx<T> empty() { return of(Spliterators.emptySpliterator()); }
/** * 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 StreamEx} with given collection as its * source. * * @param <T> the type of collection elements * @param collection collection to create the stream of * @return a sequential {@code StreamEx} over the elements in given * collection * @see Collection#stream() */ public static <T> StreamEx<T> of(Collection<? extends T> collection) { return of(collection.spliterator()); }
/** * 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); }
/** * Returns a sequential ordered {@code StreamEx} whose elements are the * specified values. * * @param <T> the type of stream elements * @param elements the elements of the new stream * @return the new stream * @see Stream#of(Object...) */ @SafeVarargs public static <T> StreamEx<T> of(T... elements) { return of(Arrays.spliterator(elements)); }
/** * 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())); }
/** * Skips elements until the predicate is matched. Retains the first element that matches the * predicate. */ public S skipUntil(Predicate<T> predicate) { return supply(StreamEx.of(this).dropWhile(predicate.negate())); }
/** * 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())); }
/** * Skips elements until the predicate is matched. Retains the first element that matches the * predicate. */ public S skipUntil(Predicate<T> predicate) { return supply(StreamEx.of(this).dropWhile(predicate.negate())); }
private static void findAppendersTypes() { final Reflections reflections = new Reflections(); types = StreamEx .of(reflections.getSubTypesOf(Appender.class)) .filter(c -> !(c.isInterface() || Modifier.isAbstract(c.getModifiers()))) .map(Class::getName) .toList(); }
@Override @RequestMapping(value = SRV_PATH + M_R_CONFS, method = RequestMethod.GET) public List<OauthConfiguration> getServiceConfigurations() { return StreamEx .of(EnumSet.allOf(UserNetwork.class)) .map(oauth2Manager::getServiceConfiguration) .nonNull() .toList(); }
private boolean hasEStructuralFeature(final EObject eobject, final String name) { return StreamEx .of(eobject.eClass().getEAllStructuralFeatures()) .anyMatch(f -> check(f, name)); }
private Optional<EStructuralFeature> getEStructuralFeature(final EObject eobject, final String name) { return StreamEx .of(eobject.eClass().getEAllStructuralFeatures()) .findAny(f -> check(f, name)); }
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(); }
@Override public boolean evaluate(final EObject pObjectInstance, final EObject roleInstance, final POperation operation) { final PObject pObject = (PObject) pObjectInstance.eClass(); final Collection<EObject> permissionInstances = findPermission(pObject, roleInstance, operation); return StreamEx.of(permissionInstances).anyMatch(p -> checkPermission(pObjectInstance, p)); }
@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(); } }
private static Collection<EObject> findPermission(final PObject object, final EObject roleInstance, final POperation operation) { assert object.getEOperations().contains(operation); final List<EStructuralFeature> structuralFeatures = roleInstance.eClass().getEStructuralFeatures(); return StreamEx .of(structuralFeatures) .filter(f -> UamPackage.eINSTANCE.getPermission().isInstance(f.getEType()) && isOperationPermission((Permission) f.getEType(), operation)) .map(roleInstance::eGet) .map(EObject.class::cast) .toList(); }