1 8 package org.ozoneDB.core.storage.gammaStore; 9 10 import java.util.Comparator ; 11 12 public final class FreeSpace { 13 14 private static Comparator sizeComparator = new Comparator () { 15 16 public int compare(Object o1, Object 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 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 |