01: package com.etymon.pj.util;
02:
03: import java.util.*;
04: import com.etymon.pj.object.*;
05:
06: public class PjObjectVector {
07:
08: public PjObjectVector() {
09: _v = new Vector();
10: _free = 1;
11: }
12:
13: public PjObjectVector(int initialCapacity) {
14: _v = new Vector(initialCapacity);
15: _free = 1;
16: }
17:
18: public int getFirstFree() {
19: synchronized (this ) {
20: return _free;
21: }
22: }
23:
24: public PjObject objectAt(int index) {
25: synchronized (this ) {
26: if (index >= _v.size()) {
27: return null;
28: } else {
29: return (PjObject) (_v.elementAt(index));
30: }
31: }
32: }
33:
34: public void setObjectAt(PjObject obj, int index) {
35: synchronized (this ) {
36: if (index >= _v.size()) {
37: _v.setSize(index + 1);
38: }
39: _v.setElementAt(obj, index);
40: if (index == _free) {
41: _free = findFirstFree(index + 1);
42: }
43: }
44: }
45:
46: public int size() {
47: synchronized (this ) {
48: return _v.size();
49: }
50: }
51:
52: protected int findFirstFree(int start) {
53: synchronized (this ) {
54: int x = start;
55: int size = _v.size();
56: while ((x < size) && (_v.elementAt(x) != null)) {
57: x++;
58: }
59: return x;
60: }
61: }
62:
63: protected Vector _v;
64: protected int _free;
65:
66: }
|