package com.speedment.runtime.field.internal.util;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;

/**
 * Utility class for constructing temporary collections.
 *
 * @author Emil Forslund
 * @since  3.0.11
 */
public final class CollectionUtil {

    /**
     * Returns a {@link Set} with the values in the specified collection. If the
     * specified collection is already a {@link Set}, it might be returned. This
     * method makes no guarantees regarding mutability or iteration order of the
     * returned set.
     *
     * @param <T>         the element type
     * @param collection  the collection
     * @return            a set with the same elements as the collection
     */
    public static <T> Set<T> collectionToSet(Collection<T> collection) {
        if (collection instanceof Set) {
            return (Set<T>) collection;
        } else {
            switch (collection.size()) {
                case 0  : return emptySet();
                case 1  : return singleton(collection.iterator().next());
                default : return new HashSet<>(collection);
            }
        }
    }

    /**
     * Should not be instantiated.
     */
    private CollectionUtil() {}
}

@@ -66,160 +66,49 @@
 til.
-Collection;%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A%0Aimport static java.util.Collections.emptySet;%0Aimport static java.util.Collections.singleton
+*;%0A%0Aimport static java.util.Collections.*
 ;%0A%0A/
@@ -1120,16 +1120,854 @@
 %0A    %7D%0A%0A
+    /**%0A     * Creates a copy of the specified list and adds the specified elements to%0A     * it before returning it as an immutable list.%0A     *%0A     * @param %3CT%3E       the element type%0A     * @param original  the original list%0A     * @param element   elements to add%0A     * @return          the new immutable list%0A     */%0A    @SafeVarargs%0A    public static %3CT%3E List%3CT%3E copyAndAdd(List%3CT%3E original, T... element) %7B%0A        switch (original.size() + element.length) %7B%0A            case 0 : return emptyList();%0A            case 1 : return singletonList(%0A                original.isEmpty() ? element%5B0%5D : original.get(0)%0A            );%0A            default : %7B%0A                final List%3CT%3E copy = new ArrayList%3C%3E(original);%0A                addAll(copy, element);%0A                return unmodifiableList(copy);%0A            %7D%0A        %7D%0A    %7D%0A%0A
     /**%0A

Add util method copyAndAdd to CollectionUtil