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 14 public JSONArrayList() { 15 backingArray = new JSONArray(); 16 } 17 18 public JSONArrayList(JSONArray array) { 19 backingArray = array; 20 } 21 22 @Override 23 public void add(int index, T object) { 24 backingArray.set(index, object); 25 } 26 27 @SuppressWarnings("unchecked") 28 @Override 29 public T get(int index) { 30 return (T) backingArray.get(index); 31 } 32 33 // JSONArrays don't directly support this 34 @Override 35 public T remove(int arg0) { 36 throw new UnsupportedOperationException(); 37 } 38 39 @Override 40 public int size() { 41 return backingArray.size(); 42 } 43 44 public JSONArray getBackingArray() { 45 return backingArray; 46 } 47 } 48