Java Collection Contain containsOne(final Collection sup, final Collection parts)

Here you can find the source of containsOne(final Collection sup, final Collection parts)

Description

Return true , if sup contains at least one item from parts .

License

Artistic License

Parameter

Parameter Description
E a parameter
sup a parameter
parts <p/>

Return

true if at least one item of parts was found in sup .

Declaration

public static <E> boolean containsOne(final Collection<E> sup, final Collection<? extends E> parts) 

Method Source Code

//package com.java2s;
/**//  w  ww .  ja va2s.c om
 * (c) 2009-2014 Peter Wullinger
 *
 * $Id$
 *
 * Use, modification and restribution of this file are covered by the
 * terms of the Artistic License 2.0.
 *
 * You should have received a copy of the license terms in a file named
 * "LICENSE" together with this software package.
 *
 * Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT
 * HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
 * A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE
 * EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO
 * COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT
 * OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 **/

import java.util.Collection;

public class Main {
    /**
     * Return {@literal true}, if {@literal sup} contains at least one item from {@literal parts}.
     *
     * @param <E>
     * @param sup
     * @param parts
     * <p/>
     * @return {@literal true} if at least one item of {@literal parts} was found in {@literal sup}.
     */
    public static <E> boolean containsOne(final Collection<E> sup, final Collection<? extends E> parts) {
        for (E part : parts) {
            if (sup.contains(part))
                return true;
        }

        return false;
    }
}

Related

  1. containsNull(final Collection c)
  2. containsNullsOrEmptyStrings(Collection c)
  3. containsNumber(Collection collection, Number number)
  4. containsObject(Collection c, T o)
  5. containsObjectIdentity(Collection collection, Object object)
  6. containsPrefix(final Collection words, final String prefix)
  7. containsPrefix(String str, Collection prefixes)
  8. containsSafe(Collection collection, V value)
  9. containsSame(Collection first, Collection second)