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:com.evolveum.midpoint.model.impl.util.Utils.java

private static void applyVisitorToValues(Collection<? extends PrismValue> values, ItemDelta<?, ?> delta,
        Visitor visitor) {/*ww w .  j  av a2s  . com*/
    Collection<? extends PrismValue> valuesToDelete = delta.getValuesToDelete();
    if (valuesToDelete == null) {
        valuesToDelete = new ArrayList<>(0); // just to simplify the code below
    }
    if (values != null) {
        for (PrismValue pval : values) {
            boolean isToBeDeleted = valuesToDelete.contains(pval);
            pval.accept(visitor);
            if (!isToBeDeleted && valuesToDelete.contains(pval)) {
                // value becomes 'to be deleted' -> we remove it from toBeDeleted list
                ((ItemDelta<PrismValue, ?>) delta).removeValueToDelete(pval);
            }
        }
    }
}

From source file:com.gm.bamboo.util.HibernateUtils.java

/**
 * ?ID?, ???./*from  ww w. ja  v  a  2 s . c  o  m*/
 * 
 * ??????id,Hibernate??????id?????.
 * ???id??,??id??.
 * ?ID, ??cascade-save-or-update??.
 * 
 * @param srcObjects ??,.
 * @param checkedIds  ?,ID.
 * @param clazz  ?,IdEntity?
 */
public static <T extends BaseEntity> void mergeByCheckedIds(final Collection<T> srcObjects,
        final Collection<Long> checkedIds, final Class<T> clazz) {

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

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

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

        while (srcIterator.hasNext()) {
            T element = srcIterator.next();
            Long id = element.getId();

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

        //ID??id????,,id??.
        for (Long id : checkedIds) {
            T element = clazz.newInstance();
            element.setId(id);
            srcObjects.add(element);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
}

From source file:com.gm.wine.util.HibernateUtils.java

/**
 * ?ID?, ???./*from  w  ww. ja va 2 s .  c o m*/
 * 
 * ??????id,Hibernate??????id?????.
 * ???id??,??id??. ?ID,
 * ??cascade-save-or-update??.
 * 
 * @param srcObjects
 *            ??,.
 * @param checkedIds
 *            ?,ID.
 * @param clazz
 *            ?,IdEntity?
 */
public static <T extends BaseEntity> void mergeByCheckedIds(final Collection<T> srcObjects,
        final Collection<Long> checkedIds, final Class<T> clazz) {

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

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

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

        while (srcIterator.hasNext()) {
            T element = srcIterator.next();
            Long id = element.getId();

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

        // ID??id????,,id??.
        for (Long id : checkedIds) {
            T element = clazz.newInstance();
            element.setId(id);
            srcObjects.add(element);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
}

From source file:com.thebuzzmedia.exiftool.ExifToolNew3.java

public static Charset computeDefaultCharset(Collection<Feature> features) {
    if (features.contains(Feature.WINDOWS))
        return Charset.forName("windows-1252");
    return Charset.defaultCharset();
}

From source file:delfos.dataset.util.DatasetPrinter.java

public static String printCompactRatingTableSortedByNumRatings(DatasetLoader<? extends Rating> datasetLoader,
        Collection<User> _users) {

    final List<User> users = _users.stream().sorted(User.BY_ID).collect(Collectors.toList());
    final List<Item> itemsAllUsersRated = datasetLoader.getContentDataset().stream().sorted(Item.BY_ID)
            .map(item -> {/* w ww  . j  a v a  2  s  . c  om*/
                List<User> listOfUsersThatRated = datasetLoader.getRatingsDataset()
                        .getItemRatingsRated(item.getId()).values().stream().filter(rating -> {
                            return _users.contains(rating.getUser());
                        }).map(rating -> rating.getUser()).collect(Collectors.toList());
                GroupOfUsers groupOfUsersThatRated = new GroupOfUsers(listOfUsersThatRated);
                return new Pair<GroupOfUsers, Item>(groupOfUsersThatRated, item);
            }).filter(pair -> !pair.getKey().isEmpty())
            .sorted((pair1, pair2) -> -pair1.getKey().compareTo(pair2.getKey())).map(pair -> pair.getValue())
            .collect(Collectors.toList());

    return actuallyDoTheTable(itemsAllUsersRated, users, datasetLoader);
}

From source file:com.reachlocal.grails.plugins.cassandra.utils.DataMapper.java

public static Map<String, Object> dataProperties(GroovyObject data, List<String> transients,
        Map<String, Class> hasMany, String expandoMapName, Collection mappedProperties) throws IOException {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    Class clazz = data.getClass();
    if (expandoMapName != null) {
        transients.add(expandoMapName);//from w ww.  ja v  a 2  s  .c om
    }

    // Unneeded since we now get the class from the method signatures
    // Might be needed again if we ever support subclasses
    //map.put(CLASS_NAME_KEY, clazz.getName());

    for (PropertyDescriptor pd : PropertyUtils.getPropertyDescriptors(data)) {
        String name = pd.getName();
        if (!transients.contains(name) && !GLOBAL_TRANSIENTS.contains(name) && hasMany.get(name) == null) {
            Object prop = data.getProperty(name);
            if (prop == null) {
                if (mappedProperties.contains(name)) {
                    map.put(name + "Id", null);
                } else {
                    map.put(name, null);
                }
            } else {
                //if (OrmHelper.isMappedObject(prop)) {   // TODO new is mapped
                if (mappedProperties.contains(name)) {
                    GroovyObject g = (GroovyObject) prop;
                    String idName = name + "Id";
                    map.put(idName, g.getProperty("id"));
                } else {
                    Object value = dataProperty(prop);
                    map.put(name, value);
                }
            }
        }
    }

    if (expandoMapName != null) {
        Map<String, Object> expandoMap = (Map<String, Object>) data.getProperty(expandoMapName);
        if (expandoMap != null) {
            for (Map.Entry<String, Object> entry : expandoMap.entrySet()) {
                map.put(entry.getKey(), entry.getValue());
            }
        }
    }

    return map;
}

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

public static <T> boolean addIfNotContains(Collection<T> collection, T value) {
    if (collection != null && value != null && !collection.contains(value)) {
        return collection.add(value);
    } else {/* www .  j a  va2  s  .c o m*/
        return false;
    }
}

From source file:com.perl5.lang.perl.util.PerlPackageUtil.java

private static <E> void addIfMissing(Collection<E> result, Iterable<E> addition) {
    if (addition == null) {
        return;/* www  .  ja  v a2 s .c o  m*/
    }

    for (E e : addition) {
        if (!result.contains(e)) {
            result.add(e);
        }
    }
}

From source file:com.nextep.datadesigner.sqlgen.impl.SQLGenerator.java

public static void processPreconditions(IGenerationResult result, List<IGenerationResult> resolvedResults,
        Map<DatabaseReference, IGenerationResult> refMap, Collection<IGenerationResult> stack) {
    if (result.getPreconditions().isEmpty()) {
        resolvedResults.add(result);//  ww  w .  j  a v a 2s.c  om
    } else {
        // We have a deadloop here, so we return
        if (stack.contains(result)) {
            LOGGER.warn("Circular dependencies found, generation order may not be accurate.");
            return;
        }
        stack.add(result);
        for (DatabaseReference ref : result.getPreconditions()) {
            IGenerationResult precondResult = refMap.get(ref);
            if (!resolvedResults.contains(precondResult) && precondResult != null && precondResult != result) {
                try {
                    processPreconditions(precondResult, resolvedResults, refMap, stack);
                } catch (StackOverflowError e) {
                    LOGGER.info(result.getName());
                    throw e;
                }
            }
        }
        stack.remove(result);
        resolvedResults.add(result);
    }
}

From source file:com.fengduo.bee.commons.core.lang.CollectionUtils.java

public static <T extends Object> List<T> removeAll(Collection<T> collection, Collection<T> remove) {
    List<T> list = new ArrayList<T>();
    for (Iterator<T> iter = collection.iterator(); iter.hasNext();) {
        T obj = iter.next();//from w  w w  .j  av a 2s .  com
        if (remove.contains(obj) == false) {
            list.add(obj);
        }
    }
    return list;
}