private static void assertNonEmptyString(String exprText, int length) { if (length == 0) { final StringBuffer sb = createExprStringBuffer(exprText).append(" is an empty string"); throw new IllegalArgumentException(sb.toString()); } }
private static void assertNonEmptyArray(String exprText, int length) { if (length == 0) { final StringBuffer sb = createExprStringBuffer(exprText).append(" is an empty array"); throw new IllegalArgumentException(sb.toString()); } }
/** * Checks if the given value is greater than the given limit. If not, an <code>IllegalArgumentException</code> is * thrown with a standardized message text using the supplied argument name. * <p/> * <p>This utility method is used to check arguments passed into methods: * <pre> * public void setWeight(long weight) { * Guardian.assertGreaterThan("weight", weight, 0); * _weight = weight; * } * </pre> * * @param exprText the test expression as text * @param exprValue the test expression result * @param limit the lower limit for the expression result * @throws IllegalArgumentException if the <code>exprValue</code> is less than or equal to <code>limit</code> */ public static void assertGreaterThan(String exprText, long exprValue, long limit) { if (exprValue <= limit) { StringBuffer sb = createExprStringBuffer(exprText) .append(" is less than or equal to [") .append(limit) .append("]"); throw new IllegalArgumentException(sb.toString()); } }
StringBuffer sb = createExprStringBuffer(exprText) .append(" is [") .append(exprValue)
/** * Checks if the given values are equal. If not, an <code>IllegalArgumentException</code> is thrown with a * standardized message text using the supplied message. * <p/> * <p>This utility method is used to check arguments passed into methods: * <pre> * public void writeDataAtRegion(int x, inty, int w, int h, byte[] data) { * Guardian.assertEquals("data.length", * data.length, w * h); * ... * } * </pre> * * @param exprText the test expression as text * @param exprValue the test expression result * @param expectedValue the expected value * @throws IllegalArgumentException if the <code>exprValue</code> is not equal to <code>expectedValue</code> */ public static void assertEquals(String exprText, long exprValue, long expectedValue) { if (expectedValue != exprValue) { StringBuffer sb = createExprStringBuffer(exprText) .append(" is [") .append(exprValue) .append("] but should be equal to [") .append(expectedValue) .append("]"); throw new IllegalArgumentException(sb.toString()); } }
/** * Checks if the given objects are the same instances. If not, an <code>IllegalArgumentException</code> is thrown * with a standardized message text using the supplied message. * <p/> * <p>This utility method is used to check arguments passed into methods: * <pre> * public NewBandDialog(final Window parent, ProductNodeList products) { * Guardian.assertNotNull("products", products); * Guardian.assertEquals("not the expected element type", Product.class, products.getElemType()); * ... * } * </pre> * * @param exprText the test expression as text * @param exprValue the actual value * @param expectedValue the expected value * @throws IllegalArgumentException if the <code>expected</code> is not identical to <code>actual</code> */ public static void assertSame(String exprText, Object exprValue, Object expectedValue) { if (expectedValue != exprValue) { StringBuffer sb = createExprStringBuffer(exprText) .append(" is [") .append(exprValue) .append("] but should be same as [") .append(expectedValue) .append("]"); throw new IllegalArgumentException(sb.toString()); } }
StringBuffer sb = createExprStringBuffer(exprText) .append(" is [") .append(exprValue)
/** * Checks if the given objects are equal. If not, an <code>IllegalArgumentException</code> is thrown with a * standardized message text using the supplied message. * <p/> * <p>This utility method is used to check arguments passed into methods: * <pre> * public NewBandDialog(final Window parent, ProductNodeList products) { * Guardian.assertNotNull("products", products); * Guardian.assertEquals("not the expected element type", Product.class, products.getElemType()); * ... * } * </pre> * * @param exprText the test expression as text * @param exprValue the test expression result * @param expectedValue the expected value * @throws IllegalArgumentException if the <code>exprValue</code> is not equal to <code>expectedValue</code> */ public static void assertEquals(String exprText, Object exprValue, Object expectedValue) { if (!ObjectUtils.equalObjects(expectedValue, exprValue)) { StringBuffer sb = createExprStringBuffer(exprText) .append(" is [") .append(exprValue) .append("] but should be equal to [") .append(expectedValue) .append("]"); throw new IllegalArgumentException(sb.toString()); } }