1 18 package org.objectweb.speedo.genclass.collection; 19 20 import org.objectweb.jorm.api.PIndexedElem; 21 import org.objectweb.jorm.api.PExceptionIO; 22 import org.objectweb.speedo.genclass.api.SpeedoGenClassProxy; 23 import org.objectweb.speedo.genclass.GenClassAccessor; 24 25 import java.util.List ; 26 import java.util.Collection ; 27 import java.util.ListIterator ; 28 import java.util.Iterator ; 29 30 34 public class ListAccessor extends CollectionAccessor implements List { 35 39 protected int loadedSize = -1; 40 41 public ListAccessor(SpeedoGenClassProxy jdoProxy) { 42 super(jdoProxy); 43 } 44 public void workingSetClosed() { 45 super.workingSetClosed(); 46 loadedSize = elements.size(); 48 } 49 50 51 public String toString() { 52 return "ListAccessor: id=" + jdoProxy.jdoGetGenClassId(); 53 } 54 55 public PIndexedElem createPIndexedElem(GenClassAccessor gca) { 56 return new ListElem(gca); 57 } 58 59 public void paSetNbElem(int nbelem) { 60 super.paSetNbElem(nbelem); 61 loadedSize = 0; 62 } 63 64 public void paAdd(PIndexedElem elem, Object conn) throws PExceptionIO { 65 super.paAdd(elem, conn); 66 loadedSize++; 67 } 68 69 public boolean add(Object o) { 70 if (super.add(o)) { 71 int idx = elements.size() - 1; 72 ListElem le = (ListElem) elements.get(idx); 73 le.setIndex(new Integer (idx)); 74 return true; 75 } else { 76 return false; 77 } 78 } 79 80 public boolean addAll(int i, Collection collection) { 81 if (collection == null) { 82 return false; 83 } 84 int size = elements.size(); 85 if (size > i) { 86 Iterator it = collection.iterator(); 87 int j = i; 88 while(it.hasNext()) { 89 add(j, it.next()); 90 j++; 91 } 92 return true; 93 } else { 94 throw new IndexOutOfBoundsException ("Try to insert at the position " 95 + i + " whereas there is only " + size + " elements."); 96 } 97 } 98 99 public Object get(int i) { 100 ListElem le = (ListElem) elements.get(i); 101 if (le.getElemStatus() == PIndexedElem.ELEM_DELETED) { 102 throw new java.lang.ArrayIndexOutOfBoundsException (i); 103 } 104 return le.getElement(); 105 } 106 107 public Object set(int i, Object o) { 108 ListElem le = (ListElem) elements.get(i); 109 if (le.getElemStatus() == PIndexedElem.ELEM_DELETED) { 110 throw new java.lang.ArrayIndexOutOfBoundsException (i); 111 } 112 Object res = le.getElement(); 113 le.setStatus(PIndexedElem.ELEM_MODIFIED); 114 le.setElement(o); 115 return res; 116 } 117 118 public void add(int i, Object o) { 119 int size = elements.size(); 120 if (size > i) { 121 Object toAdd = o; 122 Object tmp = o; 123 int j = i; 124 ListElem le; 125 while(j < size) { 127 le =(ListElem) elements.get(j); 128 tmp = le.element; 129 le.element = toAdd; 130 le.setStatus((j < loadedSize 131 ? PIndexedElem.ELEM_MODIFIED 132 : PIndexedElem.ELEM_CREATED)); 133 toAdd = tmp; 134 j++; 135 } 136 le = (ListElem) createPIndexedElem(); 138 le.setStatus((j < loadedSize 139 ? PIndexedElem.ELEM_MODIFIED 140 : PIndexedElem.ELEM_CREATED)); 141 le.setIndex(new Integer (size)); 142 elements.add(le); 143 } else { 144 throw new IndexOutOfBoundsException ("Try to insert at the position " 145 + i + " whereas there is only " + size + " elements."); 146 } 147 } 148 149 public Object remove(int i) { 150 return null; 151 } 152 153 public int indexOf(Object o) { 154 return 0; 155 } 156 157 public int lastIndexOf(Object o) { 158 return 0; 159 } 160 161 public ListIterator listIterator() { 162 return null; 163 } 164 165 public ListIterator listIterator(int i) { 166 return null; 167 } 168 169 public List subList(int i, int i1) { 170 return null; 171 } 172 } 173 | Popular Tags |