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

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

Introduction

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

Prototype

public static boolean contains(Iterable<?> iterable, @Nullable Object element) 

Source Link

Document

Returns true if iterable contains any object for which equals(element) is true.

Usage

From source file:org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates.java

/**
 * Matches {@link Reference}s with names in the given collection.
 *
 * @param T type of the reference, for example {@link Link}
 * @param names collection of values for the name attribute of the referenced object
 * @return predicate that will match references with names starting with the given prefix
 *//* ww w.j  a va2 s .co  m*/
public static <T extends Reference> Predicate<T> nameIn(final Iterable<String> names) {
    checkNotNull(names, "names must be defined");

    return new Predicate<T>() {
        @Override
        public boolean apply(T reference) {
            String name = reference.getName();
            return Iterables.contains(names, name);
        }

        @Override
        public String toString() {
            return "nameIn(" + Iterables.toString(names) + ")";
        }
    };
}

From source file:org.sonar.core.test.DefaultTestable.java

public int countTestCasesOfLine(Integer line) {
    int number = 0;
    for (Edge edge : coverEdges()) {
        if (Iterables.contains(lines(edge), line)) {
            number++;/*w w  w  .j  a  v a  2 s  . com*/
        }
    }
    return number;
}

From source file:io.bazel.rules.closure.BazelWorker.java

@Override
public Integer apply(Iterable<String> args) {
    if (Iterables.contains(args, "--persistent_worker")) {
        return runAsPersistentWorker();
    } else {/*from   ww w.  j ava 2s .  c om*/
        return delegate.apply(loadArguments(args, false));
    }
}

From source file:com.google.devtools.build.lib.util.CommandBuilder.java

public CommandBuilder addArgs(Iterable<String> args) {
    Preconditions.checkArgument(!Iterables.contains(args, null), "Arguments must not be null");
    Iterables.addAll(argv, args);//from ww w  .j  a  v a2 s. co m
    return this;
}

From source file:edu.umn.msi.tropix.storage.core.authorization.impl.IterableAuthorizationProviderImpl.java

public Boolean canUpload(final String id, final String callerIdentity) {
    if (Iterables.contains(canWriteIds, callerIdentity)) {
        return inPermission;
    } else {/* w ww  .  j  a v  a  2 s .  co  m*/
        return outPermission;
    }
}

From source file:org.eclipse.xtext.graphview.behavior.visibility.RevealRequest.java

public boolean removeFromSelection(IInstanceModelEditPart selectedEditPart) {
    if (!(selectedEditPart instanceof IInstanceModelEditPart))
        return false;
    else if (Iterables.contains(revealedEditPartMap.getLayoutables(), selectedEditPart))
        return selection.remove((IInstanceModelEditPart) selectedEditPart);
    else/*from w ww .  j a v  a 2s.com*/
        return addToSelection(selectedEditPart.getParent());
}

From source file:org.spongepowered.common.data.value.immutable.ImmutableSpongeCollectionValue.java

@Override
public boolean containsAll(Iterable<E> iterable) {
    for (E element : iterable) {
        if (!Iterables.contains(this.actualValue, element)) {
            return false;
        }//  w  w  w.  j  a  v  a2 s.  com
    }
    return true;
}

From source file:org.lanternpowered.server.data.value.immutable.ImmutableLanternCollectionValue.java

@Override
public boolean containsAll(Iterable<E> iterable) {
    for (E element : iterable) {
        if (!Iterables.contains(getActualValue(), element)) {
            return false;
        }/*from   w w  w  .j ava 2s  .c  om*/
    }
    return true;
}

From source file:com.codebullets.sagalib.processing.SagaTypeCacheLoader.java

private Collection<SagaType> sortAccordingToPreference(final Iterable<SagaType> unsorted) {
    Collection<SagaType> sorted = new LinkedList<>();

    // place preferred items first
    for (Class preferredClass : preferredOrder) {
        SagaType containedItem = containsItem(unsorted, preferredClass);
        if (containedItem != null) {
            sorted.add(containedItem);/*from ww  w . ja  v a 2 s.c o m*/
        }
    }

    // add all starting saga types next
    for (SagaType sagaType : unsorted) {
        if (sagaType.isStartingNewSaga() && !Iterables.contains(sorted, sagaType)) {
            sorted.add(sagaType);
        }
    }

    // add all the rest not yet in sorted list.
    for (SagaType sagaType : unsorted) {
        if (!Iterables.contains(sorted, sagaType)) {
            sorted.add(sagaType);
        }
    }

    return sorted;
}

From source file:io.katharsis.servlet.resource.repository.ProjectRepository.java

@JsonApiFindAllWithIds
public Iterable<Project> findAll(Iterable<Long> iterable, QueryParams queryParams) {
    return REPOSITORY.entrySet().stream().filter(p -> Iterables.contains(iterable, p.getKey()))
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).values();
}