1 package autotest.common; 2 3 import com.google.gwt.json.client.JSONArray; 4 import com.google.gwt.json.client.JSONValue; 5 6 import java.util.AbstractList; 7 8 /** 9 * Wraps a JSONArray in a handy-dandy java.util.List interface. 10 */ 11 public class JSONArrayList<T extends JSONValue> extends AbstractList<T> { 12 private JSONArray backingArray; 13 JSONArrayList()14 public JSONArrayList() { 15 backingArray = new JSONArray(); 16 } 17 JSONArrayList(JSONArray array)18 public JSONArrayList(JSONArray array) { 19 backingArray = array; 20 } 21 22 @Override add(int index, T object)23 public void add(int index, T object) { 24 backingArray.set(index, object); 25 } 26 27 @SuppressWarnings("unchecked") 28 @Override get(int index)29 public T get(int index) { 30 return (T) backingArray.get(index); 31 } 32 33 // JSONArrays don't directly support this 34 @Override remove(int arg0)35 public T remove(int arg0) { 36 throw new UnsupportedOperationException(); 37 } 38 39 @Override size()40 public int size() { 41 return backingArray.size(); 42 } 43 getBackingArray()44 public JSONArray getBackingArray() { 45 return backingArray; 46 } 47 } 48