public static boolean hasLength(String str) { return hasLength((CharSequence) str); }
public static boolean hasLength(String str) { return hasLength((CharSequence) str); }
public static boolean hasLength(String str) { return hasLength((CharSequence) str); }
/** * Assert that the given String is not empty; that is, it must not be * {@code null} and not the empty String. * * <pre class="code"> * Assert.hasLength(name, "Name must not be empty"); * </pre> * * @param text the String to check * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the text is empty * @see StringUtils#hasLength */ public static void hasLength(String text, String message) { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(message); } }
public static boolean hasText(CharSequence str) { if (!hasLength(str)) { return false; } int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
/** * Assert that the given text does not contain the given substring. * * <pre class="code"> * Assert.doesNotContain(name, "rod", "Name must not contain 'rod'"); * </pre> * * @param textToSearch the text to search * @param substring the substring to find within the text * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the text contains the substring */ public static void doesNotContain(String textToSearch, String substring, String message) { if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) && textToSearch.contains(substring)) { throw new IllegalArgumentException(message); } }
public static boolean hasText(CharSequence str) { if (!hasLength(str)) { return false; } int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
public static boolean hasText(CharSequence str) { if (!hasLength(str)) { return false; } int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
/** * Assert that the given text does not contain the given substring. * * <pre class="code"> * Assert.doesNotContain(name, "rod", "Name must not contain 'rod'"); * </pre> * * @param textToSearch the text to search * @param substring the substring to find within the text * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the text contains the substring */ public static void doesNotContain(String textToSearch, String substring, String message) { if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) && textToSearch.contains(substring)) { throw new IllegalArgumentException(message); } }
/** * Assert that the given String is not empty; that is, it must not be * {@code null} and not the empty String. * * <pre class="code"> * Assert.hasLength(name, "Name must not be empty"); * </pre> * * @param text the String to check * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the text is empty * @see StringUtils#hasLength */ public static void hasLength(String text, String message) { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(message); } }
/** * Assert that the given String is not empty; that is, it must not be * {@code null} and not the empty String. * * <pre class="code"> * Assert.hasLength(name, "Name must not be empty"); * </pre> * * @param text * the String to check * @param message * the exception message to use if the assertion fails * @see StringUtils#hasLength * @throws IllegalArgumentException * if the text is empty */ public static void hasLength(String text, String message) { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(message); } }
/** * Assert that the given text does not contain the given substring. * * <pre class="code"> * Assert.doesNotContain(name, "rod", "Name must not contain 'rod'"); * </pre> * * @param textToSearch * the text to search * @param substring * the substring to find within the text * @param message * the exception message to use if the assertion fails * @throws IllegalArgumentException * if the text contains the substring */ public static void doesNotContain(String textToSearch, String substring, String message) { if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) && textToSearch.contains(substring)) { throw new IllegalArgumentException(message); } }
/** * Delete any character in a given {@code String}. * @param inString the original {@code String} * @param charsToDelete a set of characters to delete. * E.g. "az\n" will delete 'a's, 'z's and new lines. * @return the resulting {@code String} */ public static String deleteAny(String inString, String charsToDelete) { if (!hasLength(inString) || !hasLength(charsToDelete)) { return inString; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < inString.length(); i++) { char c = inString.charAt(i); if (charsToDelete.indexOf(c) == -1) { sb.append(c); } } return sb.toString(); }
/** * Delete any character in a given {@code String}. * * @param inString the original {@code String} * @param charsToDelete a set of characters to delete. * E.g. "az\n" will delete 'a's, 'z's and new lines. * @return the resulting {@code String} */ public static String deleteAny(String inString, String charsToDelete) { if (!hasLength(inString) || !hasLength(charsToDelete)) { return inString; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < inString.length(); i++) { char c = inString.charAt(i); if (charsToDelete.indexOf(c) == -1) { sb.append(c); } } return sb.toString(); }
/** * Delete any character in a given {@code String}. * * @param inString the original {@code String} * @param charsToDelete a set of characters to delete. * E.g. "az\n" will delete 'a's, 'z's and new lines. * @return the resulting {@code String} */ public static String deleteAny(String inString, String charsToDelete) { if (!hasLength(inString) || !hasLength(charsToDelete)) { return inString; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < inString.length(); i++) { char c = inString.charAt(i); if (charsToDelete.indexOf(c) == -1) { sb.append(c); } } return sb.toString(); }
/** * Assert that the provided object is an instance of the provided class. * * <pre class="code"> * Assert.instanceOf(Foo.class, foo); * </pre> * * @param type the type to check against * @param obj the object to check * @param message a message which will be prepended to the message produced by * the function itself, and which may be used to provide context. * It should normally end in ":" or "." so that the generated * message looks OK when appended to it. * @throws IllegalArgumentException if the object is not an instance of clazz * @see Class#isInstance */ public static void isInstanceOf(Class<?> type, Object obj, String message) { notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { throw new IllegalArgumentException( (StringUtils.hasLength(message) ? message + " " : "") + "Object of class [" + (obj != null ? obj.getClass().getName() : "null") + "] must be an instance of " + type); } }
/** * Assert that {@code superType.isAssignableFrom(subType)} is {@code true}. * * <pre class="code"> * Assert.isAssignable(Number.class, myClass); * </pre> * * @param superType the super type to check against * @param subType the sub type to check * @param message a message which will be prepended to the message produced by * the function itself, and which may be used to provide context. * It should normally end in ":" or "." so that the generated * message looks OK when appended to it. * @throws IllegalArgumentException if the classes are not assignable */ public static void isAssignable(Class<?> superType, Class<?> subType, String message) { notNull(superType, "Type to check against must not be null"); if (subType == null || !superType.isAssignableFrom(subType)) { throw new IllegalArgumentException((StringUtils.hasLength(message) ? message + " " : "") + subType + " is not assignable to " + superType); } }
/** * Assert that {@code superType.isAssignableFrom(subType)} is {@code true}. * * <pre class="code"> * Assert.isAssignable(Number.class, myClass); * </pre> * * @param superType the super type to check against * @param subType the sub type to check * @param message a message which will be prepended to the message produced by * the function itself, and which may be used to provide context. * It should normally end in ":" or "." so that the generated * message looks OK when appended to it. * @throws IllegalArgumentException if the classes are not assignable */ public static void isAssignable(Class<?> superType, Class<?> subType, String message) { notNull(superType, "Type to check against must not be null"); if (subType == null || !superType.isAssignableFrom(subType)) { throw new IllegalArgumentException((StringUtils.hasLength(message) ? message + " " : "") + subType + " is not assignable to " + superType); } }
/** * Assert that the provided object is an instance of the provided class. * * <pre class="code"> * Assert.instanceOf(Foo.class, foo); * </pre> * * @param type * the type to check against * @param obj * the object to check * @param message * a message which will be prepended to the message produced by * the function itself, and which may be used to provide context. * It should normally end in ":" or "." so that the generated * message looks OK when appended to it. * @throws IllegalArgumentException * if the object is not an instance of clazz * @see Class#isInstance */ public static void isInstanceOf(Class<?> type, Object obj, String message) { notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { throw new IllegalArgumentException( (StringUtils.hasLength(message) ? message + " " : "") + "Object of class [" + (obj != null ? obj.getClass().getName() : "null") + "] must be an instance of " + type); } }
/** * Assert that {@code superType.isAssignableFrom(subType)} is {@code true}. * * <pre class="code"> * Assert.isAssignable(Number.class, myClass); * </pre> * * @param superType * the super type to check against * @param subType * the sub type to check * @param message * a message which will be prepended to the message produced by * the function itself, and which may be used to provide context. * It should normally end in ":" or "." so that the generated * message looks OK when appended to it. * @throws IllegalArgumentException * if the classes are not assignable */ public static void isAssignable(Class<?> superType, Class<?> subType, String message) { notNull(superType, "Type to check against must not be null"); if (subType == null || !superType.isAssignableFrom(subType)) { throw new IllegalArgumentException((StringUtils.hasLength(message) ? message + " " : "") + subType + " is not assignable to " + superType); } }