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.apache.cassandra.db.rows.AbstractRow.java

public boolean hasLiveData(int nowInSec) {
    if (primaryKeyLivenessInfo().isLive(nowInSec))
        return true;

    return Iterables.any(cells(), cell -> cell.isLive(nowInSec));
}

From source file:org.scassandra.cql.MapType.java

@Override
public boolean equals(Object expected, Object actual) {
    if (expected == null)
        return actual == null;
    if (actual == null)
        return false;

    if (expected instanceof Map) {
        final Map<?, ?> typedExpected = (Map<?, ?>) expected;
        final Map<?, ?> actualMap = (Map<?, ?>) actual;

        if (typedExpected.size() != actualMap.size())
            return false;

        for (final Map.Entry<?, ?> eachExpected : typedExpected.entrySet()) {
            boolean match = Iterables.any(actualMap.keySet(), new Predicate<Object>() {
                @Override//from ww w  .ja v  a 2s. co m
                public boolean apply(Object eachActualKey) {
                    Object eachActual = actualMap.get(eachActualKey);
                    return keyType.equals(eachExpected.getKey(), eachActualKey)
                            && valueType.equals(eachExpected.getValue(), eachActual);
                }
            });

            if (!match)
                return false;
        }
        return true;
    } else {
        throw throwInvalidType(expected, actual, this);
    }
}

From source file:org.obeonetwork.dsl.uml2.core.internal.listeners.UmlDesignerSessionListener.java

@Override
public void notify(int changeKind) {
    if (changeKind == SessionListener.OPENED || changeKind == SessionListener.SELECTED_VIEWS_CHANGE_KIND) {
        // The Reused viewpoint must not be disabled by the user as other
        // viewpoints depend on it, so it
        // is re-enabled automatically at the session opening or when the
        // user change the viewpoint
        // selection
        if (Iterables.any(session.getSelectedViewpoints(false), new Predicate<Viewpoint>() {
            @Override/*from   w  w  w  . j  a v a2s.c om*/
            public boolean apply(Viewpoint selectedViewpoint) {
                return UmlCoreViewpoints.isUmlViewpoint(selectedViewpoint);
            }
        })) {
            if (Iterables.indexOf(session.getSelectedViewpoints(false), new Predicate<Viewpoint>() {
                @Override
                public boolean apply(Viewpoint selectedViewpoint) {
                    return UmlCoreViewpoints.isReusedViewpoint(selectedViewpoint);
                }
            }) == -1) {
                UmlCoreViewpoints.enableReused(session);
            }
        }

    }
}

From source file:org.apache.aurora.scheduler.storage.db.DbAttributeStore.java

@Timed("attribute_store_save")
@Override// w  w w .j  ava  2s .  c om
public boolean saveHostAttributes(IHostAttributes hostAttributes) {
    checkNotBlank(hostAttributes.getHost());
    checkArgument(hostAttributes.isSetMode());

    if (Iterables.any(hostAttributes.getAttributes(), EMPTY_VALUES)) {
        throw new IllegalArgumentException("Host attributes contains empty values: " + hostAttributes);
    }

    Optional<IHostAttributes> existing = getHostAttributes(hostAttributes.getHost());
    if (existing.equals(Optional.of(hostAttributes))) {
        return false;
    } else if (existing.isPresent()) {
        mapper.updateHostModeAndSlaveId(hostAttributes.getHost(), hostAttributes.getMode(),
                hostAttributes.getSlaveId());
    } else {
        mapper.insert(hostAttributes);
    }

    mapper.deleteAttributeValues(hostAttributes.getHost());
    if (!hostAttributes.getAttributes().isEmpty()) {
        mapper.insertAttributeValues(hostAttributes);
    }

    return true;
}

From source file:com.google.uzaygezen.core.Query.java

public boolean isPotentialOverSelectivity() {
    boolean potentialOverSelectivity = Iterables.any(filteredIndexRanges,
            FilteredIndexRange.<F, R>potentialOverSelectivityExtractor());
    return potentialOverSelectivity;
}

From source file:com.anathema_roguelike.characters.ai.AIPathFinder.java

@Override
protected int getExtraCost(Point p, int direction, int previousDirection) {
    int ret = 0;/*from  w ww.  j  a va  2  s .  c o  m*/

    if (Iterables.any(level.getEntitiesAt(p, Character.class), new Predicate<Character>() {

        @Override
        public boolean apply(Character other) {
            return Faction.friendly(character, other);
        }
    })) {
        ret += 50;
    }

    return ret;
}

From source file:com.github.nethad.clustermeister.provisioning.torque.commands.RemoveNodeCommand.java

@Override
public void execute(CommandLineArguments arguments) {
    Collection<NodeInformation> allNodes = getRmiServerForApi().getAllNodes();
    LinkedList<String> nodeUuids = new LinkedList<String>();

    Scanner scanner = arguments.asScanner();

    while (scanner.hasNext()) {
        final String currentId = scanner.next();
        boolean validId = Iterables.any(allNodes, new Predicate<NodeInformation>() {
            @Override/*from www.jav a  2s  .  c om*/
            public boolean apply(NodeInformation input) {
                return input.getID().equalsIgnoreCase(currentId);
            }
        });
        if (validId) {
            nodeUuids.add(currentId);
        }
    }
    ListenableFuture<Void> removeNodesFuture = getNodeManager().removeNodes(nodeUuids);
    try {
        removeNodesFuture.get();
    } catch (InterruptedException ex) {
        throw new RuntimeException(ex);
    } catch (ExecutionException ex) {
        throw new RuntimeException(ex);
    }

}

From source file:com.clarkparsia.pelletserver.client.services.Realize.java

public Realize(KnowledgeBase kb, Endpoint endpoint, MimeType... mimetypes) {
    super(kb, endpoint, mimetypes);

    checkArgument(Iterables.any(this.mimetypes, PelletServerMimeTypes.getPredicate(MIMETYPE)),
            getName() + " service must support %s", MIMETYPE);
}

From source file:com.clarkparsia.pelletserver.client.services.Classify.java

public Classify(KnowledgeBase kb, Endpoint endpoint, MimeType... mimetypes) {
    super(kb, endpoint, mimetypes);

    checkArgument(Iterables.any(this.mimetypes, PelletServerMimeTypes.getPredicate(MIMETYPE)),
            getName() + " service must support %s", MIMETYPE);
}

From source file:ratpack.render.RenderableDecoratorSupport.java

protected RenderableDecoratorSupport() {
    TypeToken<T> typeToken = new TypeToken<T>(getClass()) {
    };//from   w  ww . j  a  v  a 2s .  c o  m

    Type type = typeToken.getType();
    if (type instanceof Class) {
        this.type = Types.cast(typeToken.getRawType());
    } else if (type instanceof ParameterizedType) {
        Iterable<Type> typeArgs = Arrays.asList(((ParameterizedType) type).getActualTypeArguments());
        if (Iterables.any(typeArgs, Predicates.not((t) -> t.getTypeName().equals("?")))) {
            throw new IllegalArgumentException("Invalid renderable type " + type
                    + ": due to type erasure, type parameter T of RenderableDecorator must be a Class or a parameterized type with '?' for all type variables (e.g. List<?>)");
        }
        this.type = Types.cast(typeToken.getRawType());
    } else {
        throw new InternalRatpackError("Unhandled type for RenderableDecorator: " + type.getClass());
    }
}