Java List Sub List subArray(List listA, List listB)

Here you can find the source of subArray(List listA, List listB)

Description

Sub array.

License

Apache License

Parameter

Parameter Description
T the generic type
listA the list a
listB the list b

Return

true, if successful Case Insensitive

Declaration

public static <T> boolean subArray(List<T> listA, List<T> listB) 

Method Source Code

//package com.java2s;
/*/*w ww.ja  v a 2 s. c  om*/
Copyright 2014 Array-Utilities
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    
 * */

import java.util.Collection;

import java.util.List;

public class Main {
    /**
     * Sub array.
     *
     * @param <T>
     *            the generic type
     * @param listA
     *            the list a
     * @param listB
     *            the list b
     * @return true, if successful
     * 
     *         Case Insensitive
     */
    public static <T> boolean subArray(List<T> listA, List<T> listB) {

        // ListA empty & ListB has values
        if (isEmpty(listA) && !isEmpty(listB)) {
            return false;
        }

        // ListA has values & ListB is empty
        if (!isEmpty(listA) && isEmpty(listB)) {
            return false;
        }

        if (isSizeZero(listA) && isSizeZero(listB)) {
            return true;
        }

        if (isListNull(listA) && isListNull(listB)) {
            return true;
        }
        return listA.containsAll(listB);
    }

    /**
     * Checks if is empty.
     *
     * @param <E>
     *            the element type
     * @param collection
     *            the collection
     * @return true, if is empty
     */
    public static <E> boolean isEmpty(Collection<? super E> collection) {

        if ((collection.size() == 0) || (collection == null))
            return true;
        return false;
    }

    /**
     * Checks if is size zero.
     *
     * @param <T>
     *            the generic type
     * @param list
     *            the list
     * @return true, if is size zero
     */
    public static <T> boolean isSizeZero(List<T> list) {
        return list.size() == 0;
    }

    /**
     * Checks if is list null.
     *
     * @param <T>
     *            the generic type
     * @param list
     *            the list
     * @return true, if is list null
     */
    public static <T> boolean isListNull(List<T> list) {
        return list == null;
    }
}

Related

  1. splitIntoSubListsByNumber(final List list, final int numberOfSublists)
  2. splitList(List list, int subListNumber)
  3. splitListToSubLists(List parentList, int subListSize)
  4. startsWith(final List list, final List subList)
  5. sub(List l, int index)
  6. subList(final Iterable

    parent, final Iterable child)

  7. subList(final List oriList, int[] indexes)
  8. subList(final List list, final int first, final int count)
  9. subList(final List list, final int offset, final int amount)