1 11 package org.eclipse.jface.text; 12 13 32 public final class Assert { 33 34 46 private static class AssertionFailedException extends RuntimeException { 47 48 55 private static final long serialVersionUID= 3689918374733886002L; 56 57 60 public AssertionFailedException() { 61 } 62 63 68 public AssertionFailedException(String detail) { 69 super(detail); 70 } 71 } 72 73 74 private Assert() { 75 } 76 77 87 public static boolean isLegal(boolean expression) { 88 if (expression) { 90 return true; 91 } 92 return isLegal(expression, ""); } 94 95 107 public static boolean isLegal(boolean expression, String message) { 108 if (!expression) 109 throw new IllegalArgumentException ("assertion failed; " + message); return expression; 111 } 112 113 130 public static void isNotNull(Object object) { 131 if (object != null) { 133 return; 134 } 135 isNotNull(object, ""); } 137 138 157 public static void isNotNull(Object object, String message) { 158 if (object == null) 159 throw new AssertionFailedException("null argument;" + message); } 161 162 170 public static boolean isTrue(boolean expression) { 171 if (expression) { 173 return true; 174 } 175 return isTrue(expression, ""); } 177 178 188 public static boolean isTrue(boolean expression, String message) { 189 if (!expression) 190 throw new AssertionFailedException("Assertion failed: "+message); return expression; 192 } 193 } 194 | Popular Tags |