1 19 package bak.pcj.adapter; 20 21 import bak.pcj.Adapter; 22 import bak.pcj.list.AbstractDoubleList; 23 import bak.pcj.list.DoubleListIterator; 24 import bak.pcj.util.Exceptions; 25 26 import java.util.List ; 27 28 63 public class ListToDoubleListAdapter extends AbstractDoubleList { 64 65 66 protected List list; 67 68 82 public ListToDoubleListAdapter(List list) { 83 this(list, false); 84 } 85 86 110 public ListToDoubleListAdapter(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, double v) 120 { list.add(index, new Double (v)); } 121 122 public double get(int index) 123 { return ((Double )list.get(index)).doubleValue(); } 124 125 public DoubleListIterator listIterator(int index) 126 { return new ListIteratorToDoubleListIteratorAdapter(list.listIterator(index)); } 127 128 public double removeElementAt(int index) 129 { return ((Double )(list.remove(index))).doubleValue(); } 130 131 public double set(int index, double v) 132 { return ((Double )list.set(index, new Double (v))).doubleValue(); } 133 134 public int size() 135 { return list.size(); } 136 137 146 public boolean validate() 147 { return Adapter.isDoubleAdaptable(list); } 148 149 158 public void evalidate() { 159 if (!validate()) 160 Exceptions.cannotAdapt("list"); 161 } 162 163 } | Popular Tags |