com.exasol.adapter.document.ListUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtual-schema-common-document Show documentation
Show all versions of virtual-schema-common-document Show documentation
Common module of Exasol Virtual Schema Adapters for Document Data Sources.
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;
}
}