Java Collection Contain containSameElements(Collection> sets)

Here you can find the source of containSameElements(Collection> sets)

Description

contain Same Elements

License

Open Source License

Declaration

public static <T> boolean containSameElements(Collection<Set<T>> sets) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

import java.util.Iterator;

import java.util.Set;

public class Main {
    public static <T> boolean containSameElements(Collection<Set<T>> sets) {
        if (sets.isEmpty() || sets.size() < 2)
            return false;
        Iterator<Set<T>> iterator = sets.iterator();
        Set<T> basicSet = iterator.next();
        Set<T> actualSet;//from   w  w w .  j a v a 2 s.c om
        while (iterator.hasNext()) {
            actualSet = iterator.next();
            if (actualSet.size() != basicSet.size())
                return false;
            if (!actualSet.containsAll(basicSet))
                return false;
        }
        return true;
    }

    public static <T> boolean containSameElements(Set<T>... sets) {
        if (sets.length == 0 || sets.length < 2)
            return false;
        Set<T> basicSet = sets[0];
        for (int i = 1; i < sets.length; i++) {
            if (sets[i].size() != basicSet.size())
                return false;
            if (!sets[i].containsAll(basicSet))
                return false;
        }
        return true;
    }
}

Related

  1. containsAll(Collection c, Iterable subset)
  2. containsAll(Collection coll, Collection other)
  3. containsAll(Collection collectionToCheck, Collection items)
  4. containsAll(final Collection c, final Object... array)
  5. containsAll(final Collection coll1, final Collection coll2)
  6. containSameItems(Collection c1, Collection c2)
  7. containsAny(Collection c1, Collection c2)
  8. containsAny(Collection collection1, Collection collection2)
  9. containsAny(Collection container, Collection contained)