KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > persistence > btreeimpl > btreeindex > TreeMetrics


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.mdr.persistence.btreeimpl.btreeindex;
20
21 import java.io.PrintStream JavaDoc;
22
23 public class TreeMetrics {
24
25     private int depth;
26     private int numOfPages;
27     private long totalBytes;
28     private long usedBytes;
29     private long numOfEntries;
30     private long numOfLeafEntries;
31
32     public TreeMetrics(int depth, int numOfPages, long totalBytes, long usedBytes, long numOfEntries,
33         long numberOfLeafEntries) {
34
35         this.depth = depth;
36         this.numOfPages = numOfPages;
37         this.totalBytes = totalBytes;
38         this.usedBytes = usedBytes;
39         this.numOfEntries = numOfEntries;
40         this.numOfLeafEntries = numberOfLeafEntries;
41     }
42
43     /*
44     public TreeMetrics() {
45         this.depth = 0;
46         this.numOfPages = 0;
47         this.totalBytes = 0;
48         this.usedBytes = 0;
49         this.numOfEntries = 0;
50     }
51      */

52     
53     public int getDepth() {
54         return depth;
55     }
56     
57     public int getNumberOfPages() {
58         return numOfPages;
59     }
60     
61     public double getLoadFactor() {
62         return totalBytes > 0 ? (double)usedBytes / (double)totalBytes : 0;
63     }
64
65     public long getTotalBytes() {
66         return totalBytes;
67     }
68
69     public long getUsedBytes() {
70         return usedBytes;
71     }
72     
73     public void setDepth(int depth) {
74         this.depth = depth;
75     }
76
77     public void setNumberOfPages(int numOfPages) {
78         this.numOfPages = numOfPages;
79     }
80
81     public void setTotalBytes(long totalBytes) {
82         this.totalBytes = totalBytes;
83     }
84
85     public void setUsedBytes(long usedBytes) {
86         this.usedBytes = usedBytes;
87     }
88
89     public void print(PrintStream JavaDoc stream) {
90         stream.println("depth: " + depth); // NOI18N
91
stream.println("#pages: " + numOfPages); // NOI18N
92
stream.println("#entries: " + numOfEntries); // NOI18N
93
stream.println("#leaf entries: " + numOfLeafEntries); // NOI18N
94
stream.println("used bytes: " + usedBytes); // NOI18N
95
stream.println("total bytes: " + totalBytes); // NOI18N
96
stream.println("load factor: " + getLoadFactor()); // NOI18N
97
}
98     
99     public static TreeMetrics computeParent(TreeMetrics[] m, long tBytes, long uBytes, long entries) {
100         int d = 0;
101         int pages = 0;
102         long bytes = 0;
103         long used = 0;
104         long entrs = 0;
105         long leafEntries = 0;
106         
107         for (int x = 0; x < m.length; x++) {
108             if (m[x].getDepth() > d) {
109                 d = m[x].getDepth();
110             }
111             pages += m[x].getNumberOfPages();
112             bytes += m[x].getTotalBytes();
113             used += m[x].getUsedBytes();
114             entrs += m[x].getNumOfEntries();
115             leafEntries += m[x].getNumOfLeafEntries();
116         }
117         return new TreeMetrics(d + 1, pages + 1, bytes + tBytes, used + uBytes, entrs + entries, leafEntries);
118     }
119
120     public long getNumOfEntries() {
121         return numOfEntries;
122     }
123
124     public void setNumOfEntries(long numOfEntries) {
125         this.numOfEntries = numOfEntries;
126     }
127
128     public long getNumOfLeafEntries() {
129         return numOfLeafEntries;
130     }
131
132     public void setNumOfLeafEntries(long numOfLeafEntries) {
133         this.numOfLeafEntries = numOfLeafEntries;
134     }
135     
136 }
137
Popular Tags