use Validate#isTrue to validate arguments
This commit is contained in:
parent
52d6e24d19
commit
ff6b0ada72
|
@ -179,9 +179,7 @@ final class CharRange implements Iterable<Character>, Serializable {
|
|||
* @throws IllegalArgumentException if {@code null} input
|
||||
*/
|
||||
public boolean contains(final CharRange range) {
|
||||
if (range == null) {
|
||||
throw new IllegalArgumentException("The Range must not be null");
|
||||
}
|
||||
Validate.isTrue(range != null, "The Range must not be null");
|
||||
if (negated) {
|
||||
if (range.negated) {
|
||||
return start >= range.start && end <= range.end;
|
||||
|
|
|
@ -128,9 +128,7 @@ public class CharUtils {
|
|||
* @throws IllegalArgumentException if the Character is null
|
||||
*/
|
||||
public static char toChar(final Character ch) {
|
||||
if (ch == null) {
|
||||
throw new IllegalArgumentException("The Character must not be null");
|
||||
}
|
||||
Validate.isTrue(ch != null, "The Character must not be null");
|
||||
return ch.charValue();
|
||||
}
|
||||
|
||||
|
@ -171,9 +169,7 @@ public class CharUtils {
|
|||
* @throws IllegalArgumentException if the String is empty
|
||||
*/
|
||||
public static char toChar(final String str) {
|
||||
if (StringUtils.isEmpty(str)) {
|
||||
throw new IllegalArgumentException("The String must not be empty");
|
||||
}
|
||||
Validate.isTrue(StringUtils.isNotEmpty(str), "The String must not be empty");
|
||||
return str.charAt(0);
|
||||
}
|
||||
|
||||
|
@ -261,9 +257,7 @@ public class CharUtils {
|
|||
* @throws IllegalArgumentException if the Character is not ASCII numeric or is null
|
||||
*/
|
||||
public static int toIntValue(final Character ch) {
|
||||
if (ch == null) {
|
||||
throw new IllegalArgumentException("The character must not be null");
|
||||
}
|
||||
Validate.isTrue(ch != null, "The character must not be null");
|
||||
return toIntValue(ch.charValue());
|
||||
}
|
||||
|
||||
|
|
|
@ -133,9 +133,7 @@ public class SerializationUtils {
|
|||
* @throws SerializationException (runtime) if the serialization fails
|
||||
*/
|
||||
public static void serialize(final Serializable obj, final OutputStream outputStream) {
|
||||
if (outputStream == null) {
|
||||
throw new IllegalArgumentException("The OutputStream must not be null");
|
||||
}
|
||||
Validate.isTrue(outputStream != null, "The OutputStream must not be null");
|
||||
try (ObjectOutputStream out = new ObjectOutputStream(outputStream)){
|
||||
out.writeObject(obj);
|
||||
} catch (final IOException ex) {
|
||||
|
@ -190,9 +188,7 @@ public class SerializationUtils {
|
|||
* (runtime) if the serialization fails
|
||||
*/
|
||||
public static <T> T deserialize(final InputStream inputStream) {
|
||||
if (inputStream == null) {
|
||||
throw new IllegalArgumentException("The InputStream must not be null");
|
||||
}
|
||||
Validate.isTrue(inputStream != null, "The InputStream must not be null");
|
||||
try (ObjectInputStream in = new ObjectInputStream(inputStream)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final T obj = (T) in.readObject();
|
||||
|
@ -223,9 +219,7 @@ public class SerializationUtils {
|
|||
* (runtime) if the serialization fails
|
||||
*/
|
||||
public static <T> T deserialize(final byte[] objectData) {
|
||||
if (objectData == null) {
|
||||
throw new IllegalArgumentException("The byte[] must not be null");
|
||||
}
|
||||
Validate.isTrue(objectData != null, "The byte[] must not be null");
|
||||
return SerializationUtils.<T>deserialize(new ByteArrayInputStream(objectData));
|
||||
}
|
||||
|
||||
|
|
|
@ -50,9 +50,7 @@ public class ThreadUtils {
|
|||
* thread groups from this thread's thread group up to the system thread group
|
||||
*/
|
||||
public static Thread findThreadById(final long threadId, final ThreadGroup threadGroup) {
|
||||
if (threadGroup == null) {
|
||||
throw new IllegalArgumentException("The thread group must not be null");
|
||||
}
|
||||
Validate.isTrue(threadGroup != null, "The thread group must not be null");
|
||||
final Thread thread = findThreadById(threadId);
|
||||
if(thread != null && threadGroup.equals(thread.getThreadGroup())) {
|
||||
return thread;
|
||||
|
@ -75,9 +73,7 @@ public class ThreadUtils {
|
|||
* thread groups from this thread's thread group up to the system thread group
|
||||
*/
|
||||
public static Thread findThreadById(final long threadId, final String threadGroupName) {
|
||||
if (threadGroupName == null) {
|
||||
throw new IllegalArgumentException("The thread group name must not be null");
|
||||
}
|
||||
Validate.isTrue(threadGroupName != null, "The thread group name must not be null");
|
||||
final Thread thread = findThreadById(threadId);
|
||||
if(thread != null && thread.getThreadGroup() != null && thread.getThreadGroup().getName().equals(threadGroupName)) {
|
||||
return thread;
|
||||
|
@ -118,12 +114,8 @@ public class ThreadUtils {
|
|||
* thread groups from this thread's thread group up to the system thread group
|
||||
*/
|
||||
public static Collection<Thread> findThreadsByName(final String threadName, final String threadGroupName) {
|
||||
if (threadName == null) {
|
||||
throw new IllegalArgumentException("The thread name must not be null");
|
||||
}
|
||||
if (threadGroupName == null) {
|
||||
throw new IllegalArgumentException("The thread group name must not be null");
|
||||
}
|
||||
Validate.isTrue(threadName != null, "The thread name must not be null");
|
||||
Validate.isTrue(threadGroupName != null, "The thread group name must not be null");
|
||||
|
||||
final Collection<ThreadGroup> threadGroups = findThreadGroups(new NamePredicate(threadGroupName));
|
||||
|
||||
|
@ -311,9 +303,7 @@ public class ThreadUtils {
|
|||
*/
|
||||
public NamePredicate(final String name) {
|
||||
super();
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("The name must not be null");
|
||||
}
|
||||
Validate.isTrue(name != null, "The name must not be null");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
@ -398,12 +388,8 @@ public class ThreadUtils {
|
|||
* thread groups from this thread's thread group up to the system thread group
|
||||
*/
|
||||
public static Collection<Thread> findThreads(final ThreadGroup group, final boolean recurse, final ThreadPredicate predicate) {
|
||||
if (group == null) {
|
||||
throw new IllegalArgumentException("The group must not be null");
|
||||
}
|
||||
if (predicate == null) {
|
||||
throw new IllegalArgumentException("The predicate must not be null");
|
||||
}
|
||||
Validate.isTrue(group != null, "The group must not be null");
|
||||
Validate.isTrue(predicate != null, "The predicate must not be null");
|
||||
|
||||
int count = group.activeCount();
|
||||
Thread[] threads;
|
||||
|
@ -434,12 +420,8 @@ public class ThreadUtils {
|
|||
* thread groups from this thread's thread group up to the system thread group
|
||||
*/
|
||||
public static Collection<ThreadGroup> findThreadGroups(final ThreadGroup group, final boolean recurse, final ThreadGroupPredicate predicate){
|
||||
if (group == null) {
|
||||
throw new IllegalArgumentException("The group must not be null");
|
||||
}
|
||||
if (predicate == null) {
|
||||
throw new IllegalArgumentException("The predicate must not be null");
|
||||
}
|
||||
Validate.isTrue(group != null, "The group must not be null");
|
||||
Validate.isTrue(predicate != null, "The predicate must not be null");
|
||||
|
||||
int count = group.activeGroupCount();
|
||||
ThreadGroup[] threadGroups;
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -102,12 +103,8 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
public DiffBuilder(final Object lhs, final Object rhs,
|
||||
final ToStringStyle style, final boolean testTriviallyEqual) {
|
||||
|
||||
if (lhs == null) {
|
||||
throw new IllegalArgumentException("lhs cannot be null");
|
||||
}
|
||||
if (rhs == null) {
|
||||
throw new IllegalArgumentException("rhs cannot be null");
|
||||
}
|
||||
Validate.isTrue(lhs != null, "lhs cannot be null");
|
||||
Validate.isTrue(rhs != null, "rhs cannot be null");
|
||||
|
||||
this.diffs = new ArrayList<>();
|
||||
this.left = lhs;
|
||||
|
@ -167,9 +164,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final boolean lhs,
|
||||
final boolean rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -209,9 +204,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final boolean[] lhs,
|
||||
final boolean[] rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
}
|
||||
|
@ -250,9 +243,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final byte lhs,
|
||||
final byte rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
}
|
||||
|
@ -291,9 +282,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final byte[] lhs,
|
||||
final byte[] rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -333,9 +322,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final char lhs,
|
||||
final char rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -375,9 +362,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final char[] lhs,
|
||||
final char[] rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -417,9 +402,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final double lhs,
|
||||
final double rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -459,9 +442,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final double[] lhs,
|
||||
final double[] rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -501,9 +482,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final float lhs,
|
||||
final float rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -543,9 +522,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final float[] lhs,
|
||||
final float[] rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -585,9 +562,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final int lhs,
|
||||
final int rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -627,9 +602,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final int[] lhs,
|
||||
final int[] rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -669,9 +642,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final long lhs,
|
||||
final long rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -711,9 +682,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final long[] lhs,
|
||||
final long[] rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -753,9 +722,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final short lhs,
|
||||
final short rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -795,9 +762,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final short[] lhs,
|
||||
final short[] rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
|
@ -837,9 +802,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final Object lhs,
|
||||
final Object rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
}
|
||||
|
@ -923,9 +886,7 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName, final Object[] lhs,
|
||||
final Object[] rhs) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
}
|
||||
|
@ -987,12 +948,8 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
*/
|
||||
public DiffBuilder append(final String fieldName,
|
||||
final DiffResult diffResult) {
|
||||
if (fieldName == null) {
|
||||
throw new IllegalArgumentException("Field name cannot be null");
|
||||
}
|
||||
if (diffResult == null) {
|
||||
throw new IllegalArgumentException("Diff result cannot be null");
|
||||
}
|
||||
validateFieldNameNotNull(fieldName);
|
||||
Validate.isTrue(diffResult != null, "Diff result cannot be null");
|
||||
if (objectsTriviallyEqual) {
|
||||
return this;
|
||||
}
|
||||
|
@ -1019,4 +976,8 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
return new DiffResult(left, right, diffs, style);
|
||||
}
|
||||
|
||||
private void validateFieldNameNotNull(final String fieldName) {
|
||||
Validate.isTrue(fieldName != null, "Field name cannot be null");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A {@code DiffResult} contains a collection of the differences between two
|
||||
|
@ -71,18 +73,9 @@ public class DiffResult implements Iterable<Diff<?>> {
|
|||
*/
|
||||
DiffResult(final Object lhs, final Object rhs, final List<Diff<?>> diffs,
|
||||
final ToStringStyle style) {
|
||||
if (lhs == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Left hand object cannot be null");
|
||||
}
|
||||
if (rhs == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Right hand object cannot be null");
|
||||
}
|
||||
if (diffs == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"List of differences cannot be null");
|
||||
}
|
||||
Validate.isTrue(lhs != null, "Left hand object cannot be null");
|
||||
Validate.isTrue(rhs != null, "Right hand object cannot be null");
|
||||
Validate.isTrue(diffs != null, "List of differences cannot be null");
|
||||
|
||||
this.diffs = diffs;
|
||||
this.lhs = lhs;
|
||||
|
|
|
@ -354,10 +354,7 @@ public class HashCodeBuilder implements Builder<Integer> {
|
|||
*/
|
||||
public static <T> int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final T object,
|
||||
final boolean testTransients, final Class<? super T> reflectUpToClass, final String... excludeFields) {
|
||||
|
||||
if (object == null) {
|
||||
throw new IllegalArgumentException("The object to build a hash code for must not be null");
|
||||
}
|
||||
Validate.isTrue(object != null, "The object to build a hash code for must not be null");
|
||||
final HashCodeBuilder builder = new HashCodeBuilder(initialNonZeroOddNumber, multiplierNonZeroOddNumber);
|
||||
Class<?> clazz = object.getClass();
|
||||
reflectionAppend(object, clazz, builder, testTransients, excludeFields);
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -364,9 +365,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
}
|
||||
|
||||
private static Object checkNotNull(final Object obj) {
|
||||
if (obj == null) {
|
||||
throw new IllegalArgumentException("The Object passed in should not be null.");
|
||||
}
|
||||
Validate.isTrue(obj != null, "The Object passed in should not be null.");
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>Assists in implementing {@link Object#toString()} methods.</p>
|
||||
|
@ -132,9 +133,7 @@ public class ToStringBuilder implements Builder<String> {
|
|||
* @throws IllegalArgumentException if the style is <code>null</code>
|
||||
*/
|
||||
public static void setDefaultStyle(final ToStringStyle style) {
|
||||
if (style == null) {
|
||||
throw new IllegalArgumentException("The style must not be null");
|
||||
}
|
||||
Validate.isTrue(style != null, "The style must not be null");
|
||||
defaultStyle = style;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.commons.lang3.concurrent;
|
|||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A specialized {@link BackgroundInitializer} implementation that wraps a
|
||||
|
@ -118,8 +120,6 @@ public class CallableBackgroundInitializer<T> extends BackgroundInitializer<T> {
|
|||
* @throws IllegalArgumentException if the {@code Callable} is <b>null</b>
|
||||
*/
|
||||
private void checkCallable(final Callable<T> call) {
|
||||
if (call == null) {
|
||||
throw new IllegalArgumentException("Callable must not be null!");
|
||||
}
|
||||
Validate.isTrue(call != null, "Callable must not be null!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.util.NoSuchElementException;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A specialized {@link BackgroundInitializer} implementation that can deal with
|
||||
|
@ -131,14 +133,8 @@ public class MultiBackgroundInitializer
|
|||
* @throws IllegalStateException if {@code start()} has already been called
|
||||
*/
|
||||
public void addInitializer(final String name, final BackgroundInitializer<?> init) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Name of child initializer must not be null!");
|
||||
}
|
||||
if (init == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Child initializer must not be null!");
|
||||
}
|
||||
Validate.isTrue(name != null, "Name of child initializer must not be null!");
|
||||
Validate.isTrue(init != null, "Child initializer must not be null!");
|
||||
|
||||
synchronized (this) {
|
||||
if (isStarted()) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.StringTokenizer;
|
|||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>Provides utilities for manipulating and examining
|
||||
|
@ -454,9 +455,7 @@ public class ExceptionUtils {
|
|||
if (throwable == null) {
|
||||
return;
|
||||
}
|
||||
if (stream == null) {
|
||||
throw new IllegalArgumentException("The PrintStream must not be null");
|
||||
}
|
||||
Validate.isTrue(stream != null, "The PrintStream must not be null");
|
||||
final String trace[] = getRootCauseStackTrace(throwable);
|
||||
for (final String element : trace) {
|
||||
stream.println(element);
|
||||
|
@ -487,9 +486,7 @@ public class ExceptionUtils {
|
|||
if (throwable == null) {
|
||||
return;
|
||||
}
|
||||
if (writer == null) {
|
||||
throw new IllegalArgumentException("The PrintWriter must not be null");
|
||||
}
|
||||
Validate.isTrue(writer != null, "The PrintWriter must not be null");
|
||||
final String trace[] = getRootCauseStackTrace(throwable);
|
||||
for (final String element : trace) {
|
||||
writer.println(element);
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.commons.lang3.math;
|
|||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p><code>Fraction</code> is a <code>Number</code> implementation that
|
||||
* stores fractions accurately.</p>
|
||||
|
@ -313,9 +315,7 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
|||
* @throws NumberFormatException if the number format is invalid
|
||||
*/
|
||||
public static Fraction getFraction(String str) {
|
||||
if (str == null) {
|
||||
throw new IllegalArgumentException("The string must not be null");
|
||||
}
|
||||
Validate.isTrue(str != null, "The string must not be null");
|
||||
// parse double format
|
||||
int pos = str.indexOf('.');
|
||||
if (pos >= 0) {
|
||||
|
@ -733,9 +733,7 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
|||
* cannot be represented in an <code>int</code>.
|
||||
*/
|
||||
private Fraction addSub(final Fraction fraction, final boolean isAdd) {
|
||||
if (fraction == null) {
|
||||
throw new IllegalArgumentException("The fraction must not be null");
|
||||
}
|
||||
Validate.isTrue(fraction != null, "The fraction must not be null");
|
||||
// zero is identity for addition.
|
||||
if (numerator == 0) {
|
||||
return isAdd ? fraction : fraction.negate();
|
||||
|
@ -783,9 +781,7 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
|||
* <code>Integer.MAX_VALUE</code>
|
||||
*/
|
||||
public Fraction multiplyBy(final Fraction fraction) {
|
||||
if (fraction == null) {
|
||||
throw new IllegalArgumentException("The fraction must not be null");
|
||||
}
|
||||
Validate.isTrue(fraction != null, "The fraction must not be null");
|
||||
if (numerator == 0 || fraction.numerator == 0) {
|
||||
return ZERO;
|
||||
}
|
||||
|
@ -808,9 +804,7 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
|||
* <code>Integer.MAX_VALUE</code>
|
||||
*/
|
||||
public Fraction divideBy(final Fraction fraction) {
|
||||
if (fraction == null) {
|
||||
throw new IllegalArgumentException("The fraction must not be null");
|
||||
}
|
||||
Validate.isTrue(fraction != null, "The fraction must not be null");
|
||||
if (fraction.numerator == 0) {
|
||||
throw new ArithmeticException("The fraction to divide by must not be zero");
|
||||
}
|
||||
|
|
|
@ -37,12 +37,8 @@ public class IEEE754rUtils {
|
|||
* @since 3.4 Changed signature from min(double[]) to min(double...)
|
||||
*/
|
||||
public static double min(final double... array) {
|
||||
// Validates input
|
||||
if (array == null) {
|
||||
throw new IllegalArgumentException("The Array must not be null");
|
||||
}
|
||||
Validate.isTrue(array != null, "The Array must not be null");
|
||||
Validate.isTrue(array.length != 0, "Array cannot be empty.");
|
||||
|
||||
|
||||
// Finds and returns min
|
||||
double min = array[0];
|
||||
|
@ -63,10 +59,7 @@ public class IEEE754rUtils {
|
|||
* @since 3.4 Changed signature from min(float[]) to min(float...)
|
||||
*/
|
||||
public static float min(final float... array) {
|
||||
// Validates input
|
||||
if (array == null) {
|
||||
throw new IllegalArgumentException("The Array must not be null");
|
||||
}
|
||||
Validate.isTrue(array != null, "The Array must not be null");
|
||||
Validate.isTrue(array.length != 0, "Array cannot be empty.");
|
||||
|
||||
// Finds and returns min
|
||||
|
@ -156,10 +149,7 @@ public class IEEE754rUtils {
|
|||
* @since 3.4 Changed signature from max(double[]) to max(double...)
|
||||
*/
|
||||
public static double max(final double... array) {
|
||||
// Validates input
|
||||
if (array== null) {
|
||||
throw new IllegalArgumentException("The Array must not be null");
|
||||
}
|
||||
Validate.isTrue(array != null, "The Array must not be null");
|
||||
Validate.isTrue(array.length != 0, "Array cannot be empty.");
|
||||
|
||||
// Finds and returns max
|
||||
|
@ -181,10 +171,7 @@ public class IEEE754rUtils {
|
|||
* @since 3.4 Changed signature from max(float[]) to max(float...)
|
||||
*/
|
||||
public static float max(final float... array) {
|
||||
// Validates input
|
||||
if (array == null) {
|
||||
throw new IllegalArgumentException("The Array must not be null");
|
||||
}
|
||||
Validate.isTrue(array != null, "The Array must not be null");
|
||||
Validate.isTrue(array.length != 0, "Array cannot be empty.");
|
||||
|
||||
// Finds and returns max
|
||||
|
|
|
@ -1113,9 +1113,7 @@ public class NumberUtils {
|
|||
* @throws IllegalArgumentException if {@code array} is either {@code null} or empty
|
||||
*/
|
||||
private static void validateArray(final Object array) {
|
||||
if (array == null) {
|
||||
throw new IllegalArgumentException("The Array must not be null");
|
||||
}
|
||||
Validate.isTrue(array != null, "The Array must not be null");
|
||||
Validate.isTrue(Array.getLength(array) != 0, "Array cannot be empty.");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ import java.util.NoSuchElementException;
|
|||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>A suite of utilities surrounding the use of the
|
||||
* {@link java.util.Calendar} and {@link java.util.Date} object.</p>
|
||||
|
@ -511,9 +513,7 @@ public class DateUtils {
|
|||
* @throws IllegalArgumentException if the date is null
|
||||
*/
|
||||
private static Date add(final Date date, final int calendarField, final int amount) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
validateDateNotNull(date);
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
c.add(calendarField, amount);
|
||||
|
@ -640,9 +640,7 @@ public class DateUtils {
|
|||
* @since 2.4
|
||||
*/
|
||||
private static Date set(final Date date, final int calendarField, final int amount) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
validateDateNotNull(date);
|
||||
// getInstance() returns a new object, so this method is thread safe.
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.setLenient(false);
|
||||
|
@ -708,9 +706,7 @@ public class DateUtils {
|
|||
* @throws ArithmeticException if the year is over 280 million
|
||||
*/
|
||||
public static Date round(final Date date, final int field) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
validateDateNotNull(date);
|
||||
final Calendar gval = Calendar.getInstance();
|
||||
gval.setTime(date);
|
||||
modify(gval, field, ModifyType.ROUND);
|
||||
|
@ -811,9 +807,7 @@ public class DateUtils {
|
|||
* @throws ArithmeticException if the year is over 280 million
|
||||
*/
|
||||
public static Date truncate(final Date date, final int field) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
validateDateNotNull(date);
|
||||
final Calendar gval = Calendar.getInstance();
|
||||
gval.setTime(date);
|
||||
modify(gval, field, ModifyType.TRUNCATE);
|
||||
|
@ -891,9 +885,7 @@ public class DateUtils {
|
|||
* @since 2.5
|
||||
*/
|
||||
public static Date ceiling(final Date date, final int field) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
validateDateNotNull(date);
|
||||
final Calendar gval = Calendar.getInstance();
|
||||
gval.setTime(date);
|
||||
modify(gval, field, ModifyType.CEILING);
|
||||
|
@ -1130,9 +1122,7 @@ public class DateUtils {
|
|||
* @throws IllegalArgumentException if the rangeStyle is invalid
|
||||
*/
|
||||
public static Iterator<Calendar> iterator(final Date focus, final int rangeStyle) {
|
||||
if (focus == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
validateDateNotNull(focus);
|
||||
final Calendar gval = Calendar.getInstance();
|
||||
gval.setTime(focus);
|
||||
return iterator(gval, rangeStyle);
|
||||
|
@ -1655,9 +1645,7 @@ public class DateUtils {
|
|||
* @since 2.4
|
||||
*/
|
||||
private static long getFragment(final Date date, final int fragment, final TimeUnit unit) {
|
||||
if(date == null) {
|
||||
throw new IllegalArgumentException("The date must not be null");
|
||||
}
|
||||
validateDateNotNull(date);
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
return getFragment(calendar, fragment, unit);
|
||||
|
@ -1794,6 +1782,9 @@ public class DateUtils {
|
|||
return truncatedDate1.compareTo(truncatedDate2);
|
||||
}
|
||||
|
||||
private static void validateDateNotNull(final Date date) {
|
||||
Validate.isTrue(date != null, "The date must not be null");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue