KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > indexing > Page


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.indexing;
12
13 import java.util.Observable JavaDoc;
14
15 public abstract class Page extends Observable JavaDoc implements Referable {
16
17     public static final int SIZE = 8192;
18
19     protected int pageNumber;
20     protected int referenceCount;
21     protected Buffer pageBuffer;
22     protected PageStore pageStore;
23
24     /**
25      * Constructs a new page of the given size.
26      */

27     public Page(int pageNumber, PageStore pageStore) {
28         this.pageNumber = pageNumber;
29         this.pageStore = pageStore;
30         this.referenceCount = 0;
31     }
32
33     /**
34      * Adds a reference for this entity to track.
35      */

36     public int addReference() {
37         referenceCount++;
38         return referenceCount;
39     }
40
41     /**
42      * Returns the page number of the page.
43      */

44     public int getPageNumber() {
45         return pageNumber;
46     }
47
48     /**
49      * Tests for existing references.
50      */

51     public boolean hasReferences() {
52         return referenceCount > 0;
53     }
54
55     /**
56      * Releases a page back to the store.
57      */

58     public void release() {
59         pageStore.release(this);
60     }
61
62     /**
63      * Removes a reference.
64      */

65     public int removeReference() {
66         if (referenceCount > 0)
67             referenceCount--;
68         return referenceCount;
69     }
70
71     /**
72      * Writes the contents of the page to a buffer.
73      */

74     public abstract void toBuffer(byte[] buffer);
75
76 }
77
Popular Tags