package net.bytebuddy.utility;

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

/**
 * Creates a list representation of two lists as a single, compound list.
 */
public class CompoundList {

    /**
     * A compound list cannot be created.
     */
    private CompoundList() {
        throw new UnsupportedOperationException("Cannot create a compound list");
    }

    /**
     * Creates a list of a single element and another list.
     *
     * @param left  The left element.
     * @param right The right list.
     * @param <S>   The type of the list's elements.
     * @return A compound list representing the element and the list.
     */
    public static <S> List<S> of(S left, List<? extends S> right) {
        return of(Collections.singletonList(left), right);
    }

    /**
     * Creates a list of a list and an element.
     *
     * @param left  The left left.
     * @param right The right element.
     * @param <S>   The type of the list's elements.
     * @return A compound list representing the element and the list.
     */
    public static <S> List<S> of(List<? extends S> left, S right) {
        return of(left, Collections.singletonList(right));
    }

    /**
     * Creates a list of a left and right list.
     *
     * @param left  The left list.
     * @param right The right list.
     * @param <S>   The type of the list's elements.
     * @return A compound list representing the element and the list.
     */
    public static <S> List<S> of(List<? extends S> left, List<? extends S> right) {
        List<S> list = new ArrayList<S>(left.size() + right.size());
        list.addAll(left);
        list.addAll(right);
        return list;
    }
}

@@ -734,32 +734,67 @@
 nds S%3E right) %7B%0A
+        if (right.isEmpty()) %7B%0A    
         return o
@@ -792,19 +792,16 @@
  return 
-of(
 Collecti
@@ -827,17 +827,184 @@
 eft)
-, right);
+;%0A        %7D else %7B%0A            List%3CS%3E list = new ArrayList%3CS%3E(1 + right.size());%0A            list.add(left);%0A            list.addAll(right);%0A            return list;%0A        %7D
 %0A   
@@ -1355,58 +1355,256 @@
     
-return of(left, Collections.singletonList(right));
+if (left.isEmpty()) %7B%0A            return Collections.singletonList(right);%0A        %7D else %7B%0A            List%3CS%3E list = new ArrayList%3CS%3E(left.size() + 1);%0A            list.addAll(left);%0A            list.add(right);%0A            return list;%0A        %7D
 %0A   

Improve footprint of compound lists.