/** * 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; }
/** * 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))); } }
/** * Checks that the object is an instance of the specified Class and then returns the object cast to the specified Class * * @param <C> the class type * @param argument Value * @param expectedClass Class * @param name The name of the argument * @return value cast to the specified Class * @throws IllegalArgumentException If value is not an instance of theClass. */ // due to cast in return public static <C> C getInstanceOf( Object argument, Class<C> expectedClass, String name ) { isInstanceOf(argument, expectedClass, name); return expectedClass.cast(argument); }
/** * Determine whether this component has changed with respect to the supplied component. This method basically checks all * attributes, whereas {@link #equals(Object) equals} only checks the {@link #getClass() type} and {@link #getName()}. * * @param component the component to be compared with this one * @return true if this componet and the supplied component have some changes, or false if they are exactly equivalent * @throws IllegalArgumentException if the supplied component reference is null or is not the same {@link #getClass() type} as * this object */ public boolean hasChanged( ComponentConfig component ) { CheckArg.isNotNull(component, "component"); CheckArg.isInstanceOf(component, this.getClass(), "component"); if (!this.getName().equalsIgnoreCase(component.getName())) return true; if (!this.getDescription().equals(component.getDescription())) return true; if (!this.getComponentClassname().equals(component.getComponentClassname())) return true; if (!this.getComponentClasspath().equals(component.getComponentClasspath())) return true; return false; }
/** * Asserts that the specified first object is not the same as (==) the specified second object. * * @param <T> * @param argument The argument to assert as not the same as <code>object</code>. * @param argumentName The name that will be used within the exception message for the argument should an exception be thrown * @param object The object to assert as not the same as <code>argument</code>. * @param objectName The name that will be used within the exception message for <code>object</code> should an exception be * thrown; if <code>null</code> and <code>object</code> is not <code>null</code>, <code>object.toString()</code> will * be used. * @throws IllegalArgumentException If the specified objects are the same. */ public static <T> void isNotSame( final T argument, String argumentName, final T object, String objectName ) { if (argument == object) { if (objectName == null) objectName = getObjectName(object); throw new IllegalArgumentException(CommonI18n.argumentMustNotBeSameAs.text(argumentName, objectName)); } }
/** * Utility to convert {@link File} to {@link URL}. * * @param filePath the path of the file * @return the {@link URL} representation of the file. * @throws MalformedURLException * @throws IllegalArgumentException if the file path is null, empty or blank */ public static URL convertFileToURL( String filePath ) throws MalformedURLException { CheckArg.isNotEmpty(filePath, "filePath"); File file = new File(filePath.trim()); return file.toURI().toURL(); }
/** * Check that the string is not empty, is not null, and does not contain only whitespace. * * @param argument String * @param name The name of the argument * @throws IllegalArgumentException If string is null or empty */ public static void isNotEmpty( String argument, String name ) { isNotZeroLength(argument, name); if (argument != null && argument.trim().length() == 0) { throw new IllegalArgumentException(CommonI18n.argumentMayNotBeNullOrZeroLengthOrEmpty.text(name)); } }
int maxLength, String suffix ) { CheckArg.isNonNegative(maxLength, "maxLength"); if (obj == null || maxLength == 0) { return "";
/** * Asserts that the specified first object is the same as (==) the specified second object. * * @param <T> * @param argument The argument to assert as the same as <code>object</code>. * @param argumentName The name that will be used within the exception message for the argument should an exception be thrown * @param object The object to assert as the same as <code>argument</code>. * @param objectName The name that will be used within the exception message for <code>object</code> should an exception be * thrown; if <code>null</code> and <code>object</code> is not <code>null</code>, <code>object.toString()</code> will * be used. * @throws IllegalArgumentException If the specified objects are not the same. */ public static <T> void isSame( final T argument, String argumentName, final T object, String objectName ) { if (argument != object) { if (objectName == null) objectName = getObjectName(object); throw new IllegalArgumentException(CommonI18n.argumentMustBeSameAs.text(argumentName, objectName)); } }
public void addIrregular( String singular, String plural ) { CheckArg.isNotEmpty(singular, "singular rule"); CheckArg.isNotEmpty(plural, "plural rule"); String singularRemainder = singular.length() > 1 ? singular.substring(1) : ""; String pluralRemainder = plural.length() > 1 ? plural.substring(1) : ""; addPluralize("(" + singular.charAt(0) + ")" + singularRemainder + "$", "$1" + pluralRemainder); addSingularize("(" + plural.charAt(0) + ")" + pluralRemainder + "$", "$1" + singularRemainder); }
/** * 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; }
/** * 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))); } }
/** * Asserts that the specified first object is not {@link Object#equals(Object) equal to} the specified second object. This * method does take null references into consideration. * * @param <T> * @param argument The argument to assert equal to <code>object</code>. * @param argumentName The name that will be used within the exception message for the argument should an exception be thrown * @param object The object to assert as equal to <code>argument</code>. * @param objectName The name that will be used within the exception message for <code>object</code> should an exception be * thrown; if <code>null</code> and <code>object</code> is not <code>null</code>, <code>object.toString()</code> will * be used. * @throws IllegalArgumentException If the specified objects are equals. */ public static <T> void isNotEquals( final T argument, String argumentName, final T object, String objectName ) { if (argument == null) { if (object != null) return; // fall through ... both are null } else { if (!argument.equals(object)) return; // handles object==null // fall through ... they are equal } if (objectName == null) objectName = getObjectName(object); throw new IllegalArgumentException(CommonI18n.argumentMustNotBeEquals.text(argumentName, objectName)); }
String classname, String... classpath ) { CheckArg.isNotEmpty(name, "name"); this.name = name.trim(); this.description = description != null ? description.trim() : "";
public ImmutableProblems( Problems delegate ) { CheckArg.isNotNull(delegate, "delegate"); this.delegate = delegate; }
/** * Asserts that the specified first object is {@link Object#equals(Object) equal to} the specified second object. This method * does take null references into consideration. * * @param <T> * @param argument The argument to assert equal to <code>object</code>. * @param argumentName The name that will be used within the exception message for the argument should an exception be thrown * @param object The object to assert as equal to <code>argument</code>. * @param objectName The name that will be used within the exception message for <code>object</code> should an exception be * thrown; if <code>null</code> and <code>object</code> is not <code>null</code>, <code>object.toString()</code> will * be used. * @throws IllegalArgumentException If the specified objects are not equal. */ public static <T> void isEquals( final T argument, String argumentName, final T object, String objectName ) { if (argument == null) { if (object == null) return; // fall through ... one is null } else { if (argument.equals(object)) return; // fall through ... they are not equal } if (objectName == null) objectName = getObjectName(object); throw new IllegalArgumentException(CommonI18n.argumentMustBeEquals.text(argumentName, objectName)); }
/** * 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; }
public Problem( Status status, int code, I18n message, Object[] params, String resource, String location, Throwable throwable ) { CheckArg.isNotNull(status, "status"); CheckArg.isNotNull(message, "message"); this.status = status; this.code = code; this.message = message; this.parameters = params; this.resource = resource != null ? resource.trim() : null; this.location = location != null ? location.trim() : null; this.throwable = throwable; }