KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > store > raw > PageKey


1 /*
2
3    Derby - Class org.apache.derby.iapi.store.raw.PageKey
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.store.raw;
23
24 import org.apache.derby.iapi.store.raw.ContainerKey;
25
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27 import org.apache.derby.iapi.services.io.CompressedNumber;
28
29 import java.io.ObjectOutput JavaDoc;
30 import java.io.ObjectInput JavaDoc;
31 import java.io.IOException JavaDoc;
32
33 /**
34     A key that identifies a BasePage. Used as the key for the caching mechanism.
35
36     <BR> MT - Immutable :
37 */

38
39
40 public class PageKey
41 {
42     private final ContainerKey container;
43     private final long pageNumber; // page number
44

45     public PageKey(ContainerKey key, long pageNumber) {
46         container = key;
47         this.pageNumber = pageNumber;
48     }
49
50     public long getPageNumber() {
51         return pageNumber;
52     }
53
54     public ContainerKey getContainerId() {
55         return container;
56     }
57
58     /*
59     ** Methods to read and write
60     */

61
62     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
63     {
64         container.writeExternal(out);
65         CompressedNumber.writeLong(out, pageNumber);
66     }
67
68     public static PageKey read(ObjectInput JavaDoc in) throws IOException JavaDoc
69     {
70         ContainerKey c = ContainerKey.read(in);
71         long pn = CompressedNumber.readLong(in);
72
73         return new PageKey(c, pn);
74     }
75
76
77     /*
78     ** Methods of object
79     */

80
81     public boolean equals(Object JavaDoc other) {
82
83         if (other instanceof PageKey) {
84             PageKey otherKey = (PageKey) other;
85
86             return (pageNumber == otherKey.pageNumber) &&
87                    container.equals(otherKey.container);
88         }
89
90         return false;
91     }
92
93
94     public int hashCode() {
95
96         return (int) (pageNumber ^ container.hashCode());
97     }
98
99     public String JavaDoc toString() {
100         return "Page(" + pageNumber + "," + container.toString() + ")";
101     }
102
103 }
104
Popular Tags