1 package org.apache.ojb.broker.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.Collection;
21
22
23
24
25
26
27
28 public class IdentityArrayList extends ArrayList
29 {
30
31 public IdentityArrayList()
32 {
33 }
34
35 public IdentityArrayList(int initialCapacity)
36 {
37 super(initialCapacity);
38 }
39
40 public IdentityArrayList(Collection c)
41 {
42 super(c);
43 }
44
45 public boolean contains(Object elem)
46 {
47 return indexOf(elem) >= 0;
48 }
49
50 public int indexOf(Object elem)
51 {
52 for(int i = 0; i < size(); i++)
53 if(elem == get(i))
54 return i;
55 return -1;
56 }
57
58 public int lastIndexOf(Object elem)
59 {
60 for(int i = size() - 1; i >= 0; i--)
61 if(elem == get(i))
62 return i;
63 return -1;
64 }
65
66 public boolean remove(Object o)
67 {
68 Iterator e = iterator();
69 if(o == null)
70 {
71 while(e.hasNext())
72 {
73 if(e.next() == null)
74 {
75 e.remove();
76 return true;
77 }
78 }
79 }
80 else
81 {
82 while(e.hasNext())
83 {
84 if(o == e.next())
85 {
86 e.remove();
87 return true;
88 }
89 }
90 }
91 return false;
92 }
93 }