1 18 19 package org.sablecc.sablecc.alphabet; 20 21 import org.sablecc.sablecc.exception.InternalException; 22 23 33 34 public abstract class AdjacencyRealm<T extends Comparable <? super T>> { 35 36 39 public AdjacencyRealm() { 40 41 } 42 43 55 public abstract boolean isAdjacent( 56 T bound1, 57 T bound2); 58 59 67 public abstract T previous( 68 T bound); 69 70 78 public abstract T next( 79 T bound); 80 81 93 public static <T extends Comparable <? super T>> T min( 94 T bound1, 95 T bound2) { 96 97 if (bound1 == null) { 98 throw new InternalException("bound1 may not be null"); 99 } 100 101 if (bound2 == null) { 102 throw new InternalException("bound2 may not be null"); 103 } 104 105 if (bound1.compareTo(bound2) <= 0) { 106 return bound1; 107 } 108 109 return bound2; 110 } 111 112 124 public static <T extends Comparable <? super T>> T max( 125 T bound1, 126 T bound2) { 127 128 if (bound1 == null) { 129 throw new InternalException("bound1 may not be null"); 130 } 131 132 if (bound2 == null) { 133 throw new InternalException("bound2 may not be null"); 134 } 135 136 if (bound1.compareTo(bound2) >= 0) { 137 return bound1; 138 } 139 140 return bound2; 141 } 142 143 152 public Interval<T> createInterval( 153 T lowerBound, 154 T upperBound) { 155 156 if (lowerBound == null) { 157 throw new InternalException("lowerBound may not be null"); 158 } 159 160 if (upperBound == null) { 161 throw new InternalException("upperBound may not be null"); 162 } 163 164 return new Interval<T>(lowerBound, upperBound, this); 165 } 166 167 175 public Interval<T> createInterval( 176 T bound) { 177 178 if (bound == null) { 179 throw new InternalException("bound may not be null"); 180 } 181 182 return new Interval<T>(bound, this); 183 184 } 185 } 186 | Popular Tags |