KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datasystem > persistentsystem > ClusterCharacteristics


1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem;
2
3 import java.util.Comparator JavaDoc;
4 import com.daffodilwoods.database.resource.DException;
5 import com.daffodilwoods.database.utility.P;
6 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
7
8
9 /**
10  *
11  * <p>Title: Cluster Characteristics</p>
12  * <p>Description: Maintains Cluster Size and Its Start Address</p>
13  */

14 public class ClusterCharacteristics implements Comparable JavaDoc,Comparator JavaDoc {
15
16    /**
17    * Start address of Cluster in File
18    */

19   private int startAddress;
20
21   /**
22    * whether cluster is btreeCluster or not
23    */

24   boolean isBtreeCluster;
25    /**
26     * hashCode of Cluster
27     */

28    private int hashCode;
29
30
31    public ClusterCharacteristics(int startAddress0, boolean isBtreeCluster0) {
32        startAddress = startAddress0;
33        isBtreeCluster = isBtreeCluster0;
34        long value = startAddress*11;
35        hashCode = (int)(value ^ (value >> 32));
36    }
37
38    public int hashCode() {
39       return hashCode;
40    }
41    /** Doesn't Used Now
42     * Setting start address of cluster in database file but doesn't used now.
43     * @param add int
44     */

45    public void setStartAddress(int add) {
46       startAddress = add;
47    }
48    /**
49     * to compare it with passed object that both are same or not
50     * If any class cast raised for passed object than returns false becuase passed
51     * Object is not a instance of ClusterCharacteristics.
52     * @param object Object to be compared.
53     * @return boolean - true if both have same start address ( means both points same location in file)
54     * - false if both have different start address ( means both points different location in file)
55     */

56    public boolean equals(Object JavaDoc object) {
57     try {
58       ClusterCharacteristics cc = (ClusterCharacteristics) object;
59       return cc.startAddress == startAddress;
60     }
61     catch (ClassCastException JavaDoc ex) {
62       return false;
63     }
64    }
65    /**
66     * It is used to compare that passed key have startAddress greater than it or not.
67     * It is not used in data system but is indirectly used in other classes.
68     * It checks start address of itself with start address of passed object
69     * now if it is < 0 than it indicates that passes object points location
70     * in file which is large than the loction of current ClusterCharacteristics and we return -1.
71     * if difference > 0 than it indicates that current ClusterCharacteristics
72     * points location large than passed key.
73     * If difference == 0 than it indicated that both are pointing same location
74     * of file.
75     * @param key1 Object - which is to be compared.
76     * @return int difference on campare basis of start address .
77     */

78    public int compareTo(Object JavaDoc key1) {
79       int diff = startAddress-((ClusterCharacteristics)key1).startAddress;
80       int cmp = diff < 0 ? -1 : diff > 0 ? 1 : 0;
81       return cmp;
82    }
83    /**
84     * It is used to compare that passed both key have startAddress greater
85     * of each other or not.
86     * It is not used in data system but is indirectly used in other classes.
87     * It checks start address of first object itself with start address of second object
88     * now if it is < 0 than it indicates that second object points location
89     * in file which is large than the loction of first Object and we return -1.
90     * if difference > 0 than it indicates that first object
91     * points location large than second object.
92     * If difference == 0 than it indicated that both are pointing same location
93     * of file.
94     * @param O1 Object - first object to be compared.
95     * @param O2 Object - second object to be compared.
96     * @return int difference on campare basis of there start address .
97     */

98
99    public int compare(Object JavaDoc o1, Object JavaDoc o2) {
100       int diff = (((ClusterCharacteristics)o1).startAddress-((ClusterCharacteristics)o2).startAddress);
101       int cmp = diff < 0 ? -1 : diff > 0 ? 1 : 0;
102       return cmp;
103    }
104
105    /**
106     * returns Cluster start address in file
107     * @return Start address of Cluster
108     */

109
110    public int getStartAddress(){
111       return startAddress;
112    }
113
114    public String JavaDoc toString() {
115       return "["+startAddress+"] --- ["+hashCode+"]";
116    }
117 }
118
Popular Tags