Java List Contain containsElement( List> list, List element)

Here you can find the source of containsElement( List> list, List element)

Description

contains Element

License

LGPL

Declaration

public static <E extends Object> boolean containsElement(
            List<List<E>> list, List<E> element) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    public static <E extends Object> boolean containsElement(
            List<List<E>> list, List<E> element) {
        boolean found = false;
        for (List<E> e : list) {
            if (isEqual(element, e)) {
                found = true;//from  w w w  .  j  a v a  2  s. c  om
                break;
            }
        }
        return found;
    }

    public static <E extends Object> boolean isEqual(List<E> from,
            List<E> to) {
        return (getCommonElements(from, to).size() == from.size())
                && (from.size() == to.size());
    }

    public static <E extends Object> List<E> getCommonElements(
            List<E> from, List<E> to) {
        List<E> res = new ArrayList<E>();
        for (int i = 0; i < from.size(); i++) {
            if (hasElement(to, from.get(i))) {
                res.add(from.get(i));
            }
        }
        return res;
    }

    public static <E extends Object> List<E> getCommonElements(
            List<List<E>> sets) {
        List<E> set = getCommonElements(sets.get(0), sets.get(1));
        for (int i = 2; i < sets.size(); i++) {
            set = getCommonElements(set, sets.get(i));
        }
        return set;
    }

    public static <E extends Object> List<E> getCommonElements(
            Collection<E> from, Collection<E> to) {
        List<E> res = new ArrayList<E>();
        for (E f : from) {
            for (E t : to) {
                if (f.equals(t)) {
                    res.add(f);
                }
            }
        }
        return res;
    }

    public static <E extends Object> boolean hasElement(List<E> array,
            E element) {
        boolean res = false;
        for (int i = 0; i < array.size(); i++) {
            if (array.get(i).equals(element)) {
                res = true;
                break;
            }
        }
        return res;
    }
}

Related

  1. containsAtLeastOneElement(List l1, List l2)
  2. containsBasedOnEntryIdentity(final List list, final Object object)
  3. containsCaseInsensitive(String s, List l)
  4. containsColumnByAlias(List columns, String alias)
  5. containsDuplicates(List list, Comparator comparator)
  6. containsEnchantment(String enchantments, List enchList)
  7. containsExactly(Collection list, T... mustHaveItems)
  8. containsExactly(List items, T... itemsToMatch)
  9. containsExternalFilter(List filterList, String dataSetExtId, String dataSourceExtId)