KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > storage > gammaStore > FreeSpace


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// Copyright (C) 2003-@year@, Leo Mekenkamp. All rights reserved.
5
//
6
// $Id: FreeSpace.java,v 1.1.2.1 2004/04/10 10:06:51 per_nyfelt Exp $
7

8 package org.ozoneDB.core.storage.gammaStore;
9
10 import java.util.Comparator JavaDoc;
11
12 public final class FreeSpace {
13
14     private static Comparator JavaDoc sizeComparator = new Comparator JavaDoc() {
15         
16         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
17             return compare((FreeSpace) o1, (FreeSpace) o2);
18         }
19         
20         private int compare(FreeSpace o1, FreeSpace o2) {
21             if (o1 == o2) {
22                 return 0;
23             }
24             if (o1 == null) {
25                 return -1;
26             }
27             if (o2 == null) {
28                 return 1;
29             }
30             int result = o1.getSize() - o2.getSize();
31             if (result == 0) {
32                 result = o1.getClusterId() - o2.getClusterId();
33                 if (result == 0) {
34                     result = o1.getLocation() - o2.getLocation();
35                 }
36             }
37             return result;
38         }
39     };
40     
41     public static Comparator JavaDoc getSizeComparator() {
42         return sizeComparator;
43     }
44     
45     private int clusterId;
46     private int location;
47     private int size;
48     
49     public FreeSpace(int clusterId, int location, int size) {
50         this.clusterId = clusterId;
51         this.location = location;
52         this.size = size;
53     }
54     
55     public int getClusterId() {
56         return clusterId;
57     }
58
59     public int getLocation() {
60         return location;
61     }
62     
63     public int getSize() {
64         return size;
65     }
66     
67     public int hashCode() {
68         return (clusterId + 1) * location;
69     }
70     
71 }
72
Popular Tags