01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.db4ounit.common.ta.collections;
22:
23: import com.db4o.db4ounit.common.ta.*;
24:
25: public class Page extends ActivatableImpl {
26:
27: public static final int PAGESIZE = 100;
28:
29: private Object[] _data = new Object[PAGESIZE];
30: private int _top = 0;
31:
32: private int _pageIndex;
33:
34: private transient boolean _dirty = false;
35:
36: public Page(int pageIndex) {
37: _pageIndex = pageIndex;
38: }
39:
40: public boolean add(Object obj) {
41: // TA BEGIN
42: activate();
43: // TA END
44: _dirty = true;
45: _data[_top++] = obj;
46: return true;
47: }
48:
49: public int size() {
50: // TA BEGIN
51: activate();
52: // TA END
53: return _top;
54: }
55:
56: public Object get(int indexInPage) {
57: // TA BEGIN
58: activate();
59: // TA END
60: // System.out.println("got from page: " + _pageIndex);
61: _dirty = true; // just to be safe, we'll mark things as dirty if they are used.
62: return _data[indexInPage];
63: }
64:
65: public boolean isDirty() {
66: // TA BEGIN
67: // activate();
68: // TA END
69: return _dirty;
70: }
71:
72: public void setDirty(boolean dirty) {
73: // TA BEGIN
74: // activate();
75: // TA END
76: _dirty = dirty;
77: }
78:
79: public int getPageIndex() {
80: // TA BEGIN
81: activate();
82: // TA END
83: return _pageIndex;
84: }
85:
86: public boolean atCapacity() {
87: return capacity() == 0;
88: }
89:
90: public int capacity() {
91: // TA BEGIN
92: activate();
93: // TA END
94: return Page.PAGESIZE - size();
95: }
96: }
|