[FUNCTOR-10] throw NullPointerException for illegal null values
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/functor/trunk@1234990 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/NOTICE.txt b/NOTICE.txt
index ebc9328..093640d 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,5 @@
Apache Commons Functor
-Copyright 2003-2004, 2008 The Apache Software Foundation
+Copyright 2003-2004, 2008-2012 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
diff --git a/pom.xml b/pom.xml
index e5cd952..39c290e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,6 @@
<version>22</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.commons</groupId>
<artifactId>commons-functor</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Commons Functor</name>
@@ -90,6 +89,12 @@
<dependencies>
<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <!-- if upgrading, be sure to check shaded jar relocations! -->
+ <version>3.1</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
@@ -129,6 +134,63 @@
<tarLongFileMode>gnu</tarLongFileMode>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>1.5</version>
+ <configuration>
+ <minimizeJar>true</minimizeJar>
+ <createDependencyReducedPom>true</createDependencyReducedPom>
+ <createSourcesJar>true</createSourcesJar>
+ <artifactSet>
+ <includes>
+ <include>org.apache.commons:commons-lang3</include>
+ </includes>
+ </artifactSet>
+ <relocations>
+ <relocation>
+ <pattern>org.apache.commons.lang3.builder.</pattern>
+ <shadedPattern>org.apache.commons.functor._lang3.builder.__</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>org.apache.commons.lang3.exception.</pattern>
+ <shadedPattern>org.apache.commons.functor._lang3.exception.__</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>org.apache.commons.lang3.mutable.</pattern>
+ <shadedPattern>org.apache.commons.functor._lang3.mutable.__</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>org.apache.commons.lang3.tuple.</pattern>
+ <shadedPattern>org.apache.commons.functor._lang3.tuple.__</shadedPattern>
+ </relocation>
+ <relocation>
+ <pattern>org.apache.commons.lang3.</pattern>
+ <shadedPattern>org.apache.commons.functor._lang3.__</shadedPattern>
+ </relocation>
+ </relocations>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
<!--
@@ -142,6 +204,56 @@
<version>1.0</version>
</extension>
</extensions>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>
+ org.apache.maven.plugins
+ </groupId>
+ <artifactId>
+ maven-antrun-plugin
+ </artifactId>
+ <versionRange>[1.6,)</versionRange>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>
+ maven-bundle-plugin
+ </artifactId>
+ <versionRange>
+ [2.3.5,)
+ </versionRange>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
</build>
<reporting>
<plugins>
diff --git a/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionBinaryPredicate.java b/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionBinaryPredicate.java
index c893a62..58a5e6a 100644
--- a/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionBinaryPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionBinaryPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a <code>Boolean</code>-valued {@link BinaryFunction BinaryFunction} to
@@ -47,10 +48,7 @@
* @param function the {@link BinaryFunction BinaryFunction} to wrap
*/
public BinaryFunctionBinaryPredicate(final BinaryFunction<? super L, ? super R, Boolean> function) {
- if (function == null) {
- throw new IllegalArgumentException("BinaryFunction argument must not be null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "BinaryFunction argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionUnaryFunction.java b/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionUnaryFunction.java
index ad5a527..59ac5e7 100644
--- a/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionUnaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionUnaryFunction.java
@@ -18,6 +18,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a BinaryFunction as a UnaryFunction by sending the same argument to both sides of the BinaryFunction.
@@ -38,10 +39,7 @@
* @param function to adapt
*/
public BinaryFunctionUnaryFunction(BinaryFunction<? super A, ? super A, ? extends T> function) {
- if (null == function) {
- throw new IllegalArgumentException("BinaryFunction argument was null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "BinaryFunction argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java b/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java
index ba85a9d..4ec7d64 100644
--- a/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java
@@ -18,6 +18,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a BinaryPredicate as a UnaryPredicate by sending the same argument to both sides of the BinaryPredicate.
@@ -36,10 +37,7 @@
* @param predicate to adapt
*/
public BinaryPredicateUnaryPredicate(BinaryPredicate<? super A, ? super A> predicate) {
- if (null == predicate) {
- throw new IllegalArgumentException("BinaryPredicate argument was null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "BinaryPredicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureBinaryFunction.java b/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureBinaryFunction.java
index 451476e..0eeab27 100644
--- a/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureBinaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureBinaryFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -54,10 +55,7 @@
* @param procedure to adapt as a BinaryFunction
*/
public BinaryProcedureBinaryFunction(BinaryProcedure<? super L, ? super R> procedure) {
- if (procedure == null) {
- throw new IllegalArgumentException("BinaryProcedure argument was null");
- }
- this.procedure = procedure;
+ this.procedure = Validate.notNull(procedure, "BinaryProcedure argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java b/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java
index 06c55a8..fe7390e 100644
--- a/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java
@@ -18,6 +18,7 @@
import org.apache.commons.functor.BinaryProcedure;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a BinaryProcedure as a UnaryProcedure by sending the same argument to both sides of the BinaryProcedure.
@@ -36,10 +37,7 @@
* @param procedure to adapt
*/
public BinaryProcedureUnaryProcedure(BinaryProcedure<? super A, ? super A> procedure) {
- if (null == procedure) {
- throw new IllegalArgumentException("BinaryProcedure argument was null");
- }
- this.procedure = procedure;
+ this.procedure = Validate.notNull(procedure, "BinaryProcedure argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/BoundFunction.java b/src/main/java/org/apache/commons/functor/adapter/BoundFunction.java
index 378f44c..d2cf9e4 100644
--- a/src/main/java/org/apache/commons/functor/adapter/BoundFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/BoundFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Function;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -57,10 +58,9 @@
*/
@SuppressWarnings("unchecked")
public <A> BoundFunction(UnaryFunction<? super A, ? extends T> function, A arg) {
- if (function == null) {
- throw new IllegalArgumentException("UnaryFunction argument was null");
- }
- this.function = (UnaryFunction<Object, ? extends T>) function;
+ this.function =
+ (UnaryFunction<Object, ? extends T>) Validate.notNull(function,
+ "UnaryFunction argument was null");
this.arg = arg;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/BoundPredicate.java b/src/main/java/org/apache/commons/functor/adapter/BoundPredicate.java
index ca205d0..a8ce3b2 100644
--- a/src/main/java/org/apache/commons/functor/adapter/BoundPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/BoundPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -56,10 +57,9 @@
*/
@SuppressWarnings("unchecked")
public <A> BoundPredicate(UnaryPredicate<? super A> predicate, A arg) {
- if (predicate == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.predicate = (UnaryPredicate<Object>) predicate;
+ this.predicate =
+ (UnaryPredicate<Object>) Validate.notNull(predicate,
+ "UnaryPredicate argument was null");
this.param = arg;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/BoundProcedure.java b/src/main/java/org/apache/commons/functor/adapter/BoundProcedure.java
index 20b088d..e92702b 100644
--- a/src/main/java/org/apache/commons/functor/adapter/BoundProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/BoundProcedure.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -56,10 +57,9 @@
*/
@SuppressWarnings("unchecked")
public <A> BoundProcedure(UnaryProcedure<? super A> procedure, A arg) {
- if (procedure == null) {
- throw new IllegalArgumentException("UnaryProcedure argument was null");
- }
- this.procedure = (UnaryProcedure<Object>) procedure;
+ this.procedure =
+ (UnaryProcedure<Object>) Validate.notNull(procedure,
+ "UnaryProcedure argument was null");
this.param = arg;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java b/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
index 27e55b6..889874c 100644
--- a/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.Function;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -61,10 +62,9 @@
*/
@SuppressWarnings("unchecked")
public <L, R> FullyBoundFunction(BinaryFunction<? super L, ? super R, ? extends T> function, L left, R right) {
- if (function == null) {
- throw new IllegalArgumentException("BinaryFunction argument was null");
- }
- this.function = (BinaryFunction<Object, Object, T>) function;
+ this.function =
+ (BinaryFunction<Object, Object, T>) Validate.notNull(function,
+ "BinaryFunction argument was null");
this.left = left;
this.right = right;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java b/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
index 405f86b..5190f3f 100644
--- a/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.Predicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -61,10 +62,9 @@
*/
@SuppressWarnings("unchecked")
public <L, R> FullyBoundPredicate(BinaryPredicate<? super L, ? super R> predicate, L left, R right) {
- if (predicate == null) {
- throw new IllegalArgumentException("BinaryPredicate argument was null");
- }
- this.predicate = (BinaryPredicate<Object, Object>) predicate;
+ this.predicate =
+ (BinaryPredicate<Object, Object>) Validate.notNull(predicate,
+ "BinaryPredicate argument was null");
this.left = left;
this.right = right;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java b/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
index 20e971b..77f7349 100644
--- a/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryProcedure;
import org.apache.commons.functor.Procedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -60,10 +61,9 @@
*/
@SuppressWarnings("unchecked")
public <L, R> FullyBoundProcedure(BinaryProcedure<? super L, ? super R> procedure, L left, R right) {
- if (procedure == null) {
- throw new IllegalArgumentException("BinaryProcedure argument was null");
- }
- this.procedure = (BinaryProcedure<Object, Object>) procedure;
+ this.procedure =
+ (BinaryProcedure<Object, Object>) Validate.notNull(procedure,
+ "BinaryProcedure argument was null");
this.left = left;
this.right = right;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java b/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java
index d78048d..e91171c 100644
--- a/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Function;
import org.apache.commons.functor.Predicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a <code>Boolean</code>-valued
@@ -50,10 +51,7 @@
* @param function to adapt
*/
public FunctionPredicate(Function<Boolean> function) {
- if (function == null) {
- throw new IllegalArgumentException("Function argument was null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "Function argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java b/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
index 1ec8a63..edaeddc 100644
--- a/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Function;
import org.apache.commons.functor.Procedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a {@link Function Function}
@@ -51,10 +52,7 @@
* @param function the {@link Function Function} to wrap
*/
public FunctionProcedure(Function<?> function) {
- if (function == null) {
- throw new IllegalArgumentException("Function argument was null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "Function argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java b/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java
index af95e3c..4999263 100644
--- a/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Function;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -53,10 +54,7 @@
* @param function to adapt
*/
public FunctionUnaryFunction(Function<? extends T> function) {
- if (function == null) {
- throw new IllegalArgumentException("Function argument was null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "Function argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java b/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java
index 5798a2f..3547a59 100644
--- a/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -54,10 +55,7 @@
* @param function UnaryFunction for right argument
*/
public IgnoreLeftFunction(UnaryFunction<? super R, ? extends T> function) {
- if (function == null) {
- throw new IllegalArgumentException("UnaryFunction argument was null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "UnaryFunction argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java b/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
index 7a84906..6671c66 100644
--- a/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -53,10 +54,7 @@
* @param predicate the right predicate
*/
public IgnoreLeftPredicate(UnaryPredicate<? super R> predicate) {
- if (predicate == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "UnaryPredicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java b/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java
index b4d43f7..844cc49 100644
--- a/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryProcedure;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -53,10 +54,7 @@
* @param procedure to adapt
*/
public IgnoreLeftProcedure(UnaryProcedure<? super R> procedure) {
- if (procedure == null) {
- throw new IllegalArgumentException("UnaryProcedure argument was null");
- }
- this.procedure = procedure;
+ this.procedure = Validate.notNull(procedure, "UnaryProcedure argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java b/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java
index 91bcd10..7756572 100644
--- a/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -54,10 +55,7 @@
* @param function UnaryFunction to wrap
*/
public IgnoreRightFunction(UnaryFunction<? super L, ? extends T> function) {
- if (function == null) {
- throw new IllegalArgumentException("UnaryFunction argument was null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "UnaryFunction argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java b/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java
index ef259aa..dd60da4 100644
--- a/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -53,10 +54,7 @@
* @param predicate left
*/
public IgnoreRightPredicate(UnaryPredicate<? super L> predicate) {
- if (predicate == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "UnaryPredicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java b/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
index 76aba60..d886b58 100644
--- a/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryProcedure;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -53,10 +54,7 @@
* @param procedure UnaryProcedure to adapt
*/
public IgnoreRightProcedure(UnaryProcedure<? super L> procedure) {
- if (procedure == null) {
- throw new IllegalArgumentException("UnaryProcedure argument was null");
- }
- this.procedure = procedure;
+ this.procedure = Validate.notNull(procedure, "UnaryProcedure argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java b/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java
index 2537401..85da7ad 100644
--- a/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -58,10 +59,9 @@
*/
@SuppressWarnings("unchecked")
public <L> LeftBoundFunction(BinaryFunction<? super L, ? super A, ? extends T> function, L arg) {
- if (function == null) {
- throw new IllegalArgumentException("BinaryFunction argument was null");
- }
- this.function = (BinaryFunction<Object, ? super A, ? extends T>) function;
+ this.function =
+ (BinaryFunction<Object, ? super A, ? extends T>) Validate.notNull(
+ function, "BinaryFunction argument was null");
this.param = arg;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java b/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java
index 9afb1c5..2ae973d 100644
--- a/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -58,10 +59,9 @@
*/
@SuppressWarnings("unchecked")
public <L> LeftBoundPredicate(BinaryPredicate<? super L, ? super A> predicate, L arg) {
- if (predicate == null) {
- throw new IllegalArgumentException("BinaryPredicate argument was null");
- }
- this.predicate = (BinaryPredicate<Object, ? super A>) predicate;
+ this.predicate =
+ (BinaryPredicate<Object, ? super A>) Validate.notNull(predicate,
+ "BinaryPredicate argument was null");
this.param = arg;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java b/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java
index 6f1fc14..86e7981 100644
--- a/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryProcedure;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -57,10 +58,9 @@
*/
@SuppressWarnings("unchecked")
public <L> LeftBoundProcedure(BinaryProcedure<? super L, ? super A> procedure, L arg) {
- if (procedure == null) {
- throw new IllegalArgumentException("BinaryProcedure argument was null");
- }
- this.procedure = (BinaryProcedure<Object, ? super A>) procedure;
+ this.procedure =
+ (BinaryProcedure<Object, ? super A>) Validate.notNull(procedure,
+ "BinaryProcedure argument was null");
this.param = arg;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java b/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
index 905212a..7d58414 100644
--- a/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Function;
import org.apache.commons.functor.Predicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -50,10 +51,7 @@
* @param predicate to adapt
*/
public PredicateFunction(Predicate predicate) {
- if (predicate == null) {
- throw new IllegalArgumentException("Predicate argument was null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "Predicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java b/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java
index 3cc567e..8136dcb 100644
--- a/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -52,10 +53,7 @@
* @param predicate to adapt
*/
public PredicateUnaryPredicate(Predicate predicate) {
- if (predicate == null) {
- throw new IllegalArgumentException("Predicate argument was null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "Predicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java b/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
index 13b4fcc..0d2a8f0 100644
--- a/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Function;
import org.apache.commons.functor.Procedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -52,10 +53,7 @@
* @param procedure to adapt
*/
public ProcedureFunction(Procedure procedure) {
- if (procedure == null) {
- throw new IllegalArgumentException("Procedure argument was null");
- }
- this.procedure = procedure;
+ this.procedure = Validate.notNull(procedure, "Procedure argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java b/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java
index 535a62b..b62125d 100644
--- a/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -52,10 +53,7 @@
* @param procedure to adapt
*/
public ProcedureUnaryProcedure(Procedure procedure) {
- if (procedure == null) {
- throw new IllegalArgumentException("Procedure argument was null");
- }
- this.procedure = procedure;
+ this.procedure = Validate.notNull(procedure, "Procedure argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java b/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java
index ce91a12..bd3e3ec 100644
--- a/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -57,10 +58,9 @@
*/
@SuppressWarnings("unchecked")
public <R> RightBoundFunction(BinaryFunction<? super A, ? super R, ? extends T> function, R arg) {
- if (function == null) {
- throw new IllegalArgumentException("left-hand BinaryFunction argument was null");
- }
- this.function = (BinaryFunction<? super A, Object, ? extends T>) function;
+ this.function =
+ (BinaryFunction<? super A, Object, ? extends T>) Validate.notNull(
+ function, "left-hand BinaryFunction argument was null");
this.param = arg;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java b/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java
index a432912..fe2eb13 100644
--- a/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -57,10 +58,9 @@
*/
@SuppressWarnings("unchecked")
public <R> RightBoundPredicate(BinaryPredicate<? super A, ? super R> predicate, R arg) {
- if (predicate == null) {
- throw new IllegalArgumentException("BinaryPredicate argument was null");
- }
- this.predicate = (BinaryPredicate<? super A, Object>) predicate;
+ this.predicate =
+ (BinaryPredicate<? super A, Object>) Validate.notNull(predicate,
+ "BinaryPredicate argument was null");
this.param = arg;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java b/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java
index 1edd892..2071f9d 100644
--- a/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryProcedure;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -57,10 +58,9 @@
*/
@SuppressWarnings("unchecked")
public <R> RightBoundProcedure(BinaryProcedure<? super A, ? super R> procedure, R arg) {
- if (procedure == null) {
- throw new IllegalArgumentException("BinaryProcedure argument was null");
- }
- this.procedure = (BinaryProcedure<? super A, Object>) procedure;
+ this.procedure =
+ (BinaryProcedure<? super A, Object>) Validate.notNull(procedure,
+ "BinaryProcedure argument was null");
this.param = arg;
}
diff --git a/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java b/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java
index 10bf225..1385cfe 100644
--- a/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java
+++ b/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a <code>Boolean</code>-valued
@@ -52,10 +53,7 @@
* @param function the {@link UnaryFunction UnaryFunction} to wrap
*/
public UnaryFunctionUnaryPredicate(UnaryFunction<? super A, Boolean> function) {
- if (function == null) {
- throw new IllegalArgumentException("UnaryFunction argument was null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "UnaryFunction argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java b/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java
index 70c1575..49cb16a 100644
--- a/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java
+++ b/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a {@link UnaryFunction UnaryFunction}
@@ -53,10 +54,7 @@
* @param function the {@link UnaryFunction UnaryFunction} to wrap
*/
public UnaryFunctionUnaryProcedure(UnaryFunction<? super A, ?> function) {
- if (function == null) {
- throw new IllegalArgumentException("UnaryFunction argument was null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "UnaryFunction argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/UnaryPredicateUnaryFunction.java b/src/main/java/org/apache/commons/functor/adapter/UnaryPredicateUnaryFunction.java
index 9165c75..fdcdffb 100644
--- a/src/main/java/org/apache/commons/functor/adapter/UnaryPredicateUnaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/UnaryPredicateUnaryFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -51,10 +52,7 @@
* @param predicate to adapt
*/
public UnaryPredicateUnaryFunction(UnaryPredicate<? super A> predicate) {
- if (predicate == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "UnaryPredicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/adapter/UnaryProcedureUnaryFunction.java b/src/main/java/org/apache/commons/functor/adapter/UnaryProcedureUnaryFunction.java
index 57714c3..f3d6b4c 100644
--- a/src/main/java/org/apache/commons/functor/adapter/UnaryProcedureUnaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/adapter/UnaryProcedureUnaryFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a
@@ -53,10 +54,7 @@
* @param procedure to adapt
*/
public UnaryProcedureUnaryFunction(UnaryProcedure<? super A> procedure) {
- if (procedure == null) {
- throw new IllegalArgumentException("UnaryProcedure argument was null");
- }
- this.procedure = procedure;
+ this.procedure = Validate.notNull(procedure, "UnaryProcedure argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java b/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java
index 4d1ddaf..07af04b 100644
--- a/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java
+++ b/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.Function;
+import org.apache.commons.lang3.Validate;
/**
* Tail recursion for {@link Function functions}. If the {@link Function}
@@ -55,14 +56,12 @@
* @param functionType as long as result is an instance, keep processing.
*/
public RecursiveEvaluation(Function<?> function, Class<?> functionType) {
- if (function == null) {
- throw new IllegalArgumentException("Function argument was null");
- }
- if (functionType == null || !Function.class.isAssignableFrom(functionType)) {
+ Validate.notNull(function, "Function argument was null");
+ if (!Function.class.isAssignableFrom(functionType)) {
throw new IllegalArgumentException(Function.class + " is not assignable from " + functionType);
}
this.function = function;
- this.functionType = functionType;
+ this.functionType = Validate.notNull(functionType, "FunctionType argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/collection/FilteredIterator.java b/src/main/java/org/apache/commons/functor/core/collection/FilteredIterator.java
index e8a6e36..7236cf5 100644
--- a/src/main/java/org/apache/commons/functor/core/collection/FilteredIterator.java
+++ b/src/main/java/org/apache/commons/functor/core/collection/FilteredIterator.java
@@ -20,6 +20,7 @@
import java.util.NoSuchElementException;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Iterator that filters another Iterator by only passing through those elements
@@ -63,14 +64,8 @@
* @param predicate to apply
*/
public FilteredIterator(Iterator<? extends T> iterator, UnaryPredicate<? super T> predicate) {
- if (null == iterator) {
- throw new IllegalArgumentException("Iterator argument was null");
- }
- if (null == predicate) {
- throw new IllegalArgumentException("filtering UnaryPredicate argument was null");
- }
- this.predicate = predicate;
- this.iterator = iterator;
+ this.iterator = Validate.notNull(iterator, "Iterator argument was null");
+ this.predicate = Validate.notNull(predicate, "filtering UnaryPredicate argument was null");
}
// iterator methods
diff --git a/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java b/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java
index 9d2f977..04e19d3 100644
--- a/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java
+++ b/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java
@@ -23,6 +23,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate} that checks to see if the
@@ -63,15 +64,13 @@
* {@inheritDoc}
*/
public boolean test(L obj, R col) {
+ Validate.notNull(col, "Right side argument must not be null.");
if (col instanceof Collection<?>) {
return testCollection(obj, (Collection<?>) col);
}
- if (null != col && col.getClass().isArray()) {
+ if (col.getClass().isArray()) {
return testArray(obj, col);
}
- if (null == col) {
- throw new IllegalArgumentException("Right side argument must not be null.");
- }
throw new IllegalArgumentException("Expected Collection or Array, found " + col.getClass());
}
diff --git a/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java b/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java
index b1d9512..3ebda92 100644
--- a/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java
+++ b/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java
@@ -22,6 +22,7 @@
import java.util.Map;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* @param <A> the predicate argument type.
@@ -57,6 +58,7 @@
* {@inheritDoc}
*/
public boolean test(A obj) {
+ Validate.notNull(obj, "Argument must not be null");
if (obj instanceof Collection<?>) {
return testCollection((Collection<?>) obj);
}
@@ -66,12 +68,9 @@
if (obj instanceof String) {
return testString((String) obj);
}
- if (null != obj && obj.getClass().isArray()) {
+ if (obj.getClass().isArray()) {
return testArray(obj);
}
- if (null == obj) {
- throw new IllegalArgumentException("Argument must not be null");
- }
throw new IllegalArgumentException("Expected Collection, Map, String or Array, found " + obj.getClass());
}
diff --git a/src/main/java/org/apache/commons/functor/core/collection/Size.java b/src/main/java/org/apache/commons/functor/core/collection/Size.java
index 02593c1..6bf30df 100644
--- a/src/main/java/org/apache/commons/functor/core/collection/Size.java
+++ b/src/main/java/org/apache/commons/functor/core/collection/Size.java
@@ -21,6 +21,7 @@
import java.util.Collection;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Returns the size of the specified Collection, or the length
@@ -52,18 +53,16 @@
* {@inheritDoc}
*/
public Integer evaluate(Object obj) {
+ Validate.notNull(obj, "Argument must not be null");
if (obj instanceof Collection<?>) {
return evaluate((Collection<?>) obj);
}
if (obj instanceof String) {
return evaluate((String) obj);
}
- if (null != obj && obj.getClass().isArray()) {
+ if (obj.getClass().isArray()) {
return evaluateArray(obj);
}
- if (null == obj) {
- throw new IllegalArgumentException("Argument must not be null");
- }
throw new IllegalArgumentException("Expected Collection, String or Array, found " + obj);
}
diff --git a/src/main/java/org/apache/commons/functor/core/collection/TransformedIterator.java b/src/main/java/org/apache/commons/functor/core/collection/TransformedIterator.java
index a225da8..89ab5ba 100644
--- a/src/main/java/org/apache/commons/functor/core/collection/TransformedIterator.java
+++ b/src/main/java/org/apache/commons/functor/core/collection/TransformedIterator.java
@@ -19,6 +19,7 @@
import java.util.Iterator;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Iterator that transforms another Iterator by applying a UnaryFunction to each returned element.
@@ -50,14 +51,8 @@
* @param function to apply
*/
public TransformedIterator(Iterator<? extends E> iterator, UnaryFunction<? super E, ? extends T> function) {
- if (null == iterator) {
- throw new IllegalArgumentException("Iterator argument was null");
- }
- if (null == function) {
- throw new IllegalArgumentException("filtering UnaryFunction argument was null");
- }
- this.function = function;
- this.iterator = iterator;
+ this.function = Validate.notNull(function, "filtering UnaryFunction argument was null");
+ this.iterator = Validate.notNull(iterator, "Iterator argument was null");
}
// iterator methods
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java b/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java
index b7382a5..ddf57a9 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java
@@ -20,6 +20,7 @@
import java.util.Comparator;
import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a {@link Comparator Comparator} to the
@@ -51,10 +52,7 @@
* @param comparator to wrap
*/
public ComparatorFunction(Comparator<? super T> comparator) {
- if (comparator == null) {
- throw new IllegalArgumentException("Comparator must not be null");
- }
- this.comparator = comparator;
+ this.comparator = Validate.notNull(comparator, "Comparator argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java b/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java
index 6870d43..e9967d8 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java
@@ -22,6 +22,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate BinaryPredicate} that {@link #test tests}
@@ -70,10 +71,7 @@
* be used.
*/
public IsEquivalent(Comparator<? super T> comparator) {
- if (comparator == null) {
- throw new IllegalArgumentException("Comparator must not be null");
- }
- this.comparator = comparator;
+ this.comparator = Validate.notNull(comparator, "Comparator argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java b/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java
index 370aa1d..50589fa 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java
@@ -22,6 +22,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate BinaryPredicate} that {@link #test tests}
@@ -69,10 +70,7 @@
* be used.
*/
public IsGreaterThan(Comparator<? super T> comparator) {
- if (comparator == null) {
- throw new IllegalArgumentException("Comparator argument must not be null");
- }
- this.comparator = comparator;
+ this.comparator = Validate.notNull(comparator, "Comparator argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java b/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java
index fbd060a..672e7a3 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java
@@ -22,6 +22,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate BinaryPredicate} that {@link #test tests}
@@ -70,10 +71,7 @@
* be used.
*/
public IsGreaterThanOrEqual(Comparator<? super T> comparator) {
- if (comparator == null) {
- throw new IllegalArgumentException("Comparator argument must not be null");
- }
- this.comparator = comparator;
+ this.comparator = Validate.notNull(comparator, "Comparator argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java b/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java
index cb65bbe..6ed7ea3 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java
@@ -22,6 +22,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate BinaryPredicate} that {@link #test tests}
@@ -69,10 +70,7 @@
* be used.
*/
public IsLessThan(Comparator<? super T> comparator) {
- if (comparator == null) {
- throw new IllegalArgumentException("Comparator argument must not be null");
- }
- this.comparator = comparator;
+ this.comparator = Validate.notNull(comparator, "Comparator argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java b/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java
index 3c763b3..6132760 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java
@@ -22,6 +22,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate BinaryPredicate} that {@link #test tests}
@@ -69,10 +70,7 @@
* be used.
*/
public IsLessThanOrEqual(Comparator<? super T> comparator) {
- if (comparator == null) {
- throw new IllegalArgumentException("Comparator argument must not be null");
- }
- this.comparator = comparator;
+ this.comparator = Validate.notNull(comparator, "Comparator argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java b/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java
index 8051646..f481662 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java
@@ -22,6 +22,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate BinaryPredicate} that {@link #test tests}
@@ -70,10 +71,7 @@
* be used.
*/
public IsNotEquivalent(Comparator<? super T> comparator) {
- if (comparator == null) {
- throw new IllegalArgumentException("Comparator must not be null");
- }
- this.comparator = comparator;
+ this.comparator = Validate.notNull(comparator, "Comparator argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java b/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java
index 856ef02..b7756d9 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java
@@ -18,6 +18,7 @@
import java.io.Serializable;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link UnaryPredicate} that tests whether a {@link Comparable} object is
@@ -61,9 +62,8 @@
* @param max Comparable
*/
public IsWithinRange(A min, A max) {
- if (min == null || max == null) {
- throw new IllegalArgumentException("min and max must not be null");
- }
+ Validate.notNull(min, "min must not be null");
+ Validate.notNull(max, "max must not be null");
if (min.compareTo(max) > 0) {
throw new IllegalArgumentException("min must be <= max");
}
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/Max.java b/src/main/java/org/apache/commons/functor/core/comparator/Max.java
index f9822f8..6034e79 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/Max.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/Max.java
@@ -22,6 +22,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.adapter.RightBoundFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a {@link Comparator Comparator} to the
@@ -61,10 +62,7 @@
* @param comparator Comparator to use
*/
public Max(Comparator<T> comparator) {
- if (comparator == null) {
- throw new IllegalArgumentException("Comparator argument must not be null");
- }
- this.comparator = comparator;
+ this.comparator = Validate.notNull(comparator, "Comparator argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/comparator/Min.java b/src/main/java/org/apache/commons/functor/core/comparator/Min.java
index 69d47d2..7bf9d51 100644
--- a/src/main/java/org/apache/commons/functor/core/comparator/Min.java
+++ b/src/main/java/org/apache/commons/functor/core/comparator/Min.java
@@ -22,6 +22,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.adapter.RightBoundFunction;
+import org.apache.commons.lang3.Validate;
/**
* Adapts a {@link Comparator Comparator} to the
@@ -61,10 +62,7 @@
* @param comparator to use
*/
public Min(Comparator<T> comparator) {
- if (comparator == null) {
- throw new IllegalArgumentException("Comparator argument must not be null");
- }
- this.comparator = comparator;
+ this.comparator = Validate.notNull(comparator, "Comparator argument must not be null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java b/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java
index 4429fb1..98c1b8c 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java
@@ -21,6 +21,7 @@
import java.util.List;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Abstract base class for {@link BinaryPredicate BinaryPredicates}
@@ -116,10 +117,7 @@
* @param p BinaryPredicate to add
*/
protected void addBinaryPredicate(BinaryPredicate<? super L, ? super R> p) {
- if (p == null) {
- throw new IllegalArgumentException("Cannot add null BinaryPredicate");
- }
- list.add(p);
+ list.add(Validate.notNull(p, "Cannot add null BinaryPredicate"));
}
// protected
diff --git a/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java b/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java
index 759efdc..93b824f 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java
@@ -21,6 +21,7 @@
import java.util.List;
import org.apache.commons.functor.Predicate;
+import org.apache.commons.lang3.Validate;
/**
* Abstract base class for {@link Predicate Predicates}
@@ -112,10 +113,7 @@
* @param p Predicate to add
*/
protected void addPredicate(Predicate p) {
- if (p == null) {
- throw new IllegalArgumentException("Cannot add null Predicate");
- }
- list.add(p);
+ list.add(Validate.notNull(p, "Cannot add null Predicate"));
}
// protected
diff --git a/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java b/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java
index 0b3f490..da6d590 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java
@@ -21,6 +21,7 @@
import java.util.List;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Abstract base class for {@link UnaryPredicate UnaryPredicates}
@@ -114,10 +115,7 @@
* @param p UnaryPredicate to add
*/
protected void addUnaryPredicate(UnaryPredicate<? super A> p) {
- if (p == null) {
- throw new IllegalArgumentException("Cannot add null UnaryPredicate");
- }
- list.add(p);
+ list.add(Validate.notNull(p, "Cannot add null UnaryPredicate"));
}
// protected
diff --git a/src/main/java/org/apache/commons/functor/core/composite/BinaryCompositeBinaryFunction.java b/src/main/java/org/apache/commons/functor/core/composite/BinaryCompositeBinaryFunction.java
index 44f4619..0f081a3 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/BinaryCompositeBinaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/BinaryCompositeBinaryFunction.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryFunction BinaryFunction} composed of
@@ -113,10 +114,11 @@
*/
public <G, H> BinaryCompositeBinaryFunction(BinaryFunction<? super G, ? super H, ? extends T> f,
BinaryFunction<? super L, ? super R, ? extends G> g, BinaryFunction<? super L, ? super R, ? extends H> h) {
- if (f == null || g == null || h == null) {
- throw new IllegalArgumentException("BinaryFunction arguments may not be null");
- }
- this.helper = new Helper<G, H, L, R, T>(f, g, h);
+ this.helper = new Helper<G, H, L, R, T>(
+ Validate.notNull(f, "final BinaryFunction argument must not be null"),
+ Validate.notNull(g, "left preceding BinaryFunction argument must not be null"),
+ Validate.notNull(h, "right preceding BinaryFunction argument must not be null")
+ );
}
// function interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/BinaryNot.java b/src/main/java/org/apache/commons/functor/core/composite/BinaryNot.java
index 9ad15ab..8606483 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/BinaryNot.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/BinaryNot.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* {@link #test Tests} to the logical inverse
@@ -55,10 +56,7 @@
* @param predicate BinaryPredicate to negate
*/
public BinaryNot(BinaryPredicate<? super L, ? super R> predicate) {
- if (predicate == null) {
- throw new IllegalArgumentException("BinaryPredicate argument was null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "BinaryPredicate argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java b/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java
index 0f120cd..ff862b4 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* A {@link UnaryFunction UnaryFunction}
@@ -148,10 +149,7 @@
* @param function UnaryFunction to call
*/
public CompositeUnaryFunction(UnaryFunction<? super A, ? extends T> function) {
- if (function == null) {
- throw new IllegalArgumentException("function must not be null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "function must not be null");
}
/**
@@ -180,9 +178,7 @@
* @return CompositeUnaryFunction<P, T>
*/
public final <P> CompositeUnaryFunction<P, T> of(UnaryFunction<? super P, ? extends A> preceding) {
- if (preceding == null) {
- throw new IllegalArgumentException("preceding function was null");
- }
+ Validate.notNull(preceding, "preceding function was null");
return new CompositeUnaryFunction<P, T>(function, preceding);
}
diff --git a/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java b/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java
index 351fecf..d0f7629 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java
@@ -21,6 +21,7 @@
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.adapter.UnaryPredicateUnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* A {@link UnaryPredicate UnaryPredicate}
@@ -65,10 +66,10 @@
* @param predicate UnaryPredicate against which the composite functions' output will be tested
*/
public CompositeUnaryPredicate(UnaryPredicate<? super A> predicate) {
- if (null == predicate) {
- throw new IllegalArgumentException("predicate must not be null");
- }
- this.function = new CompositeUnaryFunction<A, Boolean>(new UnaryPredicateUnaryFunction<A>(predicate));
+ this.function =
+ new CompositeUnaryFunction<A, Boolean>(
+ new UnaryPredicateUnaryFunction<A>(Validate.notNull(predicate,
+ "predicate must not be null")));
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java b/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java
index 402e5cd..0af44a8 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java
@@ -21,6 +21,7 @@
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryProcedure;
import org.apache.commons.functor.adapter.UnaryProcedureUnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* A {@link UnaryProcedure UnaryProcedure}
@@ -65,10 +66,10 @@
* @param procedure final UnaryProcedure to run
*/
public CompositeUnaryProcedure(UnaryProcedure<? super A> procedure) {
- if (null == procedure) {
- throw new IllegalArgumentException("procedure must not be null");
- }
- this.function = new CompositeUnaryFunction<A, Object>(new UnaryProcedureUnaryFunction<A, Object>(procedure));
+ this.function =
+ new CompositeUnaryFunction<A, Object>(
+ new UnaryProcedureUnaryFunction<A, Object>(Validate.notNull(
+ procedure, "procedure must not be null")));
}
/**
diff --git a/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryFunction.java b/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryFunction.java
index 2c33ebd..317f4cc 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryFunction BinaryFunction}
@@ -78,15 +79,9 @@
public ConditionalBinaryFunction(BinaryPredicate<? super L, ? super R> ifPred,
BinaryFunction<? super L, ? super R, ? extends T> thenFunc,
BinaryFunction<? super L, ? super R, ? extends T> elseFunc) {
- if (ifPred == null) {
- throw new IllegalArgumentException("BinaryPredicate argument was null");
- }
- if (thenFunc == null || elseFunc == null) {
- throw new IllegalArgumentException("One or more BinaryFunction arguments was null");
- }
- this.ifPred = ifPred;
- this.thenFunc = thenFunc;
- this.elseFunc = elseFunc;
+ this.ifPred = Validate.notNull(ifPred, "BinaryPredicate argument was null");
+ this.thenFunc = Validate.notNull(thenFunc, "'then' BinaryFunction argument was null");
+ this.elseFunc = Validate.notNull(elseFunc, "'else' BinaryFunction argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryPredicate.java b/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryPredicate.java
index 311582d..5e3f8f5 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryPredicate.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryPredicate.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate BinaryPredicate}
@@ -75,12 +76,9 @@
*/
public ConditionalBinaryPredicate(BinaryPredicate<? super L, ? super R> ifPred,
BinaryPredicate<? super L, ? super R> thenPred, BinaryPredicate<? super L, ? super R> elsePred) {
- if (ifPred == null || thenPred == null || elsePred == null) {
- throw new IllegalArgumentException("One or more BinaryPredicate arguments was null");
- }
- this.ifPred = ifPred;
- this.thenPred = thenPred;
- this.elsePred = elsePred;
+ this.ifPred = Validate.notNull(ifPred, "'if' BinaryPredicate argument was null");
+ this.thenPred = Validate.notNull(thenPred, "'then' BinaryPredicate argument was null");
+ this.elsePred = Validate.notNull(elsePred, "'else' BinaryPredicate argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryProcedure.java b/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryProcedure.java
index 2a8fc0e..8daf0ff 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryProcedure.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/ConditionalBinaryProcedure.java
@@ -21,6 +21,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.BinaryProcedure;
import org.apache.commons.functor.core.NoOp;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryProcedure BinaryProcedure}
@@ -88,15 +89,9 @@
*/
public ConditionalBinaryProcedure(BinaryPredicate<? super L, ? super R> ifPred,
BinaryProcedure<? super L, ? super R> thenProc, BinaryProcedure<? super L, ? super R> elseProc) {
- if (ifPred == null) {
- throw new IllegalArgumentException("BinaryPredicate argument was null");
- }
- this.ifPred = ifPred;
- if (thenProc == null || elseProc == null) {
- throw new IllegalArgumentException("One or more BinaryProcedure arguments was null");
- }
- this.thenProc = thenProc;
- this.elseProc = elseProc;
+ this.ifPred = Validate.notNull(ifPred, "BinaryPredicate argument was null");
+ this.thenProc = Validate.notNull(thenProc, "'then' BinaryProcedure argument was null");
+ this.elseProc = Validate.notNull(elseProc, "'else' BinaryProcedure argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java b/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
index c4a930b..a0e6076 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.Function;
import org.apache.commons.functor.Predicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link Function Function}
@@ -74,15 +75,9 @@
* @param elseFunc else
*/
public ConditionalFunction(Predicate ifPred, Function<? extends T> thenFunc, Function<? extends T> elseFunc) {
- if (ifPred == null) {
- throw new IllegalArgumentException("Predicate argument was null");
- }
- this.ifPred = ifPred;
- if (thenFunc == null || elseFunc == null) {
- throw new IllegalArgumentException("One or more Function arguments was null");
- }
- this.thenFunc = thenFunc;
- this.elseFunc = elseFunc;
+ this.ifPred = Validate.notNull(ifPred, "Predicate argument was null");
+ this.thenFunc = Validate.notNull(thenFunc, "'then' Function argument was null");
+ this.elseFunc = Validate.notNull(elseFunc, "'else' Function argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java b/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
index fd58ea1..1a8e6c3 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.Predicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link Predicate Predicate}
@@ -72,12 +73,9 @@
* @param elsePred else
*/
public ConditionalPredicate(Predicate ifPred, Predicate thenPred, Predicate elsePred) {
- if (ifPred == null || thenPred == null || elsePred == null) {
- throw new IllegalArgumentException("One or more Predicate arguments was null");
- }
- this.ifPred = ifPred;
- this.thenPred = thenPred;
- this.elsePred = elsePred;
+ this.ifPred = Validate.notNull(ifPred, "'if' Predicate argument was null");
+ this.thenPred = Validate.notNull(thenPred, "'then' Predicate argument was null");
+ this.elsePred = Validate.notNull(elsePred, "'else' Predicate argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java b/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
index 7690d9f..e96d4aa 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
@@ -21,6 +21,7 @@
import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.core.NoOp;
+import org.apache.commons.lang3.Validate;
/**
* A {@link Procedure Procedure}
@@ -83,15 +84,9 @@
* @param elseProc else
*/
public ConditionalProcedure(Predicate ifPred, Procedure thenProc, Procedure elseProc) {
- if (ifPred == null) {
- throw new IllegalArgumentException("Predicate argument was null");
- }
- this.ifPred = ifPred;
- if (thenProc == null || elseProc == null) {
- throw new IllegalArgumentException("Procedure argument was null");
- }
- this.thenProc = thenProc;
- this.elseProc = elseProc;
+ this.ifPred = Validate.notNull(ifPred, "Predicate argument was null");
+ this.thenProc = Validate.notNull(thenProc, "'then' Procedure argument was null");
+ this.elseProc = Validate.notNull(elseProc, "'else' Procedure argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java b/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java
index 4e4bc8e..6da2447 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link UnaryFunction UnaryFunction}
@@ -75,16 +76,10 @@
* @param elseFunc else
*/
public ConditionalUnaryFunction(UnaryPredicate<? super A> ifPred, UnaryFunction<? super A, ? extends T> thenFunc,
- UnaryFunction<? super A, ? extends T> elseFunc) {
- if (ifPred == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.ifPred = ifPred;
- if (thenFunc == null || elseFunc == null) {
- throw new IllegalArgumentException("One or more UnaryFunction arguments was null");
- }
- this.thenFunc = thenFunc;
- this.elseFunc = elseFunc;
+ UnaryFunction<? super A, ? extends T> elseFunc) {
+ this.ifPred = Validate.notNull(ifPred, "UnaryPredicate argument was null");
+ this.thenFunc = Validate.notNull(thenFunc, "'then' UnaryFunction argument was null");
+ this.elseFunc = Validate.notNull(elseFunc, "'else' UnaryFunction argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java b/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java
index 8675c79..6c411eb 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* A {@link UnaryPredicate UnaryPredicate}
@@ -74,12 +75,9 @@
*/
public ConditionalUnaryPredicate(UnaryPredicate<? super A> ifPred, UnaryPredicate<? super A> thenPred,
UnaryPredicate<? super A> elsePred) {
- if (ifPred == null || thenPred == null || elsePred == null) {
- throw new IllegalArgumentException("One or more UnaryPredicate arguments was null");
- }
- this.ifPred = ifPred;
- this.thenPred = thenPred;
- this.elsePred = elsePred;
+ this.ifPred = Validate.notNull(ifPred, "'if' UnaryPredicate argument was null");
+ this.thenPred = Validate.notNull(thenPred, "'then' UnaryPredicate argument was null");
+ this.elsePred = Validate.notNull(elsePred, "'else' UnaryPredicate argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java b/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java
index 2a79061..361506d 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java
@@ -21,6 +21,7 @@
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
import org.apache.commons.functor.core.NoOp;
+import org.apache.commons.lang3.Validate;
/**
* A {@link UnaryProcedure UnaryProcedure}
@@ -85,15 +86,9 @@
public ConditionalUnaryProcedure(UnaryPredicate<? super A> ifPred,
UnaryProcedure<? super A> thenProc,
UnaryProcedure<? super A> elseProc) {
- if (ifPred == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.ifPred = ifPred;
- if (thenProc == null || elseProc == null) {
- throw new IllegalArgumentException("One or more UnaryProcedure arguments was null");
- }
- this.thenProc = thenProc;
- this.elseProc = elseProc;
+ this.ifPred = Validate.notNull(ifPred, "UnaryPredicate argument was null");
+ this.thenProc = Validate.notNull(thenProc, "'then' UnaryProcedure argument was null");
+ this.elseProc = Validate.notNull(elseProc, "'else' UnaryProcedure argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/Not.java b/src/main/java/org/apache/commons/functor/core/composite/Not.java
index 3dd7d1a..67849a6 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/Not.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/Not.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.Predicate;
+import org.apache.commons.lang3.Validate;
/**
* {@link #test Tests} to the logical inverse
@@ -54,10 +55,7 @@
* @param predicate Predicate to negate
*/
public Not(Predicate predicate) {
- if (predicate == null) {
- throw new IllegalArgumentException("Predicate argument was null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "Predicate argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/TransposedFunction.java b/src/main/java/org/apache/commons/functor/core/composite/TransposedFunction.java
index 518cc5a..f46375f 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/TransposedFunction.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/TransposedFunction.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* Transposes (swaps) the arguments to some other
@@ -62,10 +63,7 @@
* @param function BinaryFunction to transpose.
*/
public TransposedFunction(BinaryFunction<? super R, ? super L, ? extends T> function) {
- if (function == null) {
- throw new IllegalArgumentException("BinaryFunction argument was null");
- }
- this.function = function;
+ this.function = Validate.notNull(function, "BinaryFunction argument was null");
}
// functor interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/TransposedPredicate.java b/src/main/java/org/apache/commons/functor/core/composite/TransposedPredicate.java
index 5b89630..ad6e7ee 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/TransposedPredicate.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/TransposedPredicate.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* Transposes (swaps) the arguments to some other
@@ -60,10 +61,7 @@
* @param predicate the BinaryPredicate to transpose
*/
public TransposedPredicate(BinaryPredicate<? super R, ? super L> predicate) {
- if (predicate == null) {
- throw new IllegalArgumentException("BinaryPredicate argument must not be null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "BinaryPredicate argument must not be null");
}
// functor interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/TransposedProcedure.java b/src/main/java/org/apache/commons/functor/core/composite/TransposedProcedure.java
index 5691e5c..5bac7f4 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/TransposedProcedure.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/TransposedProcedure.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Transposes (swaps) the arguments to some other
@@ -60,10 +61,7 @@
* @param procedure BinaryProcedure to transpose
*/
public TransposedProcedure(BinaryProcedure<? super R, ? super L> procedure) {
- if (procedure == null) {
- throw new IllegalArgumentException("BinaryProcedure argument was null");
- }
- this.procedure = procedure;
+ this.procedure = Validate.notNull(procedure, "BinaryProcedure argument was null");
}
// functor interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryFunction.java b/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryFunction.java
index f60c4d4..f08a6e6 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryFunction.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryFunction.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryFunction BinaryFunction} composed of
@@ -117,13 +118,11 @@
*/
public <G, H> UnaryCompositeBinaryFunction(BinaryFunction<? super G, ? super H, ? extends T> f,
UnaryFunction<? super L, ? extends G> g, UnaryFunction<? super R, ? extends H> h) {
- if (f == null) {
- throw new IllegalArgumentException("BinaryFunction must not be null");
- }
- if (g == null || h == null) {
- throw new IllegalArgumentException("Left and right UnaryFunctions may not be null");
- }
- this.helper = new Helper<G, H, L, R, T>(f, g, h);
+ this.helper = new Helper<G, H, L, R, T>(
+ Validate.notNull(f, "BinaryFunction must not be null"),
+ Validate.notNull(g, "left UnaryFunction must not be null"),
+ Validate.notNull(h, "right UnaryFunction must not be null")
+ );
}
// function interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryPredicate.java b/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryPredicate.java
index 3905dec..f2fce42 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryPredicate.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryPredicate.java
@@ -20,6 +20,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate BinaryPredicate} composed of
@@ -116,13 +117,11 @@
*/
public <G, H> UnaryCompositeBinaryPredicate(final BinaryPredicate<? super G, ? super H> f,
final UnaryFunction<? super L, ? extends G> g, final UnaryFunction<? super R, ? extends H> h) {
- if (f == null) {
- throw new IllegalArgumentException("BinaryPredicate must not be null");
- }
- if (g == null || h == null) {
- throw new IllegalArgumentException("Left and right UnaryFunctions may not be null");
- }
- helper = new Helper<G, H, L, R>(f, g, h);
+ helper = new Helper<G, H, L, R>(
+ Validate.notNull(f, "BinaryPredicate must not be null"),
+ Validate.notNull(g, "left UnaryFunction must not be null"),
+ Validate.notNull(h, "right UnaryFunction must not be null")
+ );
}
// function interface
diff --git a/src/main/java/org/apache/commons/functor/core/composite/UnaryNot.java b/src/main/java/org/apache/commons/functor/core/composite/UnaryNot.java
index 57f700f..a28e7c6 100644
--- a/src/main/java/org/apache/commons/functor/core/composite/UnaryNot.java
+++ b/src/main/java/org/apache/commons/functor/core/composite/UnaryNot.java
@@ -19,6 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.lang3.Validate;
/**
* {@link #test Tests} to the logical inverse
@@ -54,10 +55,7 @@
* @param predicate UnaryPredicate to negate
*/
public UnaryNot(UnaryPredicate<? super A> predicate) {
- if (predicate == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.predicate = predicate;
+ this.predicate = Validate.notNull(predicate, "UnaryPredicate argument was null");
}
// predicate interface
diff --git a/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java b/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java
index f835f76..4203c5e 100644
--- a/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java
+++ b/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java
@@ -19,6 +19,7 @@
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
import org.apache.commons.functor.core.composite.ConditionalUnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Generator that filters another Generator by only passing through those elements
@@ -40,14 +41,8 @@
* @param pred filtering UnaryPredicate
*/
public FilteredGenerator(Generator<? extends E> wrapped, UnaryPredicate<? super E> pred) {
- super(wrapped);
- if (wrapped == null) {
- throw new IllegalArgumentException("Generator argument was null");
- }
- if (pred == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.pred = pred;
+ super(Validate.notNull(wrapped, "Generator argument was null"));
+ this.pred = Validate.notNull(pred, "UnaryPredicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java b/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
index 4086b3b..d031821 100644
--- a/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
+++ b/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
@@ -18,6 +18,7 @@
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Wrap another {@link Generator} such that {@link #run(UnaryProcedure)} terminates once
@@ -39,14 +40,8 @@
* @param test {@link UnaryPredicate}
*/
public GenerateUntil(Generator<? extends E> wrapped, UnaryPredicate<? super E> test) {
- super(wrapped);
- if (wrapped == null) {
- throw new IllegalArgumentException("Generator argument was null");
- }
- if (test == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.test = test;
+ super(Validate.notNull(wrapped, "Generator argument was null"));
+ this.test = Validate.notNull(test, "UnaryPredicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java b/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
index c6cad23..6c0a84d 100644
--- a/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
+++ b/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
@@ -18,6 +18,7 @@
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Wrap another {@link Generator} such that {@link #run(UnaryProcedure)} continues
@@ -39,14 +40,8 @@
* @param test {@link UnaryPredicate}
*/
public GenerateWhile(Generator<? extends E> wrapped, UnaryPredicate<? super E> test) {
- super(wrapped);
- if (wrapped == null) {
- throw new IllegalArgumentException("Generator argument was null");
- }
- if (test == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.test = test;
+ super(Validate.notNull(wrapped, "Generator argument was null"));
+ this.test = Validate.notNull(test, "UnaryPredicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java b/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java
index f1a0a30..f3f2a7c 100644
--- a/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java
+++ b/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java
@@ -15,6 +15,7 @@
package org.apache.commons.functor.generator;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
import java.util.Iterator;
@@ -43,10 +44,7 @@
* @param iter Iterator to adapt
*/
public IteratorToGeneratorAdapter(Iterator<? extends E> iter) {
- if (null == iter) {
- throw new IllegalArgumentException("Iterator argument was null");
- }
- this.iter = iter;
+ this.iter = Validate.notNull(iter, "Iterator argument was null");
}
// instance methods
diff --git a/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java b/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
index bc81492..0b1aeb6 100644
--- a/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
+++ b/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
@@ -18,6 +18,7 @@
import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Generator that transforms the elements of another Generator.
@@ -39,14 +40,8 @@
* @param func UnaryFunction to apply to each element
*/
public TransformedGenerator(Generator<? extends I> wrapped, UnaryFunction<? super I, ? extends E> func) {
- super(wrapped);
- if (wrapped == null) {
- throw new IllegalArgumentException("Generator argument was null");
- }
- if (func == null) {
- throw new IllegalArgumentException("UnaryFunction argument was null");
- }
- this.func = func;
+ super(Validate.notNull(wrapped, "Generator argument was null"));
+ this.func = Validate.notNull(func, "UnaryFunction argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java b/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
index e4daf55..6c2fdc8 100644
--- a/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
+++ b/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
@@ -18,6 +18,7 @@
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Wrap another {@link Generator} such that {@link #run(UnaryProcedure)} terminates once
@@ -39,14 +40,8 @@
* @param test {@link UnaryPredicate}
*/
public UntilGenerate(UnaryPredicate<? super E> test, Generator<? extends E> wrapped) {
- super(wrapped);
- if (wrapped == null) {
- throw new IllegalArgumentException("Generator argument was null");
- }
- if (test == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.test = test;
+ super(Validate.notNull(wrapped, "Generator argument was null"));
+ this.test = Validate.notNull(test, "UnaryPredicate argument was null");
}
/**
diff --git a/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java b/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
index 8ecbd04..f50411e 100644
--- a/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
+++ b/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
@@ -18,6 +18,7 @@
import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.lang3.Validate;
/**
* Wrap another {@link Generator} such that {@link #run(UnaryProcedure)} continues
@@ -39,14 +40,8 @@
* @param wrapped {@link Generator}
*/
public WhileGenerate(UnaryPredicate<? super E> test, Generator<? extends E> wrapped) {
- super(wrapped);
- if (wrapped == null) {
- throw new IllegalArgumentException("Generator argument was null");
- }
- if (test == null) {
- throw new IllegalArgumentException("UnaryPredicate argument was null");
- }
- this.test = test;
+ super(Validate.notNull(wrapped, "Generator argument was null"));
+ this.test = Validate.notNull(test,"UnaryPredicate argument was null");
}
/**
diff --git a/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java b/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java
index 4f89bb3..8569466 100644
--- a/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java
+++ b/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java
@@ -218,28 +218,20 @@
assertSame(iter,FilteredIterator.filter(iter,null));
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testConstructorProhibitsNull() {
- try {
- new FilteredIterator(null,null);
- fail("ExpectedNullPointerException");
- } catch(IllegalArgumentException e) {
- // expected
- }
- try {
- new FilteredIterator(null,Constant.truePredicate());
- fail("ExpectedNullPointerException");
- } catch(IllegalArgumentException e) {
- // expected
- }
- try {
- new FilteredIterator(list.iterator(),null);
- fail("ExpectedNullPointerException");
- } catch(IllegalArgumentException e) {
- // expected
- }
+ new FilteredIterator(null,null);
}
+ @Test(expected = NullPointerException.class)
+ public void testConstructorProhibitsNull2() {
+ new FilteredIterator(null,Constant.truePredicate());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testConstructorProhibitsNull3() {
+ new FilteredIterator(list.iterator(),null);
+ }
// Attributes
// ------------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java b/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java
index 6b966bd..2fded3c 100644
--- a/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java
+++ b/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java
@@ -103,14 +103,9 @@
}
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testTestNull() {
- try {
- IsElementOf.instance().test(new Integer(5),null);
- fail("expected IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ IsElementOf.instance().test(new Integer(5),null);
}
@Test
diff --git a/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java b/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java
index a190790..e9fe772 100644
--- a/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java
+++ b/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java
@@ -68,14 +68,9 @@
}
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testTestNull() throws Exception {
- try {
- IsEmpty.instance().test(null);
- fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) {
- // expected
- }
+ IsEmpty.instance().test(null);
}
@Test
diff --git a/src/test/java/org/apache/commons/functor/core/collection/TestSize.java b/src/test/java/org/apache/commons/functor/core/collection/TestSize.java
index 8e1e471..4fd3215 100644
--- a/src/test/java/org/apache/commons/functor/core/collection/TestSize.java
+++ b/src/test/java/org/apache/commons/functor/core/collection/TestSize.java
@@ -73,14 +73,9 @@
}
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testEvaluateNull() throws Exception {
- try {
- Size.instance().evaluate(null);
- fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) {
- // expected
- }
+ Size.instance().evaluate(null);
}
@Test
diff --git a/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java b/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
index e445188..5dbb689 100644
--- a/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
+++ b/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
@@ -178,28 +178,20 @@
assertSame(iter,TransformedIterator.maybeTransform(iter,null));
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testConstructorProhibitsNull() {
- try {
- new TransformedIterator<Integer, Integer>(null,null);
- fail("ExpectedNullPointerException");
- } catch(IllegalArgumentException e) {
- // expected
- }
- try {
- new TransformedIterator<Integer, Integer>(null,negate);
- fail("ExpectedNullPointerException");
- } catch(IllegalArgumentException e) {
- // expected
- }
- try {
- new TransformedIterator<Integer, Integer>(list.iterator(),null);
- fail("ExpectedNullPointerException");
- } catch(IllegalArgumentException e) {
- // expected
- }
+ new TransformedIterator<Integer, Integer>(null, null);
}
+ @Test(expected = NullPointerException.class)
+ public void testConstructorProhibitsNull2() {
+ new TransformedIterator<Integer, Integer>(null, negate);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testConstructorProhibitsNull3() {
+ new TransformedIterator<Integer, Integer>(list.iterator(), null);
+ }
// Attributes
// ------------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java b/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java
index b6dc115..f7ee342 100644
--- a/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java
+++ b/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java
@@ -56,25 +56,14 @@
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testInvalidRange() {
- try {
- new IsWithinRange<Integer>(new Integer(5), new Integer(4));
- fail("should have thrown IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // good
- } catch (Exception e) {
- fail("should have thrown IllegalArgumentException, not " + e);
- }
+ new IsWithinRange<Integer>(new Integer(5), new Integer(4));
+ }
- try {
- new IsWithinRange<Integer>(new Integer(5), null);
- fail("should have thrown IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // good
- } catch (Exception e) {
- fail("should have thrown IllegalArgumentException, not " + e);
- }
+ @Test(expected = NullPointerException.class)
+ public void testInvalidRange2() {
+ new IsWithinRange<Integer>(new Integer(5), null);
}
@Test
diff --git a/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryPredicate.java b/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryPredicate.java
index 64f3057..ea26b4b 100644
--- a/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryPredicate.java
+++ b/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryPredicate.java
@@ -49,21 +49,15 @@
assertFalse(Composite.predicate(Constant.FALSE, Constant.of(4)).test("xyzzy"));
}
- @Test
- @SuppressWarnings("unchecked")
+ @Test(expected = NullPointerException.class)
+ @SuppressWarnings({ "unchecked", "rawtypes" })
public void testNullNotAllowed() throws Exception {
- try {
- new CompositeUnaryPredicate(null);
- fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) {
- // expected
- }
- try {
- Composite.function(Constant.TRUE, null);
- fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) {
- // expected
- }
+ new CompositeUnaryPredicate(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testNullNotAllowed2() throws Exception {
+ Composite.function(Constant.TRUE, null);
}
@Test
diff --git a/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java b/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java
index 5806755..44d400d 100644
--- a/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java
+++ b/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java
@@ -84,14 +84,9 @@
assertEquals(list,list2);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testConstructNull() {
- try {
- new IteratorToGeneratorAdapter(null);
- fail("Expected NullPointerException");
- } catch(IllegalArgumentException e) {
- // expected
- }
+ new IteratorToGeneratorAdapter(null);
}
@Test