/** * Returns a stream consisting of the elements of this stream which are * instances of given class. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate</a> * operation. * * @param <TT> a type of instances to select. * @param clazz a class which instances should be selected * @return the new stream */ @SuppressWarnings("unchecked") public <TT> StreamEx<TT> select(Class<TT> clazz) { return (StreamEx<TT>) filter(clazz::isInstance); }
/** * Returns a stream consisting of the elements of this stream for which the * supplied mapper function returns the given value. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate * operation</a>. * * <p> * This method behaves like * {@code filter(t -> Objects.equals(value, mapper.apply(t)))}. * * @param <K> type of the value returned by mapper function. * @param mapper a * <a href="package-summary.html#NonInterference">non-interfering * </a>, <a href="package-summary.html#Statelessness">stateless</a> * function which is applied to the stream element and its returned * value is compared with the supplied value. * @param value a value the mapper function must return to pass the filter. * @return the new stream * @since 0.6.4 * @see #filter(Predicate) */ public <K> StreamEx<T> filterBy(Function<? super T, ? extends K> mapper, K value) { return value == null ? filter(t -> mapper.apply(t) == null) : filter(t -> value.equals(mapper.apply(t))); }
/** * Returns a stream consisting of the elements of this stream except those * for which the supplied mapper function returns the given value. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate * operation</a>. * * <p> * This method behaves like * {@code filter(t -> !Objects.equals(value, mapper.apply(t)))}. * * @param <K> type of the value returned by mapper function. * @param mapper a * <a href="package-summary.html#NonInterference">non-interfering * </a>, <a href="package-summary.html#Statelessness">stateless</a> * function which is applied to the stream element and its returned * value is compared with the supplied value. * @param value a value the mapper function must not return to pass the * filter. * @return the new stream * @since 0.6.4 * @see #remove(Predicate) */ public <K> StreamEx<T> removeBy(Function<? super T, ? extends K> mapper, K value) { return value == null ? filter(t -> mapper.apply(t) != null) : filter(t -> !value.equals(mapper.apply(t))); }
/** * Returns a stream consisting of the elements of this stream that don't * equal to the given value. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate</a> * operation. * * @param value the value to remove from the stream. If the value is null * then all nulls will be removed (like {@link #nonNull()} works). * Otherwise {@code value.equals()} will be used to test stream * values and matching elements will be removed. * @return the new stream * @since 0.2.2 * @see #without(Object...) * @see #remove(Predicate) */ public StreamEx<T> without(T value) { if (value == null) return filter(Objects::nonNull); return remove(value::equals); }
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(); }
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(); } }
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(); }