Example usage for java.util Collection contains

List of usage examples for java.util Collection contains

Introduction

In this page you can find the example usage for java.util Collection contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this collection contains the specified element.

Usage

From source file:fr.certu.chouette.manager.AbstractNeptuneManager.java

/**
 * add source in target collection if not null, not already in database and
 * not already in target//  w  w w . j  ava2  s.  c o  m
 * 
 * @param <U>
 *           type of source and collection entries
 * @param target
 *           collection
 * @param source
 *           object to add
 */
protected static <U extends NeptuneIdentifiedObject> void addIfMissingInCollection(Collection<U> target,
        U source) {
    if (source == null)
        return;
    if (source.getId() != null) {
        localLogger.debug(source.getObjectId() + " not added , already saved as " + source.getId());
        return;
    }
    if (!target.contains(source))
        target.add(source);

}

From source file:elaborate.editor.solr.ElaborateSolrIndexer.java

public static SolrInputDocument getSolrInputDocument(ProjectEntry projectEntry, boolean forPublication,
        Collection<String> facetsToSplit) {
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField(ID, projectEntry.getId());
    doc.addField(NAME, projectEntry.getName());
    Project project = projectEntry.getProject();
    for (String field : project.getProjectEntryMetadataFieldnames()) {
        String facetName = SolrUtils.facetName(field);
        String value = projectEntry.getMetadataValue(field);
        doc.addField(facetName,/*ww  w . ja v  a2 s.  c  o  m*/
                StringUtils.defaultIfBlank(value, EMPTYVALUE_SYMBOL).replaceAll("\\r?\\n|\\r", "/"), 1.0f);
        if (forPublication) {
            // TODO: This is CNW/BoschDoc specific, refactoring needed
            handleCNWFacets(facetName, value, doc);
            if (facetsToSplit.contains(facetName)) {
                handleMultiValuedFields(facetName, value, doc);
            }
        }
    }
    Set<String> textLayersProcessed = Sets.newHashSet();
    for (Transcription transcription : projectEntry.getTranscriptions()) {
        String tBody = convert(transcription.getBody());
        String textLayer = SolrUtils.normalize(transcription.getTextLayer());
        if (textLayersProcessed.contains(textLayer)) {
            Log.error("duplicate textlayer {} for entry {}", textLayer, projectEntry.getId());
        } else {
            doc.addField(TEXTLAYER_PREFIX + textLayer, tBody);
            doc.addField(TEXTLAYERCS_PREFIX + textLayer, tBody);
            for (Annotation annotation : transcription.getAnnotations()) {
                String body = annotation.getBody();
                if (body != null) {
                    String aBody = convert(body);
                    doc.addField(ANNOTATION_PREFIX + textLayer, aBody);
                    doc.addField(ANNOTATIONCS_PREFIX + textLayer, aBody);
                }
            }
            textLayersProcessed.add(textLayer);
        }
    }
    if (!forPublication) {
        doc.addField(PUBLISHABLE, projectEntry.isPublishable(), 1.0f);
        doc.addField(PROJECT_ID, projectEntry.getProject().getId());
    }
    Log.info("doc={}", doc);
    return doc;
}

From source file:com.sworddance.util.CUtilities.java

public static <T> void removeIfNotPresent(Collection<T> collection, Collection<T> permitted) {
    for (Iterator<T> iter = collection.iterator(); iter.hasNext();) {
        T element = iter.next();//  w ww. j a v a 2 s . c  o  m
        if (!permitted.contains(element)) {
            iter.remove();
        }
    }
}

From source file:com.framework.infrastructure.utils.HibernateUtils.java

/**
 * ID,./*from w  w w. j  ava 2s  .c  o  m*/
 * 
 * id,id.
 * id,id. ID,
 * cascade-save-or-update.
 * 
 * @param srcObjects
 *            ,.
 * @param checkedIds
 *            ,ID.
 * @param clazz
 *            
 * @param idName
 *            
 */
public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds,
        final Class<T> clazz, final String idName) {

    // 
    Assert.notNull(srcObjects, "scrObjects");
    Assert.hasText(idName, "idName");
    Assert.notNull(clazz, "clazz");

    // , .
    if (checkedIds == null) {
        srcObjects.clear();
        return;
    }

    // ,idID,.
    // ,id,idid.
    Iterator<T> srcIterator = srcObjects.iterator();
    try {

        while (srcIterator.hasNext()) {
            T element = srcIterator.next();
            Object id;
            id = PropertyUtils.getProperty(element, idName);

            if (!checkedIds.contains(id)) {
                srcIterator.remove();
            } else {
                checkedIds.remove(id);
            }
        }

        // IDid,,id.
        for (ID id : checkedIds) {
            T obj = clazz.newInstance();
            PropertyUtils.setProperty(obj, idName, id);
            srcObjects.add(obj);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
}

From source file:jef.tools.collection.CollectionUtil.java

/**
 * Return the first element in '<code>candidates</code>' that is contained
 * in '<code>source</code>'. If no element in '<code>candidates</code>' is
 * present in '<code>source</code>' returns <code>null</code>. Iteration
 * order is {@link Collection} implementation specific.
 * //w  ww  .  j a  v a 2s .co  m
 * @param source
 *            the source Collection
 * @param candidates
 *            the candidates to search for
 * @return the first present object, or <code>null</code> if not found
 */
public static Object findFirstMatch(Collection<?> source, Collection<?> candidates) {
    if (isEmpty(source) || isEmpty(candidates)) {
        return null;
    }
    for (Object candidate : candidates) {
        if (source.contains(candidate)) {
            return candidate;
        }
    }
    return null;
}

From source file:modmanager.backend.Modification.java

/**
 * Returns all options, which conflicts with current selection of
 * to-be-installed options.//from   www  . j a v  a  2 s  .  c  om
 *
 * @param modifications
 * @param to_be_added
 * @return
 */
public static LinkedList<ModificationOption> findConflicts(Collection<Modification> modifications,
        Collection<ModificationOption> to_be_added) {
    LinkedList<ModificationOption> conflicts = new LinkedList<>();

    for (Modification mod : modifications) {
        for (ModificationOption opt : mod.getOptions()) {
            /**
             * option should be installed OR in the list of to-be-added
             */
            if (mod.getStatus().isInstalled(opt) || to_be_added.contains(opt)) {
                /**
                 * Check all mods in collection
                 */
                for (ModificationOption wannabe : to_be_added) {
                    /**
                     * Prevent self-checking
                     */
                    if (wannabe == opt) {
                        continue;
                    }

                    /**
                     * Only care about uninstalled selected packages
                     */
                    if (!wannabe.getParent().getStatus().isInstalled(wannabe)) {
                        if (opt.conflicts(wannabe)) {
                            conflicts.add(opt);
                        }
                    }
                }
            }
        }
    }

    return conflicts;
}

From source file:org.openinfinity.domain.service.ProductSpecification.java

public boolean isNotEligibleForCreation(Product product, Collection<Product> products) {
    return products.contains(product);
}

From source file:com.evolveum.midpoint.test.ldap.OpenDJController.java

public static void assertNoObjectClass(Entry response, String unexpected) throws DirectoryException {
    Collection<String> objectClassValues = getAttributeValues(response, "objectClass");
    AssertJUnit.assertFalse("Unexpected objectclass for entry " + getDn(response) + ": " + unexpected + ", got "
            + objectClassValues, objectClassValues.contains(unexpected));
}

From source file:com.evolveum.midpoint.test.ldap.OpenDJController.java

public static void assertObjectClass(Entry response, String expected) throws DirectoryException {
    Collection<String> objectClassValues = getAttributeValues(response, "objectClass");
    AssertJUnit.assertTrue("Wrong objectclass for entry " + getDn(response) + ", expected " + expected
            + " but got " + objectClassValues, objectClassValues.contains(expected));
}

From source file:info.servertools.core.util.FileUtils.java

public static void zipDirectory(File directory, File zipfile, @Nullable Collection<String> fileBlacklist,
        @Nullable Collection<String> folderBlacklist) throws IOException {
    URI baseDir = directory.toURI();
    Deque<File> queue = new LinkedList<>();
    queue.push(directory);//from www.  java  2  s.  c o m
    OutputStream out = new FileOutputStream(zipfile);
    Closeable res = out;
    try {
        ZipOutputStream zout = new ZipOutputStream(out);
        res = zout;
        while (!queue.isEmpty()) {
            directory = queue.removeFirst();
            File[] dirFiles = directory.listFiles();
            if (dirFiles != null && dirFiles.length != 0) {
                for (File child : dirFiles) {
                    if (child != null) {
                        String name = baseDir.relativize(child.toURI()).getPath();
                        if (child.isDirectory()
                                && (folderBlacklist == null || !folderBlacklist.contains(child.getName()))) {
                            queue.push(child);
                            name = name.endsWith("/") ? name : name + "/";
                            zout.putNextEntry(new ZipEntry(name));
                        } else {
                            if (fileBlacklist != null && !fileBlacklist.contains(child.getName())) {
                                zout.putNextEntry(new ZipEntry(name));
                                copy(child, zout);
                                zout.closeEntry();
                            }
                        }
                    }
                }
            }
        }
    } finally {
        res.close();
    }
}