Example usage for com.google.common.collect Iterables any

List of usage examples for com.google.common.collect Iterables any

Introduction

In this page you can find the example usage for com.google.common.collect Iterables any.

Prototype

public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns true if any element in iterable satisfies the predicate.

Usage

From source file:org.graylog.collector.file.naming.ExactFileStrategy.java

@Override
public boolean pathMatches(final Path path) {
    return Iterables.any(basePaths, new Predicate<Path>() {
        @Override/*from  ww  w .  ja v a2  s.c o  m*/
        public boolean apply(@Nullable Path basePath) {
            if (basePath == null) {
                return false;
            }

            Path normalizedPath = path.normalize();
            normalizedPath = basePath.getParent().resolve(normalizedPath);

            return basePath.equals(normalizedPath);
        }
    });
}

From source file:org.eclipse.incquery.querybasedfeatures.runtime.handler.QueryBasedFeatures.java

public static boolean checkEcorePackageAnnotation(EPackage pckg) {
    return Iterables.any(pckg.getEAnnotations(), new Predicate<EAnnotation>() {
        @Override//w ww  .j  av  a2s  .  c  o m
        public boolean apply(EAnnotation annotation) {
            if (QueryBasedFeatures.ECORE_ANNOTATION.equals(annotation.getSource())) {
                return Iterables.any(annotation.getDetails().entrySet(),
                        new Predicate<Entry<String, String>>() {
                            @Override
                            public boolean apply(Entry<String, String> entry) {
                                if (QueryBasedFeatures.SETTING_DELEGATES_KEY.equals(entry.getKey())) {
                                    StringTokenizer delegateTokents = new StringTokenizer(entry.getValue());
                                    while (delegateTokents.hasMoreTokens()) {
                                        if (QueryBasedFeatures.ANNOTATION_SOURCE
                                                .equals(delegateTokents.nextToken())) {
                                            return true;
                                        }
                                    }
                                }
                                return false;
                            }
                        });
            }
            return false;
        }
    });
}

From source file:org.apache.abdera2.common.selector.AbstractSelector.java

public boolean any(Iterable<X> items) {
    if (items == null)
        return false;
    return Iterables.any(items, this);
}

From source file:uk.ac.stfc.isis.ibex.epics.observing.FilteredCollectionObservable.java

private static <T1 extends INamed> Predicate<T1> filterByName(final Collection<String> namesToFilter) {
    return new Predicate<T1>() {
        @Override/*from   w  w w  . j  ava  2s.co m*/
        public boolean apply(final T1 ioc) {
            return !Iterables.any(namesToFilter, nameMatches(ioc));
        }
    };
}

From source file:org.gradle.api.reporting.dependents.internal.DependentComponentsRenderableDependency.java

public static DependentComponentsRenderableDependency of(ComponentSpec componentSpec,
        ComponentSpecInternal internalProtocol,
        LinkedHashSet<DependentComponentsRenderableDependency> children) {
    ComponentSpecIdentifier id = internalProtocol.getIdentifier();
    String name = DependentComponentsUtils.getBuildScopedTerseName(id);
    String description = componentSpec.getDisplayName();
    boolean buildable = true;
    if (componentSpec instanceof VariantComponentSpec) {
        // Consider variant aware components with no buildable binaries as non-buildables
        VariantComponentSpec variantComponentSpec = (VariantComponentSpec) componentSpec;
        buildable = Iterables.any(variantComponentSpec.getBinaries().values(), new Predicate<BinarySpec>() {
            @Override// www  . j a  v a 2 s .  co m
            public boolean apply(BinarySpec binarySpec) {
                return binarySpec.isBuildable();
            }
        });
    }
    boolean testSuite = false;
    return new DependentComponentsRenderableDependency(id, name, description, buildable, testSuite, children);
}

From source file:org.eclipse.sirius.business.internal.contribution.ReuseHelper.java

/**
 * Tests whether an object contains any contribution which use elements from
 * another as source and contribute to the target (or any of its children).
 * //  w  w w.j  av a 2s  .com
 * @param target
 *            the reuse target.
 * @param potentialSource
 *            the potential source of reuse.
 * @return <code>true</code> if the target contains any contribution which
 *         get values from the source (or any of its descendant) and put
 *         them in the target (or any of its descendants).
 */
public boolean reuses(final EObject target, final EObject potentialSource) {
    return Iterables.any(Iterables.filter(AllContents.of(target, true), Contribution.class),
            new Predicate<Contribution>() {
                public boolean apply(Contribution input) {
                    if (input.getSource() instanceof DirectEObjectReference
                            && input.getTarget() instanceof DirectEObjectReference) {
                        EObject sourceValue = ((DirectEObjectReference) input.getSource()).getValue();
                        EObject targetValue = ((DirectEObjectReference) input.getTarget()).getValue();
                        boolean fromSource = sourceValue == potentialSource
                                || EcoreUtil.isAncestor(potentialSource, sourceValue);
                        boolean toTarget = targetValue == target || EcoreUtil.isAncestor(target, targetValue);
                        return fromSource && toTarget;
                    } else {
                        return false;
                    }
                }
            });
}

From source file:org.eclipse.viatra.addon.querybasedfeatures.runtime.handler.QueryBasedFeatures.java

public static boolean checkEcorePackageAnnotation(EPackage pckg) {
    return Iterables.any(pckg.getEAnnotations(), annotation -> {
        if (QueryBasedFeatures.ECORE_ANNOTATION.equals(annotation.getSource())) {
            return Iterables.any(annotation.getDetails().entrySet(), entry -> {
                if (QueryBasedFeatures.SETTING_DELEGATES_KEY.equals(entry.getKey())) {
                    StringTokenizer delegateTokents = new StringTokenizer(entry.getValue());
                    while (delegateTokents.hasMoreTokens()) {
                        if (QueryBasedFeatures.ANNOTATION_SOURCE.equals(delegateTokents.nextToken())) {
                            return true;
                        }/*from w w  w .  j a v a 2s  .c  o  m*/
                    }
                }
                return false;
            });
        }
        return false;
    });
}

From source file:org.graylog.collector.file.naming.NumberSuffixStrategy.java

@Override
public boolean pathMatches(final Path path) {
    return Iterables.any(basePaths, new Predicate<Path>() {
        @Override//from   w w  w. j a  v  a  2 s  . c om
        public boolean apply(@Nullable Path basePath) {
            if (basePath == null) {
                return false;
            }

            Path normalizedPath = path.normalize();
            normalizedPath = basePath.getParent().resolve(normalizedPath);
            // only allow files in the same directory
            if (!basePath.getParent().equals(normalizedPath.getParent())) {
                return false;
            }
            final String filename = normalizedPath.getFileName().toString();
            final String baseFilename = basePath.getFileName().toString();

            // same files are a match
            if (filename.equals(baseFilename)) {
                return true;
            }

            // do the files have a common beginning? if not, they aren't related.
            if (!filename.startsWith(baseFilename)) {
                return false;
            }

            // check for number suffix
            final String onlySuffix = filename.substring(baseFilename.length());
            return onlySuffix.matches("^\\.\\d+$");
        }
    });
}

From source file:io.crate.metadata.Scalar.java

protected static boolean containsNullLiteral(Collection<Symbol> symbols) {
    return Iterables.any(symbols, NULL_LITERAL);
}

From source file:org.obiba.onyx.quartz.core.engine.questionnaire.question.Attributes.java

public static boolean containsAttribute(List<Attribute> attributes, String namespace, String name,
        Locale locale) {//from w w  w .  j a v  a2  s  .  c om
    return Iterables.any(attributes, predicate(namespace, name, locale));
}