KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > tree > BINReference


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: BINReference.java,v 1.18 2006/10/30 21:14:25 bostic Exp $
7  */

8
9 package com.sleepycat.je.tree;
10
11 import java.util.HashSet JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Set JavaDoc;
14
15 import com.sleepycat.je.dbi.DatabaseId;
16
17 /**
18  * A class that embodies a reference to a BIN that does not rely on a
19  * Java reference to the actual BIN.
20  */

21 public class BINReference {
22     protected byte[] idKey;
23     private long nodeId;
24     private DatabaseId databaseId;
25     private Set JavaDoc deletedKeys; // Set of Key objects
26

27     BINReference(long nodeId, DatabaseId databaseId, byte[] idKey) {
28     this.nodeId = nodeId;
29     this.databaseId = databaseId;
30     this.idKey = idKey;
31     }
32
33     public long getNodeId() {
34     return nodeId;
35     }
36
37     public DatabaseId getDatabaseId() {
38     return databaseId;
39     }
40
41     public byte[] getKey() {
42     return idKey;
43     }
44
45     public byte[] getData() {
46     return null;
47     }
48
49     public void addDeletedKey(Key key) {
50
51         if (deletedKeys == null) {
52             deletedKeys = new HashSet JavaDoc();
53         }
54         deletedKeys.add(key);
55     }
56
57     public void addDeletedKeys(BINReference other) {
58
59         if (deletedKeys == null) {
60             deletedKeys = new HashSet JavaDoc();
61         }
62         if (other.deletedKeys != null) {
63             deletedKeys.addAll(other.deletedKeys);
64         }
65     }
66
67     public void removeDeletedKey(Key key) {
68
69         if (deletedKeys != null) {
70             deletedKeys.remove(key);
71             if (deletedKeys.size() == 0) {
72                 deletedKeys = null;
73             }
74         }
75     }
76
77     public boolean hasDeletedKey(Key key) {
78
79         return (deletedKeys != null) && deletedKeys.contains(key);
80     }
81
82     public boolean deletedKeysExist() {
83
84         return ((deletedKeys != null) && (deletedKeys.size() > 0));
85     }
86
87     public Iterator JavaDoc getDeletedKeyIterator() {
88         if (deletedKeys != null) {
89             return deletedKeys.iterator();
90         } else {
91             return null;
92         }
93     }
94
95     /**
96      * Compare two BINReferences.
97      */

98     public boolean equals(Object JavaDoc obj) {
99         if (this == obj) {
100             return true;
101         }
102
103         if (!(obj instanceof BINReference)) {
104             return false;
105         }
106
107     return ((BINReference) obj).nodeId == nodeId;
108     }
109
110     public int hashCode() {
111     return (int) nodeId;
112     }
113
114     public String JavaDoc toString() {
115         return "idKey=" + Key.getNoFormatString(idKey) +
116             " nodeId = " + nodeId +
117             " db=" + databaseId +
118             " deletedKeys=" + deletedKeys;
119     }
120 }
121
122
Popular Tags