1 18 19 package org.sablecc.sablecc.alphabet; 20 21 25 final class SymbolPair<T extends Comparable <? super T>> { 26 27 28 private final Symbol<T> symbol1; 29 30 31 private final Symbol<T> symbol2; 32 33 34 private Integer hashCode; 35 36 40 private String toString; 41 42 50 SymbolPair( 51 Symbol<T> symbol1, 52 Symbol<T> symbol2) { 53 54 this.symbol1 = symbol1; 55 this.symbol2 = symbol2; 56 } 57 58 63 Symbol<T> getSymbol1() { 64 65 return this.symbol1; 66 } 67 68 73 Symbol<T> getSymbol2() { 74 75 return this.symbol2; 76 } 77 78 87 @Override 88 public boolean equals( 89 Object obj) { 90 91 if (this == obj) { 92 return true; 93 } 94 95 if (obj == null) { 96 return false; 97 } 98 99 if (getClass() != obj.getClass()) { 100 return false; 101 } 102 103 SymbolPair symbolPair = (SymbolPair) obj; 104 105 if (this.symbol1 == null && symbolPair.symbol1 != null) { 106 return false; 107 } 108 109 if (this.symbol2 == null && symbolPair.symbol2 != null) { 110 return false; 111 } 112 113 return (this.symbol1 == null || this.symbol1.equals(symbolPair.symbol1)) 114 && (this.symbol2 == null || this.symbol2 115 .equals(symbolPair.symbol2)); 116 } 117 118 123 @Override 124 public int hashCode() { 125 126 if (this.hashCode == null) { 127 128 int hashCode = 0; 129 130 if (this.symbol1 != null) { 131 hashCode += this.symbol1.hashCode(); 132 } 133 134 if (this.symbol2 != null) { 135 hashCode += 17 * this.symbol2.hashCode(); 136 } 137 138 this.hashCode = hashCode; 139 } 140 141 return this.hashCode; 142 } 143 144 149 @Override 150 public String toString() { 151 152 if (this.toString == null) { 153 this.toString = "(" + this.symbol1 + "," + this.symbol2 + ")"; 154 } 155 156 return this.toString; 157 } 158 } 159 | Popular Tags |