1 19 20 package edu.umd.cs.findbugs.ba.vna; 21 22 import edu.umd.cs.findbugs.ba.InstanceField; 23 import edu.umd.cs.findbugs.ba.StaticField; 24 import edu.umd.cs.findbugs.ba.XField; 25 26 41 public class AvailableLoad implements Comparable <AvailableLoad> { 42 private final ValueNumber reference; 43 private final XField field; 44 45 50 public AvailableLoad(StaticField staticField) { 51 this.reference = null; 52 this.field = staticField; 53 } 54 55 61 public AvailableLoad(ValueNumber reference, InstanceField field) { 62 if (reference == null) throw new IllegalArgumentException (); 63 this.reference = reference; 64 this.field = field; 65 } 66 67 73 public ValueNumber getReference() { 74 return reference; 75 } 76 77 public boolean matchesReference(ValueNumber v) { 78 if (v == reference) return true; 79 if (reference== null) return false; 80 return reference.equals(v); 81 } 82 87 public XField getField() { 88 return field; 89 } 90 91 public int compareTo(AvailableLoad other) { 92 int cmp = field.compareTo(other.field); 93 if (cmp != 0) 94 return cmp; 95 else if (reference == other.reference) 96 return 0; 97 else if (reference == null) 98 return -1; 99 else if (other.reference == null) 100 return 1; 101 else 102 return reference.compareTo(other.reference); 103 } 104 105 @Override 106 public int hashCode() { 107 return (reference == null ? 0 : reference.hashCode()) ^ field.hashCode(); 108 } 109 110 @Override 111 public boolean equals(Object o) { 112 if (o == null || this.getClass() != o.getClass()) 113 return false; 114 AvailableLoad other = (AvailableLoad) o; 115 return (reference == other.reference || 116 (reference != null && other.reference != null && reference.equals(other.reference))) 117 && field.equals(other.field); 118 } 119 120 @Override 121 public String toString() { 122 return (reference == null ? "" : reference.getNumber() + ".") + field; 123 } 124 } 125 126 | Popular Tags |