Java List Contain containsExactly(Collection list, T... mustHaveItems)

Here you can find the source of containsExactly(Collection list, T... mustHaveItems)

Description

Checks if the collection contains exactly the given mustHaveItems.

License

Open Source License

Declaration

@SafeVarargs
public static <T> boolean containsExactly(Collection<T> list, T... mustHaveItems) 

Method Source Code


//package com.java2s;
/*/*  ww w .  j  av  a 2  s  .co  m*/
 * Syncany, www.syncany.org
 * Copyright (C) 2011-2015 Philipp C. Heckel <philipp.heckel@gmail.com> 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Arrays;
import java.util.Collection;

public class Main {
    /**
     * Checks if the collection contains exactly the given <tt>mustHaveItems</tt>. 
     * 
     * <p><b>Examples:</b><br>
     * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }))          --> false</tt><br>
     * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), 1, 99)   --> false</tt><br>
     * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), 1, 2, 3) --> true</tt>
     */
    @SafeVarargs
    public static <T> boolean containsExactly(Collection<T> list, T... mustHaveItems) {
        return containsExactly(list, Arrays.asList(mustHaveItems));
    }

    /**
     * Checks if the collection contains exactly the given <tt>mustHaveItems</tt>.
     * 
     * <p><b>Examples:</b><br>
     * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), Arrays.asList(new Integer[] { }))         --> false</tt><br>
     * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), Arrays.asList(new Integer[] { 1, 99 }))   --> false</tt><br>
     * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), Arrays.asList(new Integer[] { 1, 2, 3 })) --> true</tt>
     */
    public static <T> boolean containsExactly(Collection<T> list, Collection<T> mustHaveItems) {
        return list.containsAll(mustHaveItems) && mustHaveItems.containsAll(list);
    }
}

Related

  1. containsCaseInsensitive(String s, List l)
  2. containsColumnByAlias(List columns, String alias)
  3. containsDuplicates(List list, Comparator comparator)
  4. containsElement( List> list, List element)
  5. containsEnchantment(String enchantments, List enchList)
  6. containsExactly(List items, T... itemsToMatch)
  7. containsExternalFilter(List filterList, String dataSetExtId, String dataSourceExtId)
  8. containsFileName(String fileName, List filterList)
  9. containsHelpRequest(List args)