Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / store / raw / PageKey.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/store/raw/PageKey.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/store/raw/PageKey.java
new file mode 100644 (file)
index 0000000..9b94581
--- /dev/null
@@ -0,0 +1,103 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.store.raw.PageKey\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.store.raw;\r
+\r
+import org.apache.derby.iapi.store.raw.ContainerKey;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.services.io.CompressedNumber;\r
+\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+\r
+/**\r
+       A key that identifies a BasePage. Used as the key for the caching mechanism.\r
+\r
+       <BR> MT - Immutable :\r
+*/\r
+\r
+\r
+public final class PageKey\r
+{\r
+       private final ContainerKey      container;\r
+       private final long      pageNumber;             // page number\r
+\r
+       public PageKey(ContainerKey key, long pageNumber) {\r
+               container = key;\r
+               this.pageNumber = pageNumber;\r
+       }\r
+\r
+       public long getPageNumber() {\r
+               return pageNumber;\r
+       }\r
+\r
+       public ContainerKey getContainerId() {\r
+               return container;\r
+       }\r
+\r
+       /*\r
+       ** Methods to read and write\r
+       */\r
+\r
+       public void writeExternal(ObjectOutput out) throws IOException \r
+       {\r
+               container.writeExternal(out);\r
+               CompressedNumber.writeLong(out, pageNumber);\r
+       }\r
+\r
+       public static PageKey read(ObjectInput in) throws IOException\r
+       {\r
+               ContainerKey c = ContainerKey.read(in);\r
+               long pn = CompressedNumber.readLong(in);\r
+\r
+               return new PageKey(c, pn);\r
+       }\r
+\r
+\r
+       /*\r
+       ** Methods of object\r
+       */\r
+\r
+       public boolean equals(Object other) {\r
+\r
+               if (other instanceof PageKey) {\r
+                       PageKey otherKey = (PageKey) other;\r
+\r
+                       return (pageNumber == otherKey.pageNumber) &&\r
+                                  container.equals(otherKey.container);\r
+               }\r
+\r
+               return false;\r
+       }\r
+\r
+\r
+       public int hashCode() {\r
+\r
+               return (int) (pageNumber ^ container.hashCode());\r
+       }\r
+\r
+       public String toString() {\r
+               return "Page(" + pageNumber + "," + container.toString() + ")";\r
+       }\r
+\r
+}\r