package com.benbarron.react;

import java.util.Iterator;

public class ImmutableList<T> implements Iterable<T> {

    private final T[] items;

    private ImmutableList(T[] items) {
        this.items = items;
    }

    public ImmutableList<T> add(T item) {
        return null;
    }

    @Override
    public Iterator<T> iterator() {
        return new Iterator<T>() {

            private int position = 0;

            @Override
            public boolean hasNext() {
                return position < items.length;
            }

            @Override
            public T next() {
                return items[position++];
            }
        };
    }

    public ImmutableList<T> remove(T item) {
        return null;
    }

    public int size() {
        return items.length;
    }


    public static <T> ImmutableList<T> from(T[] items) {
        return new ImmutableList<>(items);
    }
}

@@ -23,16 +23,41 @@
 react;%0A%0A
+import java.util.Arrays;%0A
 import j
@@ -75,16 +75,16 @@
 erator;%0A
-
 %0Apublic 
@@ -282,35 +282,163 @@
 ) %7B%0A        
-return null
+T%5B%5D newItems = Arrays.copyOf(items, items.length + 1);%0A        newItems%5Bitems.length%5D = item;%0A%0A        return new ImmutableList%3C%3E(newItems)
 ;%0A    %7D%0A%0A   
@@ -866,19 +866,362 @@
     
-return null
+T%5B%5D newItems = items;%0A%0A        for (int i = 0; i %3C items.length; i++) %7B%0A            if (items%5Bi%5D.equals(item)) %7B%0A                newItems = Arrays.copyOf(items, items.length - 1);%0A                System.arraycopy(items, i + 1, newItems, i, newItems.length - i);%0A                break;%0A            %7D%0A        %7D%0A%0A        return new ImmutableList%3C%3E(newItems)
 ;%0A  

Implement remaining ImmutableList methods.