| 1 19 package bak.pcj.util; 20 21 import bak.pcj.map.NoSuchMappingException; 22 import java.util.NoSuchElementException ; 23 24 32 public class Exceptions { 33 34 public static void indexOutOfBounds(int index, int low, int high) throws IndexOutOfBoundsException { 35 throw new IndexOutOfBoundsException ("Index out of bounds: " + index + ", valid range is " + low + " to " + high); 36 } 37 38 public static void nullArgument(String name) throws NullPointerException { 39 throw new NullPointerException ("The specified " + name + " is null"); 40 } 41 42 public static void negativeArgument(String name, Object value) throws IllegalArgumentException { 43 throw new IllegalArgumentException (name + " cannot be negative: " + String.valueOf(value)); 44 } 45 46 public static void negativeOrZeroArgument(String name, Object value) throws IllegalArgumentException { 47 throw new IllegalArgumentException (name + " must be a positive value: " + String.valueOf(value)); 48 } 49 50 54 public static void endOfIterator() throws NoSuchElementException { 55 throw new NoSuchElementException ("Attempt to iterate past iterator's last element."); 56 } 57 58 public static void startOfIterator() throws NoSuchElementException { 59 throw new NoSuchElementException ("Attempt to iterate past iterator's first element."); 60 } 61 62 public static void noElementToRemove() throws IllegalStateException { 63 throw new IllegalStateException ("Attempt to remove element from iterator that has no current element."); 64 } 65 66 public static void noElementToGet() throws IllegalStateException { 67 throw new IllegalStateException ("Attempt to get element from iterator that has no current element. Call next() first."); 68 } 69 70 public static void noElementToSet() throws IllegalStateException { 71 throw new IllegalStateException ("Attempt to set element in iterator that has no current element."); 72 } 73 74 78 public static void noLastElement() throws IllegalStateException { 79 throw new IllegalStateException ("No value to return. Call containsKey() first."); 80 } 81 82 public static void noSuchMapping(Object key) throws NoSuchMappingException { 83 throw new NoSuchMappingException("No such key in map: " + String.valueOf(key)); 84 } 85 86 90 public static void dequeNoFirst() throws IndexOutOfBoundsException { 91 throw new IndexOutOfBoundsException ("Attempt to get first element of empty deque"); 92 } 93 94 public static void dequeNoLast() throws IndexOutOfBoundsException { 95 throw new IndexOutOfBoundsException ("Attempt to get last element of empty deque"); 96 } 97 98 public static void dequeNoFirstToRemove() throws IndexOutOfBoundsException { 99 throw new IndexOutOfBoundsException ("Attempt to remove last element of empty deque"); 100 } 101 102 public static void dequeNoLastToRemove() throws IndexOutOfBoundsException { 103 throw new IndexOutOfBoundsException ("Attempt to remove last element of empty deque"); 104 } 105 106 110 public static void nullElementNotAllowed() throws IllegalArgumentException { 111 throw new IllegalArgumentException ("Attempt to add a null value to an adapted primitive set."); 112 } 113 114 public static void cannotAdapt(String name) throws IllegalStateException { 115 throw new IllegalStateException ("The " + name + " contains values preventing it from being adapted to a primitive " + name); 116 } 117 118 122 public static void unsupported(String name) throws UnsupportedOperationException { 123 throw new UnsupportedOperationException ("Attempt to invoke unsupported operation: " + name); 124 } 125 126 public static void unmodifiable(String name) throws UnsupportedOperationException { 127 throw new UnsupportedOperationException ("Attempt to modify unmodifiable " + name); 128 } 129 130 public static void cloning() throws RuntimeException { 131 throw new RuntimeException ("Clone is not supported"); 132 } 133 134 public static void invalidRangeBounds(Object first, Object last) throws IllegalArgumentException { 135 throw new IllegalArgumentException ("First ("+first+") cannot be greater than last ("+last+")"); 136 } 137 138 public static void cannotMergeRanges(Object r1, Object r2) throws IllegalArgumentException { 139 throw new IllegalArgumentException ("Ranges cannot be merged: " + r1.toString() + " and " + r2.toString()); 140 } 141 142 146 public static void setNoFirst() throws NoSuchElementException { 147 throw new NoSuchElementException ("Attempt to get first element of empty set"); 148 } 149 150 public static void setNoLast() throws NoSuchElementException { 151 throw new NoSuchElementException ("Attempt to get last element of empty set"); 152 } 153 154 public static void invalidSetBounds(Object low, Object high) throws IllegalArgumentException { 155 throw new IllegalArgumentException ("Lower bound ("+low+") cannot be greater than upper bound ("+high+")"); 156 } 157 158 public static void valueNotInSubRange(Object value) throws IllegalArgumentException { 159 throw new IllegalArgumentException ("Attempt to add a value outside valid range: " + value); 160 } 161 162 public static void invalidUpperBound(Object value) throws IllegalArgumentException { 163 throw new IllegalArgumentException ("Upper bound is not in valid sub-range: " + value); 164 } 165 166 public static void invalidLowerBound(Object value) throws IllegalArgumentException { 167 throw new IllegalArgumentException ("Lower bound is not in valid sub-range: " + value); 168 } 169 170 171 172 } | Popular Tags |