/interpreter/tags/at2dist170907/test/edu/vub/at/objects/natives/VectorProxy.java

http://ambienttalk.googlecode.com/ · Java · 202 lines · 151 code · 45 blank · 6 comment · 2 complexity · f3468d3792e6988fec88c152eaad42a8 MD5 · raw file

  1. /**
  2. *
  3. */
  4. package edu.vub.at.objects.natives;
  5. import java.util.Collection;
  6. import java.util.Enumeration;
  7. import java.util.List;
  8. /**
  9. * Auxiliary class which forwards all operations to the default Vector but has elementCount as a public field
  10. */
  11. public class VectorProxy {
  12. public int elementCount;
  13. private java.util.Vector impl;
  14. public VectorProxy() {
  15. impl = new java.util.Vector();
  16. }
  17. public void add(int index, Object element) {
  18. impl.add(index, element);
  19. elementCount++;
  20. }
  21. public synchronized boolean add(Object o) {
  22. elementCount++;
  23. return impl.add(o);
  24. }
  25. public synchronized boolean addAll(Collection c) {
  26. elementCount += c.size();
  27. return impl.addAll(c);
  28. }
  29. public synchronized boolean addAll(int index, Collection c) {
  30. elementCount += c.size();
  31. return impl.addAll(index, c);
  32. }
  33. public synchronized void addElement(Object obj) {
  34. elementCount++;
  35. impl.addElement(obj);
  36. }
  37. public int capacity() {
  38. return impl.capacity();
  39. }
  40. public void clear() {
  41. elementCount = 0;
  42. impl.clear();
  43. }
  44. public synchronized Object clone() {
  45. return impl.clone();
  46. }
  47. public boolean contains(Object elem) {
  48. return impl.contains(elem);
  49. }
  50. public synchronized boolean containsAll(Collection c) {
  51. return impl.containsAll(c);
  52. }
  53. public synchronized void copyInto(Object[] anArray) {
  54. impl.copyInto(anArray);
  55. }
  56. public synchronized Object elementAt(int index) {
  57. return impl.elementAt(index);
  58. }
  59. public Enumeration elements() {
  60. return impl.elements();
  61. }
  62. public synchronized void ensureCapacity(int minCapacity) {
  63. impl.ensureCapacity(minCapacity);
  64. }
  65. public synchronized boolean equals(Object o) {
  66. return impl.equals(o);
  67. }
  68. public synchronized Object firstElement() {
  69. return impl.firstElement();
  70. }
  71. public synchronized Object get(int index) {
  72. return impl.get(index);
  73. }
  74. public synchronized int hashCode() {
  75. return impl.hashCode();
  76. }
  77. public synchronized int indexOf(Object elem, int index) {
  78. return impl.indexOf(elem, index);
  79. }
  80. public int indexOf(Object elem) {
  81. return impl.indexOf(elem);
  82. }
  83. public synchronized void insertElementAt(Object obj, int index) {
  84. impl.insertElementAt(obj, index);
  85. }
  86. public boolean isEmpty() {
  87. return impl.isEmpty();
  88. }
  89. public synchronized Object lastElement() {
  90. return impl.lastElement();
  91. }
  92. public synchronized int lastIndexOf(Object elem, int index) {
  93. return impl.lastIndexOf(elem, index);
  94. }
  95. public int lastIndexOf(Object elem) {
  96. return impl.lastIndexOf(elem);
  97. }
  98. public synchronized Object remove(int index) {
  99. elementCount--;
  100. return impl.remove(index);
  101. }
  102. public boolean remove(Object o) {
  103. boolean result = impl.remove(o);
  104. if(result) elementCount--;
  105. return result;
  106. }
  107. public synchronized boolean removeAll(Collection c) {
  108. boolean result = impl.removeAll(c);
  109. elementCount = impl.size();
  110. return result;
  111. }
  112. public synchronized void removeAllElements() {
  113. elementCount = 0;
  114. impl.removeAllElements();
  115. }
  116. public synchronized boolean removeElement(Object obj) {
  117. boolean result = impl.removeElement(obj);
  118. if(result) elementCount--;
  119. return result;
  120. }
  121. public synchronized void removeElementAt(int index) {
  122. elementCount--;
  123. impl.removeElementAt(index);
  124. }
  125. public synchronized boolean retainAll(Collection c) {
  126. boolean result = impl.retainAll(c);
  127. elementCount = impl.size();
  128. return result;
  129. }
  130. public synchronized Object set(int index, Object element) {
  131. return impl.set(index, element);
  132. }
  133. public synchronized void setElementAt(Object obj, int index) {
  134. impl.setElementAt(obj, index);
  135. }
  136. public synchronized void setSize(int newSize) {
  137. impl.setSize(newSize);
  138. }
  139. public int size() {
  140. return impl.size();
  141. }
  142. public List subList(int fromIndex, int toIndex) {
  143. return impl.subList(fromIndex, toIndex);
  144. }
  145. public synchronized Object[] toArray() {
  146. return impl.toArray();
  147. }
  148. public synchronized Object[] toArray(Object[] a) {
  149. return impl.toArray(a);
  150. }
  151. public synchronized String toString() {
  152. return impl.toString();
  153. }
  154. public synchronized void trimToSize() {
  155. impl.trimToSize();
  156. }
  157. }