package io.github.gimmi;

import java.util.ArrayList;

public class AnyListBuilder {
	private final ArrayList<Any> list = new ArrayList<>();
	private int lastNonNullIndex = 0;
	
	public AnyListBuilder put(Any value) {
		if (value == null) {
			value = Any.NULL;
		}
		list.add(value);
		if (value.size() > 0) {
			lastNonNullIndex = list.size();
		}
		return this;
	}
	
	public Any build() {
		if (list.isEmpty()) {
			return Any.NULL;
		}
		return new Any(null, null, new ArrayList<>(list.subList(0, lastNonNullIndex)));
	}
}

@@ -172,17 +172,18 @@
 Index = 
-0
+-1
 ;%0D%0A%09%0D%0A%09p
@@ -276,28 +276,8 @@
 %09%7D%0D%0A
-%09%09list.add(value);%0D%0A
 %09%09if
@@ -332,32 +332,52 @@
 t.size();%0D%0A%09%09%7D%0D%0A
+%09%09list.add(value);%0D%0A
 %09%09return this;%0D%0A
@@ -417,21 +417,27 @@
 f (l
-ist.isEmpty()
+astNonNullIndex %3C 0
 ) %7B%0D
@@ -454,24 +454,87 @@
  Any.NULL;%0D%0A
+%09%09%7D else if (lastNonNullIndex == 0) %7B%0D%0A%09%09%09return list.get(0);%0D%0A
 %09%09%7D%0D%0A%09%09retur
@@ -603,16 +603,20 @@
 ullIndex
+ + 1
 )));%0D%0A%09%7D

Single valued list are not list