package com.seadowg.loafers.collection;

import java.util.Arrays;
import java.util.Random;

public class List<T> {

  private final java.util.List<T> values;

  public List(T ... values) {
    this.values = Arrays.asList(values);
  }

  public T chooseOne() {
    int index = new Random().nextInt(values.size());
    return values.get(index);
  }

  public T first() {
    return values.get(0);
  }

  public T last() {
    return values.get(values.size() - 1);
  }

  public T get(int index) {
    return values.get(index);
  }

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

  public List<T> add(List<T> appendList) {
    int newLength = length() + appendList.length();
    Object[] buffer = new Object[newLength];

    for (int i = 0; i < newLength; i++) {
      if (i < length()) {
        buffer[i]= get(i);
      } else {
        buffer[i] = appendList.get(i - length());
      }
    }

    return new List<T>((T[]) buffer);
  }

  public boolean equals(Object object) {
    if (object.getClass().isAssignableFrom(this.getClass())) {
      return equalsList((List<T>) object);
    } else {
      return false;
    }
  }

  private boolean equalsList(List<T> otherList) {
    if (length() == otherList.length()) {
      boolean isEqual = true;

      for (int i = 0; i < length(); i++) {
        if (!get(i).equals(otherList.get(i))) {
          isEqual = false;
        }
      }

      return isEqual;
    } else {
      return false;
    }
  }
}

@@ -34,16 +34,44 @@
 ction;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -619,46 +619,45 @@
 lic 
-List%3CT%3E add(List%3CT%3E append
+java.util.List%3CT%3E toJava
 List
+(
 ) %7B%0A    
 int 
@@ -656,275 +656,181 @@
     
-int newLength = length() + appendList.length();%0A    Object%5B%5D buffer = new Object%5BnewLength%5D;%0A%0A    for (int i = 0; i %3C newLength; i++) %7B%0A      if (i %3C length()) %7B%0A        buffer%5Bi%5D= ge
+return new ArrayList%3CT%3E(values);%0A  %7D%0A%0A  public List%3CT%3E add(List%3CT%3E appendList) %7B%0A    java.util.List%3CT%3E javaList = toJavaLis
 t(
-i
 );%0A    
-  %7D else %7B%0A        buffer%5Bi%5D = appendList.get(i - length());%0A      %7D%0A    %7D
+javaList.addAll(appendList.toJavaList());
 %0A%0A  
@@ -850,24 +850,33 @@
 List
-%3CT%3E
 ((T%5B%5D) 
-buffer
+javaList.toArray()
 );%0A 
@@ -993,26 +993,28 @@
     
-return equals
+List%3CT%3E other
 List
-(
+ = 
 (Lis
@@ -1029,335 +1029,66 @@
 ject
-)
 ;%0A    
-%7D else %7B%0A      return false;%0A    %7D%0A  %7D%0A%0A  private boolean equalsList(List%3CT%3E otherList) %7B%0A    if (length() == otherList.length()) %7B%0A      boolean isEqual = true;%0A%0A      for (int i = 0; i %3C length(); i++) %7B%0A        if (!get(i).equals(otherList.get(i))) %7B%0A          isEqual = false;%0A        %7D%0A      %7D%0A%0A      return isEqual
+  return toJavaList().equals(otherList.toJavaList())
 ;%0A  

Use Java implementation for #equals/#add