/** * Construct a Reflection instance that cache's some information about the target class. The target class is the Class object * upon which the methods will be found. * * @param targetClass the target class * @throws IllegalArgumentException if the target class is null */ public Reflection( Class<?> targetClass ) { CheckArg.isNotNull(targetClass, "targetClass"); this.targetClass = targetClass; }
/** * Create an encoder that uses the supplied algorithm and returns only the supplied number of characters in the hash. * * @param algorithm the algorithm that should be used * @param maxLength the maximumLength, or a non-positive number (or {@link Integer#MAX_VALUE}) if the full hash should be used * @throws IllegalArgumentException if the algorithm is null */ public SecureHashTextEncoder( Algorithm algorithm, int maxLength ) { CheckArg.isNotNull(algorithm, "algorithm"); this.algorithm = algorithm; this.maxLength = maxLength < 1 ? Integer.MAX_VALUE : maxLength; }
public ImmutableProblems( Problems delegate ) { CheckArg.isNotNull(delegate, "delegate"); this.delegate = delegate; }
/** * Returns the specified argument if it is not <code>null</code>. * * @param <T> * @param argument The argument * @param name The name of the argument * @return The argument * @throws IllegalArgumentException If argument is <code>null</code> */ public static <T> T getNotNull( T argument, String name ) { isNotNull(argument, name); return argument; }
public TokenStream( String content, Tokenizer tokenizer, boolean caseSensitive ) { CheckArg.isNotNull(content, "content"); CheckArg.isNotNull(tokenizer, "tokenizer"); this.inputString = content; this.inputContent = content.toCharArray(); this.caseSensitive = caseSensitive; this.inputUppercased = caseSensitive ? inputString : content.toUpperCase(); this.tokenizer = tokenizer; }
/** * Create an instance using the supplied parent list and an element to be virtually appended to the parent. Note that the * parent must be immutable (though this is not checked). * * @param parent the parent list * @param element the child element (may be null) * @throws IllegalArgumentException if the reference to the parent list is null */ public ImmutableAppendedList( List<T> parent, T element ) { CheckArg.isNotNull(parent, "parent"); this.parent = parent; this.element = element; this.size = parent.size() + 1; }
/** * Removes leading and trailing whitespace from the supplied text, and reduces other consecutive whitespace characters to a * single space. Whitespace includes line-feeds. * * @param text the text to be normalized * @return the normalized text */ public static String normalize( String text ) { CheckArg.isNotNull(text, "text"); // This could be much more efficient. return NORMALIZE_PATTERN.matcher(text).replaceAll(" ").trim(); }
/** * Create a {@link ServletSecurityContext} with the supplied {@link HttpServletRequest servlet information}. * * @param request the servlet request; may not be null */ public ServletSecurityContext( HttpServletRequest request ) { CheckArg.isNotNull(request, "request"); this.request = request; this.userName = request.getUserPrincipal() != null ? request.getUserPrincipal().getName() : null; }
/** * Check that the array is not empty * * @param argument Array * @param name The name of the argument * @throws IllegalArgumentException If array is null or empty */ public static void isNotEmpty( Object[] argument, String name ) { isNotNull(argument, name); if (argument.length == 0) { throw new IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text(name)); } }
/** * Check that the string is non-null and has length > 0 * * @param argument The argument * @param name The name of the argument * @throws IllegalArgumentException If value is null or length == 0 */ public static void isNotZeroLength( String argument, String name ) { isNotNull(argument, name); if (argument.length() <= 0) { throw new IllegalArgumentException(CommonI18n.argumentMayNotBeNullOrZeroLength.text(name)); } }
/** * Check that the map is not empty * * @param argument Map * @param name The name of the argument * @throws IllegalArgumentException If map is null or empty */ public static void isNotEmpty( Map<?, ?> argument, String name ) { isNotNull(argument, name); if (argument.isEmpty()) { throw new IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text(name)); } }
/** * Checks that the iterator is not empty, and throws an exception if it is. * * @param argument the iterator to check * @param name The name of the argument * @throws IllegalArgumentException If iterator is empty (i.e., iterator.hasNext() returns false) */ public static void isNotEmpty( Iterator<?> argument, String name ) { isNotNull(argument, name); if (!argument.hasNext()) { throw new IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text(name)); } }
/** * Check that the collection is not empty * * @param argument Collection * @param name The name of the argument * @throws IllegalArgumentException If collection is null or empty */ public static void isNotEmpty( Collection<?> argument, String name ) { isNotNull(argument, name); if (argument.isEmpty()) { throw new IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text(name)); } }
/** * Check that the array is empty * * @param argument Array * @param name The name of the argument * @throws IllegalArgumentException If array is not empty */ public static void isEmpty( Object[] argument, String name ) { isNotNull(argument, name); if (argument.length > 0) { throw new IllegalArgumentException(CommonI18n.argumentMustBeEmpty.text(name)); } }
/** * Check that the array is not null and contains no nulls * * @param argument Array * @param name The name of the argument * @throws IllegalArgumentException If array is null or has null values */ public static void containsNoNulls( Object[] argument, String name ) { isNotNull(argument, name); int i = 0; for (Object object : argument) { if (object == null) { throw new IllegalArgumentException(CommonI18n.argumentMayNotContainNullValue.text(name, i)); } ++i; } }
/** * Check that the collection contains the value * * @param argument Collection to check * @param value Value to check for, may be null * @param name The name of the argument * @throws IllegalArgumentException If collection is null or doesn't contain value */ public static void contains( Collection<?> argument, Object value, String name ) { isNotNull(argument, name); if (!argument.contains(value)) { throw new IllegalArgumentException(CommonI18n.argumentDidNotContainObject.text(name, getObjectName(value))); } }
/** * Check that the map contains the key * * @param argument Map to check * @param key Key to check for, may be null * @param name The name of the argument * @throws IllegalArgumentException If map is null or doesn't contain key */ public static void containsKey( Map<?, ?> argument, Object key, String name ) { isNotNull(argument, name); if (!argument.containsKey(key)) { throw new IllegalArgumentException(CommonI18n.argumentDidNotContainKey.text(name, getObjectName(key))); } }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param content the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null */ public static byte[] getHash( Algorithm algorithm, byte[] content ) throws NoSuchAlgorithmException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), content); }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param stream the stream containing the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null * @throws IOException if there is an error reading the stream */ public static byte[] getHash( Algorithm algorithm, InputStream stream ) throws NoSuchAlgorithmException, IOException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), stream); }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param file the file containing the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null * @throws IOException if there is an error reading the file */ public static byte[] getHash( Algorithm algorithm, File file ) throws NoSuchAlgorithmException, IOException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), file); }