Changeset 1179
- Timestamp:
- 05/27/08 07:41:53 (3 months ago)
- Files:
-
- trunk/descent.core/src-util/melnorme/miscutil/ArrayUtil.java (modified) (3 diffs)
- trunk/descent.core/src-util/melnorme/miscutil/Assert.java (modified) (3 diffs)
- trunk/descent.core/src-util/melnorme/miscutil/ExceptionAdapter.java (modified) (3 diffs)
- trunk/descent.core/src-util/melnorme/miscutil/IteratorUtil.java (modified) (1 diff)
- trunk/descent.core/src-util/melnorme/miscutil/StringUtil.java (modified) (1 diff)
- trunk/descent.core/src-util/melnorme/miscutil/log/AbstractPrinter.java (deleted)
- trunk/descent.core/src-util/melnorme/miscutil/log/IPrinter.java (deleted)
- trunk/descent.core/src-util/melnorme/miscutil/log/StreamPrinter.java (deleted)
- trunk/descent.core/src-util/melnorme/miscutil/log/WriterPrinter.java (deleted)
- trunk/descent.core/src-util/melnorme/miscutil/tree/TreeDepthRecon.java (modified) (2 diffs)
- trunk/descent.core/src-util/readme.txt (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.core/src-util/melnorme/miscutil/ArrayUtil.java
r675 r1179 1 1 package melnorme.miscutil; 2 2 3 import static melnorme.miscutil.Assert.assertTrue; 4 3 5 import java.lang.reflect.Array; 6 import java.util.List; 4 7 5 8 public class ArrayUtil { … … 75 78 return false; 76 79 } 80 81 /** Return the index of the first occurrence of elem in array, or -1 if no occurrences. */ 82 public static <T> int indexOf(T[] array, T elem) { 83 for (int i = 0; i < array.length; i++) { 84 if(array[i].equals(elem)) 85 return i; 86 } 87 return -1; 88 } 89 90 /** Return the index of the first occurrence of elem in array, or -1 if no occurrences. */ 91 public static int indexOf(byte[] array, byte elem) { 92 for (int i = 0; i < array.length; i++) { 93 if(array[i] == elem) 94 return i; 95 } 96 return -1; 97 } 98 77 99 78 100 /** … … 152 174 return copy; 153 175 } 176 177 /** Copies src array range [0 .. src.length] to dest array starting at destIx. */ 178 public static void copyToRange(byte[] src, byte[] dest, int destIx) { 179 assertTrue(src.length < dest.length - destIx); 180 System.arraycopy(src, 0, dest, destIx, src.length); 181 } 182 183 /** Create an array from the given list, with the given run-time 184 * component type. 185 * If the list is null, a zero-length array is created. */ 186 @SuppressWarnings("unchecked") 187 public static <T> T[] createFrom(List<T> list, Class<T> cpType) { 188 if(list == null) 189 return (T[])Array.newInstance(cpType, 0); 190 191 return list.toArray((T[])Array.newInstance(cpType, list.size())); 192 } 193 194 /** Creates an array with the same size as the given list. 195 * If the list is null, a zero-length array is created. */ 196 @SuppressWarnings("unchecked") 197 public static <T> T[] newSameSize(List<?> list, Class<T> cpType) { 198 if(list == null) 199 return (T[])Array.newInstance(cpType, 0); 200 201 return (T[])Array.newInstance(cpType, list.size()); 202 } 203 204 /** Finds the index in the given array of the element that 205 * equal given elem. */ 206 public static <T> int getIndexOfEquals(T[] arr, T elem) { 207 for (int i = 0; i < arr.length; i++) { 208 if(arr[i].equals(elem)); 209 return i; 210 } 211 return -1; 212 } 154 213 155 214 trunk/descent.core/src-util/melnorme/miscutil/Assert.java
r711 r1179 82 82 83 83 /** Causes an inconditional assertion failure, with message msg. 84 * Never returns, even though return type is not void. 84 85 */ 85 public static voidfail(String msg) {86 public static AssertionFailedException fail(String msg) { 86 87 throw new AssertionFailedException("ASSERT FAIL:" + msg); 87 88 } … … 89 90 /** Like {@link #fail(String)} with empty message. 90 91 */ 91 public static voidfail() {92 public static AssertionFailedException fail() { 92 93 throw new AssertionFailedException("ASSERT FAIL"); 93 94 } … … 139 140 /** Causes an inconditional assertion failure, with message msg. 140 141 */ 141 public static voidassertFail(String msg) {142 Assert.fail(msg);142 public static AssertionFailedException assertFail(String msg) { 143 return Assert.fail(msg); 143 144 } 144 145 145 146 /** Like {@link #fail(String)} with empty message. 146 147 */ 147 public static voidassertFail() {148 Assert.fail();148 public static AssertionFailedException assertFail() { 149 return Assert.fail(); 149 150 } 150 151 trunk/descent.core/src-util/melnorme/miscutil/ExceptionAdapter.java
r646 r1179 1 1 package melnorme.miscutil; 2 3 import java.io.IOException; 2 4 3 5 … … 36 38 */ 37 39 38 protected void printStackTrace(melnorme.miscutil.log.IPrinter pr) { 39 synchronized (pr) { 40 pr.println(this); 41 StackTraceElement[] trace = originalException.getStackTrace(); 42 for (int i=0; i < trace.length; i++) { 43 pr.print("\tat " + trace[i]); 44 if(i == checkedLength) 45 pr.print(" [UNCHECKED]"); 46 pr.println(); 47 } 40 41 protected void printStackTrace(Appendable pr) { 42 synchronized(pr) { 43 try { 44 pr.append(this.toString()); 45 StackTraceElement[] trace = originalException.getStackTrace(); 46 for (int i=0; i < trace.length; i++) { 47 pr.append("\tat " + trace[i]); 48 if(i == checkedLength) 49 pr.append(" [UNCHECKED]"); 50 pr.append("\n"); 51 } 52 } catch (IOException e) { 53 melnorme.miscutil.Assert.assertFail(); 54 } 48 55 } 49 56 } 50 57 51 public void printStackTrace(java.io.PrintStream ps) { 52 printStackTrace(new melnorme.miscutil.log.StreamPrinter(ps)); 58 @Override 59 public void printStackTrace(java.io.PrintStream ps) { 60 printStackTrace(ps); 53 61 } 54 62 63 @Override 55 64 public void printStackTrace(java.io.PrintWriter pw) { 56 printStackTrace( new melnorme.miscutil.log.WriterPrinter(pw));65 printStackTrace(pw); 57 66 } 58 67 … … 62 71 } 63 72 73 @Override 64 74 public String toString() { 65 75 //String name = getClass().getName(); trunk/descent.core/src-util/melnorme/miscutil/IteratorUtil.java
r646 r1179 6 6 public class IteratorUtil { 7 7 8 public static final Iterator EMPTY_ITERATOR = Collections.EMPTY_LIST.iterator();8 public static final Iterator<?> EMPTY_ITERATOR = Collections.EMPTY_LIST.iterator(); 9 9 10 10 @SuppressWarnings("unchecked") 11 11 public static <T> Iterator<T> getEMPTY_ITERATOR() { 12 return EMPTY_ITERATOR;12 return (Iterator<T>) EMPTY_ITERATOR; 13 13 } 14 14 trunk/descent.core/src-util/melnorme/miscutil/StringUtil.java
r671 r1179 82 82 return new String[0]; 83 83 String[] strs = new String[coll.size()]; 84 Iterator iter = coll.iterator();84 Iterator<?> iter = coll.iterator(); 85 85 for (int i = 0; i < strs.length; i++) { 86 86 strs[i] = iter.next().toString(); trunk/descent.core/src-util/melnorme/miscutil/tree/TreeDepthRecon.java
r653 r1179 39 39 40 40 41 @Override 41 42 public boolean enterNode(IElement element) { 42 43 depth++; … … 56 57 } 57 58 59 @Override 58 60 public void leaveNode(IElement element) { 59 61 depth--;
