1 19 package bak.pcj.adapter; 20 21 import bak.pcj.Adapter; 22 import bak.pcj.list.AbstractIntList; 23 import bak.pcj.list.IntListIterator; 24 import bak.pcj.util.Exceptions; 25 26 import java.util.List ; 27 28 63 public class ListToIntListAdapter extends AbstractIntList { 64 65 66 protected List list; 67 68 82 public ListToIntListAdapter(List list) { 83 this(list, false); 84 } 85 86 110 public ListToIntListAdapter(List list, boolean validate) { 111 super(); 112 if (list == null) 113 Exceptions.nullArgument("list"); 114 this.list = list; 115 if (validate) 116 evalidate(); 117 } 118 119 public void add(int index, int v) 120 { list.add(index, new Integer (v)); } 121 122 public int get(int index) 123 { return ((Integer )list.get(index)).intValue(); } 124 125 public IntListIterator listIterator(int index) 126 { return new ListIteratorToIntListIteratorAdapter(list.listIterator(index)); } 127 128 public int removeElementAt(int index) 129 { return ((Integer )(list.remove(index))).intValue(); } 130 131 public int set(int index, int v) 132 { return ((Integer )list.set(index, new Integer (v))).intValue(); } 133 134 public int size() 135 { return list.size(); } 136 137 146 public boolean validate() 147 { return Adapter.isIntAdaptable(list); } 148 149 158 public void evalidate() { 159 if (!validate()) 160 Exceptions.cannotAdapt("list"); 161 } 162 163 } | Popular Tags |