KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > server > page > info > PageInfo


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.impl.server.page.info;
25
26 import org.objectweb.jalisto.se.impl.InFileAddress;
27
28 import java.io.Serializable JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.LinkedList JavaDoc;
31
32 public class PageInfo implements Serializable JavaDoc {
33     public PageInfo(short pageSize, short pageType) {
34         this.freePlaces = new LinkedList JavaDoc();
35         this.size = pageSize;
36         this.pageType = pageType;
37
38         for (int i = 0; i < size; i++) {
39             freePlaces.addLast(new Integer JavaDoc(i));
40         }
41     }
42
43     public short getPageType() {
44         return pageType;
45     }
46
47     public Iterator JavaDoc getAllFreePlace() {
48         return freePlaces.iterator();
49     }
50
51     public boolean isEmpty() {
52         return (freePlaces.size() == size);
53     }
54
55     public int getEmptySpace() {
56         return freePlaces.size();
57     }
58
59     public Integer JavaDoc getAFreePlace() {
60         Integer JavaDoc result = (Integer JavaDoc) freePlaces.getFirst();
61         freePlaces.removeFirst();
62         return result;
63     }
64
65     public void allocateFreeSpaceAt(Integer JavaDoc index) {
66         freePlaces.addLast(index);
67     }
68
69     public boolean hasFreeSpaceAt(Integer JavaDoc index) {
70         return freePlaces.contains(index);
71     }
72
73     public void noMorefreeSpaceAt(Integer JavaDoc index) {
74         freePlaces.remove(index);
75     }
76
77     public void setPageIfa(InFileAddress pageIfa) {
78         this.pageIfa = pageIfa;
79     }
80
81     public InFileAddress getPageIfa() {
82         return pageIfa.getClone();
83     }
84
85     public void setPid(Object JavaDoc pid) {
86         this.pid = pid;
87     }
88
89     public Object JavaDoc getPid() {
90         return pid;
91     }
92
93     public PageInfo getClone() {
94         PageInfo clone = new PageInfo(size, pageType);
95         clone.pageIfa = pageIfa.getClone();
96         clone.freePlaces = new LinkedList JavaDoc(freePlaces);
97         clone.pid = pid;
98         return clone;
99     }
100
101     public String JavaDoc toString() {
102         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
103         sb.append("PageInfo:").append(pid).append(':').append(pageIfa)
104                 .append(':').append(getEmptySpace());
105
106         return sb.toString();
107     }
108
109
110     private InFileAddress pageIfa;
111     private LinkedList JavaDoc freePlaces;
112     private Object JavaDoc pid;
113     private short size;
114     private short pageType;
115
116
117     static final long serialVersionUID = -7589377097964761459L;
118 }
119
Popular Tags