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:forge.game.zone.Zone.java

public final boolean contains(final Predicate<Card> condition) {
    return Iterables.any(cardList, condition);
}

From source file:org.eclipse.sirius.tree.business.internal.migration.description.InitializeCreationToolElementsToSelectExpressionParticipant.java

@Override
protected void postLoad(Group group, Version loadedVersion) {
    if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) {
        EList<Viewpoint> ownedViewpoints = group.getOwnedViewpoints();
        for (Viewpoint viewpoint : ownedViewpoints) {
            boolean atLeastOneChange = false;
            for (TreeDescription treeDescription : Iterables.filter(viewpoint.getOwnedRepresentations(),
                    TreeDescription.class)) {
                Iterator<EObject> creationTools = Iterators.filter(treeDescription.eAllContents(),
                        Predicates.or(/*  w  ww  .  j a  va 2  s .c o m*/
                                Predicates.or(Predicates.instanceOf(TreeItemContainerDropTool.class),
                                        Predicates.instanceOf(TreeItemDragTool.class)),
                                Predicates.instanceOf(TreeItemCreationTool.class)));
                while (creationTools.hasNext()) {
                    AbstractToolDescription tool = (AbstractToolDescription) creationTools.next();
                    if (StringUtil.isEmpty(tool.getElementsToSelect())) {
                        tool.setElementsToSelect(ELEMENTS_TO_SELECT_EXPRESSION);
                        atLeastOneChange = true;
                    }
                }
            }

            if (atLeastOneChange) {
                // Add the Java Extension to use the service:
                if (!Iterables.any(viewpoint.getOwnedJavaExtensions(), new Predicate<JavaExtension>() {
                    @Override
                    public boolean apply(JavaExtension input) {
                        return JAVA_EXTENSION_QUALIFIED_NAME.equals(input.getQualifiedClassName());
                    }
                })) {
                    JavaExtension javaExtension = DescriptionFactory.eINSTANCE.createJavaExtension();
                    javaExtension.setQualifiedClassName(JAVA_EXTENSION_QUALIFIED_NAME);
                    viewpoint.getOwnedJavaExtensions().add(javaExtension);
                }
            }
        }
    }
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplStructSchemaExtractionStrategySupport.java

@Override
protected ModelProperty.StateManagementType determineStateManagementType(
        ModelSchemaExtractionContext<?> extractionContext, PropertyAccessorExtractionContext getterContext) {
    // Named.getName() needs to be handled specially
    if (getterContext.getMostSpecificDeclaration().getName().equals("getName")
            && Named.class.isAssignableFrom(extractionContext.getType().getRawClass())) {
        if (delegateType == null) {
            return ModelProperty.StateManagementType.MANAGED;
        }/*  w ww  .j  av a2  s.  com*/
        boolean delegateHasGetNameMethod = Iterables.any(Arrays.asList(delegateType.getMethods()),
                new Predicate<Method>() {
                    @Override
                    public boolean apply(Method method) {
                        return method.getName().equals("getName");
                    }
                });
        if (delegateHasGetNameMethod) {
            return ModelProperty.StateManagementType.DELEGATED;
        } else {
            return ModelProperty.StateManagementType.MANAGED;
        }
    }

    if (getterContext.isDeclaredInManagedType()) {
        if (getterContext.isDeclaredAsAbstract()) {
            return ModelProperty.StateManagementType.MANAGED;
        } else {
            return ModelProperty.StateManagementType.UNMANAGED;
        }
    } else {
        return ModelProperty.StateManagementType.DELEGATED;
    }
}

From source file:se.crafted.chrisb.ecoCreature.drops.categories.AbstractDropCategory.java

private boolean isNotRuleBroken(final Event event, AbstractDropSource dropSource) {
    return !Iterables.any(dropSource.getHuntingRules().values(), new Predicate<Rule>() {

        @Override/*from  w ww.j  a v a  2s  . c o m*/
        public boolean apply(Rule rule) {
            if (rule.isBroken(event)) {
                rule.enforce(event);
                LoggerUtil.getInstance().debug("Rule " + rule.getClass().getSimpleName() + " broken");
                return true;
            }

            return false;
        }
    });
}

From source file:org.gradle.api.internal.plugins.PluginManager.java

private boolean isApplied(final Class<?> pluginClass) {
    return Iterables.any(plugins, new Predicate<AppliedPluginImpl>() {
        public boolean apply(AppliedPluginImpl input) {
            return input.getImplementationClass().equals(pluginClass);
        }/* w  w  w.  j a  v a2s  . c  o m*/
    });
}

From source file:io.druid.segment.realtime.plumber.CoordinatorBasedSegmentHandoffNotifier.java

static boolean isHandOffComplete(List<ImmutableSegmentLoadInfo> serverView, SegmentDescriptor descriptor) {
    for (ImmutableSegmentLoadInfo segmentLoadInfo : serverView) {
        if (segmentLoadInfo.getSegment().getInterval().contains(descriptor.getInterval())
                && segmentLoadInfo.getSegment().getShardSpec().getPartitionNum() == descriptor
                        .getPartitionNumber()
                && segmentLoadInfo.getSegment().getVersion().compareTo(descriptor.getVersion()) >= 0
                && Iterables.any(segmentLoadInfo.getServers(), new Predicate<DruidServerMetadata>() {
                    @Override/*w  w  w.  j  a v  a  2 s  .  c o m*/
                    public boolean apply(DruidServerMetadata input) {
                        return input.isAssignable();
                    }
                })) {
            return true;
        }
    }
    return false;
}

From source file:com.google.devtools.build.lib.skyframe.SkylarkModuleCycleReporter.java

@Override
public boolean maybeReportCycle(SkyKey topLevelKey, CycleInfo cycleInfo, boolean alreadyReported,
        EventHandler eventHandler) {
    ImmutableList<SkyKey> pathToCycle = cycleInfo.getPathToCycle();
    ImmutableList<SkyKey> cycle = cycleInfo.getCycle();
    if (pathToCycle.isEmpty()) {
        return false;
    }/*from  w  w w  .j a  v a  2 s .c  o  m*/
    SkyKey lastPathElement = pathToCycle.get(pathToCycle.size() - 1);
    if (alreadyReported) {
        return true;
    } else if (Iterables.all(cycle, IS_SKYLARK_MODULE_SKY_KEY)
            // The last element before the cycle has to be a PackageFunction or SkylarkModule.
            && (IS_PACKAGE_SKY_KEY.apply(lastPathElement)
                    || IS_SKYLARK_MODULE_SKY_KEY.apply(lastPathElement))) {

        Function printer = new Function<SkyKey, String>() {
            @Override
            public String apply(SkyKey input) {
                if (input.argument() instanceof SkylarkImportLookupValue.SkylarkImportLookupKey) {
                    return ((SkylarkImportLookupValue.SkylarkImportLookupKey) input.argument()).importLabel
                            .toString();
                } else if (input.argument() instanceof PackageIdentifier) {
                    return ((PackageIdentifier) input.argument()) + "/BUILD";
                } else {
                    throw new UnsupportedOperationException();
                }
            }
        };

        StringBuilder cycleMessage = new StringBuilder().append("cycle detected in extension files: ")
                .append("\n    ").append(printer.apply(lastPathElement));

        AbstractLabelCycleReporter.printCycle(cycleInfo.getCycle(), cycleMessage, printer);
        // TODO(bazel-team): it would be nice to pass the Location of the load Statement in the
        // BUILD file.
        eventHandler.handle(Event.error(null, cycleMessage.toString()));
        return true;
    } else if (Iterables.any(cycle, IS_PACKAGE_LOOKUP) && Iterables.any(cycle, IS_WORKSPACE_FILE)
            && (IS_REPOSITORY_DIRECTORY.apply(lastPathElement) || IS_PACKAGE_SKY_KEY.apply(lastPathElement)
                    || IS_EXTERNAL_PACKAGE.apply(lastPathElement))) {
        // We have a cycle in the workspace file, report as such.
        Label fileLabel = (Label) Iterables.getLast(Iterables.filter(cycle, IS_AST_FILE_LOOKUP)).argument();
        String repositoryName = fileLabel.getPackageIdentifier().getRepository().strippedName();
        eventHandler.handle(Event.error(null, "Failed to load Skylark extension '" + fileLabel.toString()
                + "'.\n" + "It usually happens when the repository is not defined prior to being used.\n"
                + "Maybe repository '" + repositoryName + "' was defined later in your WORKSPACE file?"));
        return true;
    }
    return false;
}

From source file:org.atlasapi.remotesite.hulu.WritingHuluBrandAdapter.java

private static boolean ignoredUrl(final String uri) {
    Set<String> ignoredPrefixes = ImmutableSet.of("http://www.hulu.com/browse", "http://www.hulu.com/trailers",
            "http://www.hulu.com/movie-trailers", "http://www.hulu.com/search", "http://www.hulu.com/watch",
            "http://www.hulu.com/feed");

    return Iterables.any(ignoredPrefixes, new Predicate<String>() {
        @Override/*w  ww.  java 2  s  . co m*/
        public boolean apply(String input) {
            return uri.startsWith(input);
        }
    });
}

From source file:com.github.autermann.yaml.nodes.YamlPairsNode.java

@Override
public boolean hasNotNull(YamlNode key) {
    return has(key) && Iterables.any(this.multiMap.get(key), YamlNodes.notNullOrMissing());
}

From source file:org.apache.druid.segment.realtime.plumber.CoordinatorBasedSegmentHandoffNotifier.java

static boolean isHandOffComplete(List<ImmutableSegmentLoadInfo> serverView, SegmentDescriptor descriptor) {
    for (ImmutableSegmentLoadInfo segmentLoadInfo : serverView) {
        if (segmentLoadInfo.getSegment().getInterval().contains(descriptor.getInterval())
                && segmentLoadInfo.getSegment().getShardSpec().getPartitionNum() == descriptor
                        .getPartitionNumber()
                && segmentLoadInfo.getSegment().getVersion().compareTo(descriptor.getVersion()) >= 0
                && Iterables.any(segmentLoadInfo.getServers(), new Predicate<DruidServerMetadata>() {
                    @Override//  w w  w.j a  v a2 s .  c  o m
                    public boolean apply(DruidServerMetadata input) {
                        return input.segmentReplicatable();
                    }
                })) {
            return true;
        }
    }
    return false;
}