1 11 package org.eclipse.jface.util; 12 13 32 public final class Assert { 33 34 43 private static class AssertionFailedException extends RuntimeException { 44 45 49 private static final long serialVersionUID = 3257852073508024376L; 50 51 54 public AssertionFailedException() { 55 } 56 57 61 public AssertionFailedException(String detail) { 62 super(detail); 63 } 64 } 65 66 67 private Assert() { 68 } 69 70 80 public static boolean isLegal(boolean expression) { 81 if (expression) { 83 return true; 84 } 85 return isLegal(expression, ""); } 87 88 100 public static boolean isLegal(boolean expression, String message) { 101 if (!expression) { 102 throw new IllegalArgumentException ("assertion failed; " + message); } 104 return expression; 105 } 106 107 124 public static void isNotNull(Object object) { 125 if (object != null) { 127 return; 128 } 129 isNotNull(object, ""); } 131 132 151 public static void isNotNull(Object object, String message) { 152 if (object == null) { 153 throw new AssertionFailedException("null argument;" + message); } 155 } 156 157 165 public static boolean isTrue(boolean expression) { 166 if (expression) { 168 return true; 169 } 170 return isTrue(expression, ""); } 172 173 183 public static boolean isTrue(boolean expression, String message) { 184 if (!expression) { 185 throw new AssertionFailedException("Assertion failed: " + message); } 187 return expression; 188 } 189 } 190 | Popular Tags |