Android List Minus removeRepeatElements(List origin, List target)

Here you can find the source of removeRepeatElements(List origin, List target)

Description

Remove repeat elements in origin List by target List.

Declaration

public static <T> List<T> removeRepeatElements(List<T> origin,
        List<T> target) 

Method Source Code

//package com.java2s;
import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    /**/*w  w  w.  j  a  va 2  s .  c om*/
     * Remove repeat elements in origin List by target List.
     */
    public static <T> List<T> removeRepeatElements(List<T> origin,
            List<T> target) {
        if (origin == null || target == null) {
            return target;
        }

        List<T> temp = new ArrayList<T>();
        if (!isEmpty(origin)) {
            for (T object : target) {
                if (!origin.contains(object)) {
                    temp.add(object);
                }
            }
            return temp;
        }
        return target;
    }

    public static boolean isEmpty(Collection<?> collection) {
        if (size(collection) == 0) {
            return true;
        }
        return false;
    }

    /**
     * Get the size of specified collection.
     */
    public static int size(Collection<?> collection) {
        if (collection == null) {
            return 0;
        }
        return collection.size();
    }
}