All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.exasol.adapter.document.ListUtils Maven / Gradle / Ivy

The newest version!
package com.exasol.adapter.document;

import java.util.ArrayList;
import java.util.List;

/**
 * This class contains static functions for concatenating lists.
 */
public class ListUtils {

    private ListUtils() {
        // empty on purpose
    }

    /**
     * Add an element to an unmodifiable list.
     * 
     * @param list              list to add element to
     * @param additionalElement element to add
     * @param                type of the list elements
     * @return copy of the list with added element
     */
    public static  List listWith(final List list, final T additionalElement) {
        final ArrayList result = new ArrayList<>(list);
        result.add(additionalElement);
        return result;
    }

    /**
     * Concatenate two lists with removing duplicates.
     * 
     * @param list      first list
     * @param otherList second list
     * @param        type of the list elements
     * @return new list
     */
    public static  List union(final List list, final List otherList) {
        final ArrayList result = new ArrayList<>(list);
        for (final T item : otherList) {
            if (!result.contains(item)) {
                result.add(item);
            }
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy