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:io.sarl.lang.scoping.batch.SARLMapExtensions.java

/** Replies the elements of the given map except the pairs with the given keys.
 *
 * <p>The replied map is a view on the given map. It means that any change
 * in the original map is reflected to the result of this operation.
 *
 * @param <K> - type of the map keys.
 * @param <V> - type of the map values.
 * @param map - the map to update.//from  w  ww .  j  a v a 2s. c  o  m
 * @param keys - the keys of the pairs to remove.
 * @return the map with the content of the map except the pairs.
 */
@Pure
public static <K, V> Map<K, V> operator_minus(Map<K, V> map, final Iterable<?> keys) {
    return Maps.filterKeys(map, new Predicate<K>() {
        @Override
        public boolean apply(K input) {
            return !Iterables.contains(keys, input);
        }
    });
}

From source file:org.eclipse.sirius.business.api.control.SiriusUncontrolCommand.java

/**
 * Get the resource that contains the analysis which has the specified
 * object as main models references./*from  w  w w.  jav  a 2 s. com*/
 * 
 * @param object
 *            The object to search. This object must be a root of a semantic
 *            model.
 * @return the corresponding resource if found, false otherwise.
 */
protected Resource getAirdResourceWithAnalysisOn(final EObject object) {

    for (final Resource anResource : session.getAllSessionResources()) {
        for (final DAnalysis analysis : getAnalyses(anResource)) {
            Set<EObject> releventModels = new DAnalysisQuery(analysis).getMainModels();
            if (Iterables.contains(releventModels, object)) {
                return anResource;
            }
        }
    }
    return null;
}

From source file:tile80.tile80.Tile80.java

public boolean equals(Object o) {
    if (o == null || !(o instanceof Tile80))
        return false;
    if (o == this)
        return true;
    Tile80 t = (Tile80) o;/*w w  w.j  ava 2  s  . c o  m*/
    if (t.getId().equals(this.getId()) && t.getPos().equals(this.getPos())) {
        for (String tag : t.getTags())
            if (!Iterables.contains(this.getTags(), tag))
                return false;
        for (String tag : this.getTags())
            if (!Iterables.contains(t.getTags(), tag))
                return false;
        return true;
    }
    return false;
}

From source file:org.sosy_lab.cpachecker.cpa.threading.ThreadingTransferRelation.java

/** Search for the thread, where the current edge is available.
 * The result should be exactly one thread, that is denoted as 'active',
 * or NULL, if no active thread is available.
 *
 * This method is needed, because we use the CompositeCPA to choose the edge,
 * and when we have several locations in the threadingState,
 * only one of them has an outgoing edge matching the current edge.
 *///w w  w. j  av a2s  .  c om
@Nullable
private String getActiveThread(final CFAEdge cfaEdge, final ThreadingState threadingState) {
    final Set<String> activeThreads = new HashSet<>();
    for (String id : threadingState.getThreadIds()) {
        if (Iterables.contains(threadingState.getThreadLocation(id).getOutgoingEdges(), cfaEdge)) {
            activeThreads.add(id);
        }
    }

    assert activeThreads.size() <= 1 : "multiple active threads are not allowed: " + activeThreads;
    // then either the same function is called in different threads -> not supported.
    // (or CompositeCPA and ThreadingCPA do not work together)

    return activeThreads.isEmpty() ? null : Iterables.getOnlyElement(activeThreads);
}

From source file:org.apache.jackrabbit.oak.util.TreeUtil.java

public static void addMixin(@Nonnull Tree tree, @Nonnull String mixinName, @Nonnull Tree typeRoot,
        @CheckForNull String userID) throws RepositoryException {
    Tree type = typeRoot.getChild(mixinName);
    if (!type.exists()) {
        throw new NoSuchNodeTypeException("Node type " + mixinName + " does not exist");
    } else if (getBoolean(type, JCR_IS_ABSTRACT)) {
        throw new ConstraintViolationException("Node type " + mixinName + " is abstract");
    } else if (!getBoolean(type, JCR_ISMIXIN)) {
        throw new ConstraintViolationException("Node type " + mixinName + " is a not a mixin type");
    }// www.  ja va 2 s . com

    List<String> mixins = Lists.newArrayList();
    String primary = getName(tree, JCR_PRIMARYTYPE);
    if (primary != null
            && Iterables.contains(getNames(type, NodeTypeConstants.REP_PRIMARY_SUBTYPES), primary)) {
        return;
    }

    Set<String> subMixins = Sets.newHashSet(getNames(type, NodeTypeConstants.REP_MIXIN_SUBTYPES));
    for (String mixin : getNames(tree, NodeTypeConstants.JCR_MIXINTYPES)) {
        if (mixinName.equals(mixin) || subMixins.contains(mixin)) {
            return;
        }
        mixins.add(mixin);
    }

    mixins.add(mixinName);
    tree.setProperty(JcrConstants.JCR_MIXINTYPES, mixins, NAMES);

    autoCreateItems(tree, type, typeRoot, userID);
}

From source file:edu.sabanciuniv.sentilab.sare.models.base.documentStore.PersistentDocumentStore.java

/**
 * Gets a boolean flag indicating whether the provided document is in this store or not.
 * @param document the {@code PersistentDocument} object to look for.
 * @return {@code true} if the document is contained in this store, {@code false} otherwise.
 *//*from  www  .  j a va 2  s  .c o  m*/
public boolean hasDocument(PersistentDocument document) {
    return this.getDocuments() != null ? Iterables.contains(this.getDocuments(), document) : false;
}

From source file:org.icgc.dcc.release.job.join.core.JoinJob.java

private static List<FileType> resolveExecuteFileTypes() {
    val tasksProperty = getProperty(EXECUTE_TASKS_PROPERTY, VALID_TASKS);
    log.info("Requested join tasks: {}", tasksProperty);
    val tasks = COMMA.split(tasksProperty);
    if (Iterables.size(tasks) == 1 && Iterables.contains(tasks, CLINICAL.getId())) {
        return emptyList();
    }/*from w  w w  .ja  v a  2 s.  c om*/

    val result = ImmutableList.<FileType>builder();
    for (val task : tasks) {
        val fileType = resolveTaskFileType(task);
        if (fileType.isPresent()) {
            result.add(fileType.get());
        }
    }

    return result.build();
}

From source file:com.zimbra.soap.util.JaxbInfo.java

public boolean hasAttribute(String name) {
    return Iterables.contains(this.getAttributeNames(), name);
}

From source file:gov.nih.nci.caarray.web.action.project.UploadProjectFilesAction.java

private List<FileWrapper> getFileWrappers() {
    List<FileWrapper> files = new ArrayList<FileWrapper>();
    for (int i = 0; i < getUpload().size(); i++) {
        File file = getUpload().get(i);
        FileWrapper wrapper = new FileWrapper();
        String fileName = getUploadFileName().get(i);
        wrapper.setFile(file);/*from  w ww. j  a va2 s. c  om*/
        wrapper.setFileName(fileName);
        wrapper.setCompressed((Iterables.contains(selectedFilesToUnpack, fileName)));
        if (getChunkedFileSize() != null) {
            wrapper.setTotalFileSize(getChunkedFileSize());
        } else {
            wrapper.setTotalFileSize(file.length());
        }
        files.add(wrapper);
    }
    return files;
}

From source file:org.eclipse.sirius.business.api.control.SiriusControlCommand.java

/**
 * The new analysis is added to the referencedAnalysis of the first parent
 * representations file and the children analysis of this first parent
 * representations file are analyzed to be eventually moved.<BR>
 * <UL>/*  w  ww .  java2  s  .co m*/
 * <LI>Take the root of the resource container the parent of the controlled
 * semantic element</LI>
 * <LI>For each analysis that have this root as first models:</LI>
 * <UL>
 * <LI>If the controlled semantic element contains the first models of a
 * referencedAnalysis of the current analysis, then move this one in the new
 * analysis (this corresponds to a fragmentation of intermediate level).
 * </LI>
 * <LI>Add the new analysis to the referencedAnalysis references</LI>
 * <UL>
 * </UL>
 * 
 * @param newDAnalysis
 *            The new analysis
 */
private void updateReferencedAnalysisReferences(final DAnalysis newDAnalysis) {
    EObject semanticParentRoot = getRootContainer(semanticObjectToControl.eContainer());
    Set<DAnalysis> referencers = Sets.newLinkedHashSet();

    for (Resource aird : session.getAllSessionResources()) {
        DAnalysis currentAnalysis = getDAnalysis(aird);
        Set<EObject> releventModels = new DAnalysisQuery(currentAnalysis).getMainModels();
        if (Iterables.contains(releventModels, semanticParentRoot)) {
            List<DAnalysis> referencedAnalysis = new ArrayList<DAnalysis>(
                    currentAnalysis.getReferencedAnalysis());
            for (DAnalysis childrenAnalysis : referencedAnalysis) {
                Option<EObject> optionalChildrenMainModel = new DAnalysisQuery(childrenAnalysis).getMainModel();
                if (optionalChildrenMainModel.some() && new EObjectQuery(optionalChildrenMainModel.get())
                        .isContainedIn(semanticObjectToControl)) {
                    currentAnalysis.getReferencedAnalysis().remove(childrenAnalysis);
                    newDAnalysis.getReferencedAnalysis().add(childrenAnalysis);
                }
            }
            referencers.add(currentAnalysis);
        }
    }

    if (!referencers.isEmpty() && session instanceof DAnalysisSession) {
        // Let the session set the reference and add adapters (visibility
        // propagator, semantic cross referencer, representation change
        // adapter, ...)
        ((DAnalysisSession) session).addReferencedAnalysis(newDAnalysis, referencers);
    }
}