diff --git a/README.md b/README.md
index 21b312509..6ef44812f 100644
--- a/README.md
+++ b/README.md
@@ -30,14 +30,24 @@ To get started, add this Maven dependency:
Designed for discovery using your favorite IDE's auto-complete feature.
The main entry points are:
-* [requireThat(value, name)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/DefaultJavaValidators.html#requireThat(T,java.lang.String)) for preconditions
-* [assumeThat(value, name)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/DefaultJavaValidators.html#assumeThat(T,java.lang.String)) for postconditions and class invariants
-* [checkIfThat(value, name)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/DefaultJavaValidators.html#checkIf(T,java.lang.String)) for multiple failures and everything else
-* [JavaValidators](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/JavaValidators.html) for custom configurations
+* [requireThat(value, name)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/java/DefaultJavaValidators.html#requireThat(T,java.lang.String)) for method preconditions.
+* [assumeThat(value, name)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/java/DefaultJavaValidators.html#assumeThat(T,java.lang.String)) for class invariants, method postconditions and private methods.
+* [checkIfThat(value, name)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/java/DefaultJavaValidators.html#checkIf(T,java.lang.String)) for multiple failures and customized error handling.
+* [JavaValidators](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/java/JavaValidators.html) for custom configurations.
The first three methods use a shared configuration, while `JavaValidators` allows you to create an independent
configuration.
+`requireThat()` and `assumeThat()` throw an exception on the first validation failure,
+while `checkIf()` collects multiple validation failures before throwing an exception at the end.
+`checkIf()` is more flexible than the others, but its syntax is more verbose.
+
+Exceptions that are thrown in response to invalid method arguments (e.g. `isGreaterThan(null, value)`) are
+thrown by all validators and cannot be configured. Exceptions that are thrown in response to the value
+failing a validation check, e.g. `isGreaterThan(5)` on a value of 0, are thrown by `requireThat()` and
+`assumeThat()` but are recorded by `checkIf()` without being thrown. The type of thrown exceptions is
+configurable using [ConfigurationUpdater#exceptionTransformer(Function)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/java/ConfigurationUpdater.html#exceptionTransformer(java.util.function.Function)).
+
See the [API documentation](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/) for more details.
## Usage Example
@@ -105,31 +115,13 @@ This library offers the following features:
* [String diff](docs/Features.md#string-diff) that shows the differences between two strings
* [Performant and robust](docs/Performance.md)
-## Getting Started
-
-The best way to learn about the API is using your IDE's auto-complete engine.
-The main entry points you should be aware of are:
-
-* [requireThat(value, name)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/DefaultJavaValidators.html#requireThat(T,java.lang.String))
-* [assumeThat(value, name)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/DefaultJavaValidators.html#assumeThat(T,java.lang.String))
-* [checkIfThat(value, name)](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/DefaultJavaValidators.html#checkIf(T,java.lang.String))
-
-The three static methods share the same configuration.
-To create an independent configuration, use [JavaValidators](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/com.github.cowwoc.requirements/com/github/cowwoc/requirements/JavaValidators.html).
-
-See the [API documentation](https://cowwoc.github.io/requirements.java/9.0.0/docs/api/) for more details.
+## Tips
-## Best practices
-
-* Use `requireThat()` to verify the preconditions of public APIs.
-* Use `assert assumeThat()` to verify class invariants, method post-conditions, and the preconditions of
- private methods.
- The JVM will remove these checks if assertions are disabled.
-* Use `checkIf()` to return multiple failures at once.
-* Use `checkIf().elseGetMessages()` to return failures without throwing an exception.
- This is the best-performing approach, ideal for web services.
-* To enhance the clarity of failure messages, you should provide parameter names, even though they are
- optional.
+* Use `assert` with `assumeThat().elseThrow()` for sanity checks. When assertions are disabled, they will get
+ disabled.
+* Use `checkIf().elseGetMessages()` to return failure messages without throwing an exception.
+ This is the fastest validation approach, ideal for web services.
+* To enhance the clarity of failure messages, you should provide parameter names, even when they are optional.
## Third-party libraries and tools
diff --git a/docs/Changelog.md b/docs/Changelog.md
index aba5e1d9c..a7dca1a41 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -28,6 +28,7 @@ See https://github.com/cowwoc/requirements.java/commits/master for a full list.
14. Dropped the `isOneOf()` and `isNotOneOf()` functionality yet again. I haven't figured out a good
design for this yet.
15. Added `ObjectValidator.isX()` methods to downcast to known types.
+ 16. Replaced thread context with `Validators.getContext()`, `putContext()`, `removeContext()`.
* Bugfixes:
* `StringValidator/Verifier.asShort()`, `asInteger()` and `asLong()` were not handling the case where a
string could not be converted to a number.
diff --git a/guava/src/main/java/com/github/cowwoc/requirements/guava/DefaultGuavaValidators.java b/guava/src/main/java/com/github/cowwoc/requirements/guava/DefaultGuavaValidators.java
index 0bdff7c87..13444aaa6 100644
--- a/guava/src/main/java/com/github/cowwoc/requirements/guava/DefaultGuavaValidators.java
+++ b/guava/src/main/java/com/github/cowwoc/requirements/guava/DefaultGuavaValidators.java
@@ -9,11 +9,13 @@
import com.github.cowwoc.requirements.java.Configuration;
import com.github.cowwoc.requirements.java.ConfigurationUpdater;
import com.github.cowwoc.requirements.java.GlobalConfiguration;
-import com.github.cowwoc.requirements.java.ScopedContext;
import com.github.cowwoc.requirements.java.internal.scope.MainApplicationScope;
+import com.github.cowwoc.requirements.java.internal.util.CloseableLock;
+import com.github.cowwoc.requirements.java.internal.util.ReentrantStampedLock;
import com.github.cowwoc.requirements.java.type.part.Validator;
import com.google.common.collect.Multimap;
+import java.util.Map;
import java.util.function.Function;
/**
@@ -36,6 +38,8 @@
* of 0, are thrown by {@code requireThat()} and {@code assumeThat()} but are recorded by {@code checkIf()}
* without being thrown. The type of thrown exceptions is configurable using
* {@link ConfigurationUpdater#exceptionTransformer(Function)}.
+ *
+ * Thread Safety : This class is thread-safe.
*
* @see GuavaValidators#newInstance() Creating a new instance with an independent configuration
*/
@@ -43,6 +47,7 @@ public final class DefaultGuavaValidators
{
private static final GuavaValidatorsImpl delegate = new GuavaValidatorsImpl(MainApplicationScope.INSTANCE,
Configuration.DEFAULT);
+ private static final ReentrantStampedLock contextLock = new ReentrantStampedLock();
/**
* Validates the state of a {@code Multimap}. Any exceptions thrown due to validation failure are
@@ -54,7 +59,7 @@ public final class DefaultGuavaValidators
* @param value the value
* @param name the name of the value
* @return a validator for the value
- * @throws NullPointerException if {@code name} is null
+ * @throws NullPointerException if any of the mandatory arguments are null
* @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
*/
public static > MultimapValidator assumeThat(T value, String name)
@@ -86,7 +91,7 @@ public static > MultimapValidator assume
* @param value the value
* @param name the name of the value
* @return a validator for the value
- * @throws NullPointerException if {@code name} is null
+ * @throws NullPointerException if any of the mandatory arguments are null
* @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
*/
public static > MultimapValidator checkIf(T value, String name)
@@ -117,7 +122,7 @@ public static > MultimapValidator checkI
* @param value the value
* @param name the name of the value
* @return a validator for the value
- * @throws NullPointerException if {@code name} is null
+ * @throws NullPointerException if any of the mandatory arguments are null
* @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
*/
public static > MultimapValidator requireThat(T value, String name)
@@ -150,26 +155,56 @@ public static ConfigurationUpdater updateConfiguration()
}
/**
- * Returns the contextual information for validations performed by this thread using any validator. The
- * contextual information is a map of key-value pairs that can provide more details about validation
- * failures. For example, if the message is "Password may not be empty" and the map contains the key-value
- * pair {@code {"username": "john.smith"}}, the exception message would be:
+ * Returns the contextual information for validators created out by this factory. The contextual information
+ * is a map of key-value pairs that can provide more details about validation failures. For example, if the
+ * message is "Password may not be empty" and the map contains the key-value pair
+ * {@code {"username": "john.smith"}}, the exception message would be:
*
* {@snippet lang = output:
* Password may not be empty
* username: john.smith}
+ *
+ * @return an unmodifiable map from each entry's name to its value
+ */
+ public static Map getContext()
+ {
+ return contextLock.optimisticRead(delegate::getContext);
+ }
+
+ /**
+ * Sets the contextual information for validators created by this factory.
*
- * Values set by this method may be overridden by {@link Validator#putContext(Object, String)}}.
- *
- * NOTE : This method affects existing and new validators used by current thread. Changes are
- * reversed once {@link ScopedContext#close()} is invoked.
+ * This method adds contextual information to exception messages. The contextual information is stored as
+ * key-value pairs in a map. Values set by this method may be overridden by
+ * {@link Validator#putContext(Object, String)}}.
*
- * @return the thread context updater
+ * @param value the value of the entry
+ * @param name the name of an entry
+ * @return the underlying validator factory
+ * @throws NullPointerException if {@code name} is null
*/
- @CheckReturnValue
- public static ScopedContext threadContext()
+ public static GuavaValidators putContext(Object value, String name)
+ {
+ try (CloseableLock unused = contextLock.write())
+ {
+ return delegate.putContext(value, name);
+ }
+ }
+
+ /**
+ * Removes the contextual information of validators created by this factory.
+ *
+ * @param name the parameter name
+ * @return the underlying validator factory
+ * @throws NullPointerException if {@code name} is null
+ * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
+ */
+ public static GuavaValidators removeContext(String name)
{
- return delegate.threadContext();
+ try (CloseableLock unused = contextLock.write())
+ {
+ return delegate.removeContext(name);
+ }
}
/**
diff --git a/guava/src/main/java/com/github/cowwoc/requirements/guava/GuavaValidators.java b/guava/src/main/java/com/github/cowwoc/requirements/guava/GuavaValidators.java
index 9a45a2e8d..8427199b6 100644
--- a/guava/src/main/java/com/github/cowwoc/requirements/guava/GuavaValidators.java
+++ b/guava/src/main/java/com/github/cowwoc/requirements/guava/GuavaValidators.java
@@ -4,6 +4,7 @@
*/
package com.github.cowwoc.requirements.guava;
+import com.github.cowwoc.requirements.annotation.CheckReturnValue;
import com.github.cowwoc.requirements.guava.internal.implementation.GuavaValidatorsImpl;
import com.github.cowwoc.requirements.java.Configuration;
import com.github.cowwoc.requirements.java.ConfigurationUpdater;
@@ -27,13 +28,14 @@
* {@code checkIf()} is more flexible than the others, but its syntax is more verbose.
*
* Exceptions that are thrown in response to invalid method arguments (e.g.
- * {@code isGreaterThan(null, value)} are thrown by all validators and cannot be configured. Exceptions that
+ * {@code isGreaterThan(null, value)}) are thrown by all validators and cannot be configured. Exceptions that
* are thrown in response to the value failing a validation check, e.g. {@code isGreaterThan(5)} on a value
* of 0, are thrown by {@code requireThat()} and {@code assumeThat()} but are recorded by {@code checkIf()}
* without being thrown. The type of thrown exceptions is configurable using
* {@link ConfigurationUpdater#exceptionTransformer(Function)}.
*/
-public interface GuavaValidators extends Validators, GuavaRequireThat, GuavaAssumeThat, GuavaCheckIf
+public interface GuavaValidators
+ extends Validators, GuavaRequireThat, GuavaAssumeThat, GuavaCheckIf
{
/**
* Creates a new instance using the default configuration.
@@ -57,4 +59,20 @@ static GuavaValidators newInstance(Configuration configuration)
{
return new GuavaValidatorsImpl(MainApplicationScope.INSTANCE, configuration);
}
+
+ /**
+ * Returns a new factory instance with an independent configuration. This method is commonly used to inherit
+ * and update contextual information from the original factory before passing it into a nested operation.
+ * For example:
+ *
+ * {@snippet :
+ * GuavaValidators copy = validators.copy();
+ * copy.context().put(json.toString(), "json");
+ * nestedOperation(copy);
+ *}
+ *
+ * @return a copy of this factory
+ */
+ @CheckReturnValue
+ GuavaValidators copy();
}
\ No newline at end of file
diff --git a/guava/src/main/java/com/github/cowwoc/requirements/guava/internal/implementation/GuavaValidatorsImpl.java b/guava/src/main/java/com/github/cowwoc/requirements/guava/internal/implementation/GuavaValidatorsImpl.java
index d364d4934..027d3a0ab 100644
--- a/guava/src/main/java/com/github/cowwoc/requirements/guava/internal/implementation/GuavaValidatorsImpl.java
+++ b/guava/src/main/java/com/github/cowwoc/requirements/guava/internal/implementation/GuavaValidatorsImpl.java
@@ -3,12 +3,18 @@
import com.github.cowwoc.requirements.guava.GuavaValidators;
import com.github.cowwoc.requirements.guava.MultimapValidator;
import com.github.cowwoc.requirements.java.Configuration;
+import com.github.cowwoc.requirements.java.ValidationFailure;
import com.github.cowwoc.requirements.java.internal.implementation.AbstractValidator;
import com.github.cowwoc.requirements.java.internal.implementation.AbstractValidators;
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.google.common.collect.Multimap;
-public class GuavaValidatorsImpl extends AbstractValidators
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class GuavaValidatorsImpl extends AbstractValidators
implements GuavaValidators
{
/**
@@ -23,10 +29,22 @@ public GuavaValidatorsImpl(ApplicationScope scope, Configuration configuration)
super(scope, configuration);
}
+ /**
+ * Creates a copy of an existing validator factory.
+ *
+ * @param other the factory to copy
+ * @throws NullPointerException if {@code other} is null
+ */
+ public GuavaValidatorsImpl(GuavaValidatorsImpl other)
+ {
+ this(other.scope, other.configuration());
+ this.context.putAll(other.context);
+ }
+
@Override
public > MultimapValidator requireThat(T value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
@@ -56,6 +74,39 @@ public > MultimapValidator checkIf(T val
private > MultimapValidator newInstance(T value, String name,
Configuration configuration)
{
- return new MultimapValidatorImpl<>(scope, configuration, name, value);
+ return new MultimapValidatorImpl<>(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
+ }
+
+ private Map newValidatorContext()
+ {
+ HashMap context = HashMap.newHashMap(this.context.size() + 2);
+ context.putAll(this.context);
+ return context;
+ }
+
+ private List newValidatorFailures()
+ {
+ return new ArrayList<>(2);
+ }
+
+ @Override
+ public GuavaValidatorsImpl copy()
+ {
+ return new GuavaValidatorsImpl(this);
+ }
+
+ @Override
+ public GuavaValidatorsImpl putContext(Object value, String name)
+ {
+ context.put(name, value);
+ return this;
+ }
+
+ @Override
+ public GuavaValidatorsImpl removeContext(String name)
+ {
+ context.remove(name);
+ return this;
}
}
\ No newline at end of file
diff --git a/guava/src/main/java/com/github/cowwoc/requirements/guava/internal/implementation/MultimapValidatorImpl.java b/guava/src/main/java/com/github/cowwoc/requirements/guava/internal/implementation/MultimapValidatorImpl.java
index b5f15aa73..425a37eae 100644
--- a/guava/src/main/java/com/github/cowwoc/requirements/guava/internal/implementation/MultimapValidatorImpl.java
+++ b/guava/src/main/java/com/github/cowwoc/requirements/guava/internal/implementation/MultimapValidatorImpl.java
@@ -8,7 +8,6 @@
import com.github.cowwoc.requirements.java.Configuration;
import com.github.cowwoc.requirements.java.ValidationFailure;
import com.github.cowwoc.requirements.java.internal.implementation.AbstractObjectValidator;
-import com.github.cowwoc.requirements.java.internal.implementation.AbstractValidator;
import com.github.cowwoc.requirements.java.internal.implementation.CollectionValidatorImpl;
import com.github.cowwoc.requirements.java.internal.implementation.PrimitiveUnsignedIntegerValidatorImpl;
import com.github.cowwoc.requirements.java.internal.implementation.message.CollectionMessages;
@@ -19,9 +18,7 @@
import com.github.cowwoc.requirements.java.type.PrimitiveUnsignedIntegerValidator;
import com.google.common.collect.Multimap;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -35,41 +32,6 @@ public final class MultimapValidatorImpl>
extends AbstractObjectValidator, T>
implements MultimapValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public MultimapValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name, T value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public MultimapValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value)
- {
- this(scope, configuration, name, value, new HashMap<>(), new ArrayList<>());
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -77,13 +39,13 @@ public MultimapValidatorImpl(ApplicationScope scope, Configuration configuration
* @param value (optional) the value
* @param context the contextual information set by the user
* @param failures the list of validation failures
- * @throws NullPointerException if {@code name} is null
+ * @throws NullPointerException if any of the mandatory arguments are null
* @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private MultimapValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value, Map context, List failures)
+ public MultimapValidatorImpl(ApplicationScope scope, Configuration configuration, String name, T value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
@@ -145,18 +107,18 @@ public PrimitiveUnsignedIntegerValidator size()
{
if (hasFailed())
{
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".size()", 0,
- null, Pluralizer.ENTRY);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".size()", 0,
+ name, null, Pluralizer.ENTRY, context, failures);
}
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".size()", 0,
- null, Pluralizer.ENTRY);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".size()", 0,
+ name, null, Pluralizer.ENTRY, context, failures);
}
PrimitiveUnsignedIntegerValidatorImpl newValidator = new PrimitiveUnsignedIntegerValidatorImpl(scope,
- this, name + ".size()", value.size(), value, Pluralizer.ENTRY);
+ configuration, name + ".size()", value.size(), name, value, Pluralizer.ENTRY, context, failures);
newValidator.putContext(value, name);
return newValidator;
}
@@ -165,18 +127,24 @@ public PrimitiveUnsignedIntegerValidator size()
public CollectionValidator> keySet()
{
if (hasFailed() || value == null)
- return new CollectionValidatorImpl<>(scope, this, name + ".keySet()", null, Pluralizer.KEY);
+ {
+ return new CollectionValidatorImpl<>(scope, configuration,
+ name + ".keySet()", null, Pluralizer.KEY, context, failures);
+ }
return new CollectionValidatorImpl<>(scope, configuration, name + ".keySet()", value.keySet(),
- Pluralizer.KEY);
+ Pluralizer.KEY, context, failures);
}
@Override
public CollectionValidator> values()
{
if (hasFailed() || value == null)
- return new CollectionValidatorImpl<>(scope, configuration, name + ".values()", null, Pluralizer.VALUE);
+ {
+ return new CollectionValidatorImpl<>(scope, configuration,
+ name + ".values()", null, Pluralizer.VALUE, context, failures);
+ }
return new CollectionValidatorImpl<>(scope, configuration, name + ".values()", value.values(),
- Pluralizer.VALUE);
+ Pluralizer.VALUE, context, failures);
}
@Override
@@ -185,9 +153,9 @@ public CollectionValidator, Collection>> entries()
if (hasFailed() || value == null)
{
return new CollectionValidatorImpl<>(scope, configuration, name + ".entries()", null,
- Pluralizer.ENTRY);
+ Pluralizer.ENTRY, context, failures);
}
return new CollectionValidatorImpl<>(scope, configuration, name + ".entries()", value.entries(),
- Pluralizer.ENTRY);
+ Pluralizer.ENTRY, context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/DefaultJavaValidators.java b/java/src/main/java/com/github/cowwoc/requirements/java/DefaultJavaValidators.java
index 53bcd481c..e87cf7f5d 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/DefaultJavaValidators.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/DefaultJavaValidators.java
@@ -7,6 +7,8 @@
import com.github.cowwoc.requirements.annotation.CheckReturnValue;
import com.github.cowwoc.requirements.java.internal.implementation.JavaValidatorsImpl;
import com.github.cowwoc.requirements.java.internal.scope.MainApplicationScope;
+import com.github.cowwoc.requirements.java.internal.util.CloseableLock;
+import com.github.cowwoc.requirements.java.internal.util.ReentrantStampedLock;
import com.github.cowwoc.requirements.java.type.BigDecimalValidator;
import com.github.cowwoc.requirements.java.type.BigIntegerValidator;
import com.github.cowwoc.requirements.java.type.BooleanValidator;
@@ -75,11 +77,13 @@
* {@code checkIf()} is more flexible than the others, but its syntax is more verbose.
*
* Exceptions that are thrown in response to invalid method arguments (e.g.
- * {@code isGreaterThan(null, value)} are thrown by all validators and cannot be configured. Exceptions that
+ * {@code isGreaterThan(null, value)}) are thrown by all validators and cannot be configured. Exceptions that
* are thrown in response to the value failing a validation check, e.g. {@code isGreaterThan(5)} on a value
* of 0, are thrown by {@code requireThat()} and {@code assumeThat()} but are recorded by {@code checkIf()}
* without being thrown. The type of thrown exceptions is configurable using
* {@link ConfigurationUpdater#exceptionTransformer(Function)}.
+ *
+ * Thread Safety : This class is thread-safe.
*
* @see JavaValidators#newInstance() Creating an independent configuration
*/
@@ -87,6 +91,7 @@ public final class DefaultJavaValidators
{
private static final JavaValidatorsImpl delegate = new JavaValidatorsImpl(MainApplicationScope.INSTANCE,
Configuration.DEFAULT);
+ private static final ReentrantStampedLock contextLock = new ReentrantStampedLock();
private DefaultJavaValidators()
{
@@ -2748,26 +2753,56 @@ public static ConfigurationUpdater updateConfiguration()
}
/**
- * Returns the contextual information for validations performed by this thread using any validator. The
- * contextual information is a map of key-value pairs that can provide more details about validation
- * failures. For example, if the message is "Password may not be empty" and the map contains the key-value
- * pair {@code {"username": "john.smith"}}, the exception message would be:
+ * Returns the contextual information for validators created out by this factory. The contextual information
+ * is a map of key-value pairs that can provide more details about validation failures. For example, if the
+ * message is "Password may not be empty" and the map contains the key-value pair
+ * {@code {"username": "john.smith"}}, the exception message would be:
*
* {@snippet lang = output:
* Password may not be empty
* username: john.smith}
+ *
+ * @return an unmodifiable map from each entry's name to its value
+ */
+ public static Map getContext()
+ {
+ return contextLock.optimisticRead(delegate::getContext);
+ }
+
+ /**
+ * Sets the contextual information for validators created by this factory.
*
- * Values set by this method may be overridden by {@link Validator#putContext(Object, String)}}.
- *
- * NOTE : This method affects existing and new validators used by current thread. Changes are
- * reversed once {@link ScopedContext#close()} is invoked.
+ * This method adds contextual information to exception messages. The contextual information is stored as
+ * key-value pairs in a map. Values set by this method may be overridden by
+ * {@link Validator#putContext(Object, String)}}.
*
- * @return the thread context updater
+ * @param value the value of the entry
+ * @param name the name of an entry
+ * @return the underlying validator factory
+ * @throws NullPointerException if {@code name} is null
*/
- @CheckReturnValue
- public static ScopedContext threadContext()
+ public static JavaValidators putContext(Object value, String name)
+ {
+ try (CloseableLock unused = contextLock.write())
+ {
+ return delegate.putContext(value, name);
+ }
+ }
+
+ /**
+ * Removes the contextual information of validators created by this factory.
+ *
+ * @param name the parameter name
+ * @return the underlying validator factory
+ * @throws NullPointerException if {@code name} is null
+ * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
+ */
+ public static JavaValidators removeContext(String name)
{
- return delegate.threadContext();
+ try (CloseableLock unused = contextLock.write())
+ {
+ return delegate.removeContext(name);
+ }
}
/**
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/JavaValidators.java b/java/src/main/java/com/github/cowwoc/requirements/java/JavaValidators.java
index 2acf9ace9..7b621d032 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/JavaValidators.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/JavaValidators.java
@@ -4,6 +4,7 @@
*/
package com.github.cowwoc.requirements.java;
+import com.github.cowwoc.requirements.annotation.CheckReturnValue;
import com.github.cowwoc.requirements.java.internal.implementation.JavaValidatorsImpl;
import com.github.cowwoc.requirements.java.internal.scope.MainApplicationScope;
@@ -24,13 +25,14 @@
* {@code checkIf()} is more flexible than the others, but its syntax is more verbose.
*
* Exceptions that are thrown in response to invalid method arguments (e.g.
- * {@code isGreaterThan(null, value)} are thrown by all validators and cannot be configured. Exceptions that
+ * {@code isGreaterThan(null, value)}) are thrown by all validators and cannot be configured. Exceptions that
* are thrown in response to the value failing a validation check, e.g. {@code isGreaterThan(5)} on a value
* of 0, are thrown by {@code requireThat()} and {@code assumeThat()} but are recorded by {@code checkIf()}
* without being thrown. The type of thrown exceptions is configurable using
* {@link ConfigurationUpdater#exceptionTransformer(Function)}.
*/
-public interface JavaValidators extends Validators, JavaRequireThat, JavaAssumeThat, JavaCheckIf
+public interface JavaValidators
+ extends Validators, JavaRequireThat, JavaAssumeThat, JavaCheckIf
{
/**
* Creates a new instance using the default configuration.
@@ -54,4 +56,20 @@ static JavaValidators newInstance(Configuration configuration)
{
return new JavaValidatorsImpl(MainApplicationScope.INSTANCE, configuration);
}
+
+ /**
+ * Returns a new factory instance with an independent configuration. This method is commonly used to inherit
+ * and update contextual information from the original factory before passing it into a nested operation.
+ * For example:
+ *
+ * {@snippet :
+ * JavaValidators copy = validators.copy();
+ * copy.context().put(json.toString(), "json");
+ * nestedOperation(copy);
+ *}
+ *
+ * @return a copy of this factory
+ */
+ @CheckReturnValue
+ JavaValidators copy();
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/ScopedContext.java b/java/src/main/java/com/github/cowwoc/requirements/java/ScopedContext.java
deleted file mode 100644
index c92ef7dc2..000000000
--- a/java/src/main/java/com/github/cowwoc/requirements/java/ScopedContext.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.github.cowwoc.requirements.java;
-
-/**
- * Contextual information that is accessible only within the scope's duration, from creation to
- * {@link #close()}.
- */
-public interface ScopedContext extends AutoCloseable
-{
- /**
- * Looks up contextual information by its name.
- *
- * To check if a parameter exists or has a {@code null} value, use {@link #containsName(String)}.
- *
- * @param name the parameter name
- * @return the value of the parameter or {@code null} if no match was found
- */
- Object get(String name);
-
- /**
- * Returns {@code true} if a parameter exists.
- *
- * @param name the parameter name
- * @return {@code true} if the parameter exists
- */
- boolean containsName(String name);
-
- /**
- * Adds or updates contextual information.
- *
- * @param value the parameter value
- * @param name the parameter name
- * @return this
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- */
- ScopedContext put(Object value, String name);
-
- /**
- * Removes contextual information.
- *
- * @param name the parameter name
- * @return this
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- */
- ScopedContext remove(String name);
-
- /**
- * Reverses any changes applied to the context.
- */
- @Override
- void close();
-}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/Validators.java b/java/src/main/java/com/github/cowwoc/requirements/java/Validators.java
index fce915bca..c4f85b849 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/Validators.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/Validators.java
@@ -3,6 +3,7 @@
import com.github.cowwoc.requirements.annotation.CheckReturnValue;
import com.github.cowwoc.requirements.java.type.part.Validator;
+import java.util.Map;
import java.util.function.Function;
/**
@@ -20,13 +21,15 @@
* {@code checkIf()} is more flexible than the others, but its syntax is more verbose.
*
* Exceptions that are thrown in response to invalid method arguments (e.g.
- * {@code isGreaterThan(null, value)} are thrown by all validators and cannot be configured. Exceptions that
+ * {@code isGreaterThan(null, value)}) are thrown by all validators and cannot be configured. Exceptions that
* are thrown in response to the value failing a validation check, e.g. {@code isGreaterThan(5)} on a value
* of 0, are thrown by {@code requireThat()} and {@code assumeThat()} but are recorded by {@code checkIf()}
* without being thrown. The type of thrown exceptions is configurable using
* {@link ConfigurationUpdater#exceptionTransformer(Function)}.
+ *
+ * @param the type of the factory
*/
-public interface Validators
+public interface Validators
{
/**
* Returns the configuration used by new validators.
@@ -47,24 +50,58 @@ public interface Validators
ConfigurationUpdater updateConfiguration();
/**
- * Returns the contextual information for validations performed by this thread using any validator. The
- * contextual information is a map of key-value pairs that can provide more details about validation
- * failures. For example, if the message is "Password may not be empty" and the map contains the key-value
- * pair {@code {"username": "john.smith"}}, the exception message would be:
+ * Returns a new factory instance with an independent configuration. This method is commonly used to inherit
+ * and update contextual information from the original factory before passing it into a nested operation.
+ * For example:
+ *
+ * {@snippet :
+ * JavaValidators copy = validators.copy();
+ * copy.context().put(json.toString(), "json");
+ * nestedOperation(copy);
+ *}
+ *
+ * @return a copy of this factory
+ */
+ @CheckReturnValue
+ S copy();
+
+ /**
+ * Returns the contextual information inherited by validators created out by this factory. The contextual
+ * information is a map of key-value pairs that can provide more details about validation failures. For
+ * example, if the message is "Password may not be empty" and the map contains the key-value pair
+ * {@code {"username": "john.smith"}}, the exception message would be:
*
* {@snippet lang = output:
* Password may not be empty
* username: john.smith}
+ *
+ * @return an unmodifiable map from each entry's name to its value
+ */
+ Map getContext();
+
+ /**
+ * Sets the contextual information for validators created by this factory.
*
- * Values set by this method may be overridden by {@link Validator#putContext(Object, String)}}.
- *
- * NOTE : This method affects existing and new validators used by current thread. Changes are
- * reversed once {@link ScopedContext#close()} is invoked.
+ * This method adds contextual information to exception messages. The contextual information is stored as
+ * key-value pairs in a map. Values set by this method may be overridden by
+ * {@link Validator#putContext(Object, String)}}.
*
- * @return the thread context updater
+ * @param value the value of the entry
+ * @param name the name of an entry
+ * @return this
+ * @throws NullPointerException if {@code name} is null
*/
- @CheckReturnValue
- ScopedContext threadContext();
+ S putContext(Object value, String name);
+
+ /**
+ * Removes the contextual information of validators created by this factory.
+ *
+ * @param name the parameter name
+ * @return this
+ * @throws NullPointerException if {@code name} is null
+ * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
+ */
+ S removeContext(String name);
/**
* Returns the global configuration shared by all validators.
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractArrayValidator.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractArrayValidator.java
index 1376efa82..c61c78353 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractArrayValidator.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractArrayValidator.java
@@ -572,18 +572,18 @@ public PrimitiveUnsignedIntegerValidatorImpl length()
{
if (hasFailed())
{
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".length", 0,
- value, PLURALIZER);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".length", 0,
+ name, value, PLURALIZER, context, failures);
}
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".length", 0,
- value, PLURALIZER);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".length", 0,
+ name, value, PLURALIZER, context, failures);
}
PrimitiveUnsignedIntegerValidatorImpl newValidator = new PrimitiveUnsignedIntegerValidatorImpl(scope,
- this, name + ".length", getLength(value), value, PLURALIZER);
+ configuration, name + ".length", getLength(value), name, value, PLURALIZER, context, failures);
newValidator.putContext(value, name);
return newValidator;
}
@@ -592,15 +592,23 @@ public PrimitiveUnsignedIntegerValidatorImpl length()
public CollectionValidatorImpl> asCollection()
{
if (!failures.isEmpty())
- return new CollectionValidatorImpl<>(scope, this, name, null, Pluralizer.ELEMENT);
- return new CollectionValidatorImpl<>(scope, this, name, asList(value), Pluralizer.ELEMENT);
+ {
+ return new CollectionValidatorImpl<>(scope, configuration, name, null, Pluralizer.ELEMENT, context,
+ failures);
+ }
+ return new CollectionValidatorImpl<>(scope, configuration, name, asList(value), Pluralizer.ELEMENT,
+ context, failures);
}
@Override
public ListValidatorImpl> asList()
{
if (!failures.isEmpty())
- return new ListValidatorImpl<>(scope, this, name, null, Pluralizer.ELEMENT);
- return new ListValidatorImpl<>(scope, this, name, asList(value), Pluralizer.ELEMENT);
+ {
+ return new ListValidatorImpl<>(scope, configuration, name, null, Pluralizer.ELEMENT, context,
+ failures);
+ }
+ return new ListValidatorImpl<>(scope, configuration, name, asList(value), Pluralizer.ELEMENT, context,
+ failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractCollectionValidator.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractCollectionValidator.java
index 072607db9..c2a7c7e0e 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractCollectionValidator.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractCollectionValidator.java
@@ -47,7 +47,7 @@ public abstract class AbstractCollectionValidator
* @param pluralizer the type of items in the collection
* @param context the contextual information set by the user
* @param failures the list of validation failures
- * @throws NullPointerException if {@code name} is null
+ * @throws NullPointerException if any of the mandatory arguments are null
* @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
@@ -613,47 +613,56 @@ public PrimitiveUnsignedIntegerValidatorImpl size()
{
if (hasFailed())
{
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".size()", 0,
- null, pluralizer);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".size()", 0,
+ name, null, pluralizer, context, failures);
}
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".size()", 0,
- null, pluralizer);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".size()", 0,
+ name, null, pluralizer, context, failures);
}
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".size()", value.size(),
- value, pluralizer);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".size()", value.size(),
+ name, value, pluralizer, context, failures);
}
@Override
public ObjectArrayValidator asArray(Class type)
{
if (hasFailed())
- return new ObjectArrayValidatorImpl<>(scope, this, name + ".asArray()", null);
+ {
+ return new ObjectArrayValidatorImpl<>(scope, configuration, name + ".asArray()", null, context,
+ failures);
+ }
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new ObjectArrayValidatorImpl<>(scope, this, name + ".asArray()", null);
+ return new ObjectArrayValidatorImpl<>(scope, configuration, name + ".asArray()", null, context,
+ failures);
}
@SuppressWarnings("unchecked")
E[] array = (E[]) Array.newInstance(type, value.size());
- return new ObjectArrayValidatorImpl<>(scope, this, name, value.toArray(array));
+ return new ObjectArrayValidatorImpl<>(scope, configuration, name, value.toArray(array), context, failures);
}
@Override
public ListValidator> asList()
{
if (hasFailed())
- return new ListValidatorImpl<>(scope, this, name + ".asList()", null, pluralizer);
+ {
+ return new ListValidatorImpl<>(scope, configuration, name + ".asList()", null, pluralizer, context,
+ failures);
+ }
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new ListValidatorImpl<>(scope, this, name + ".asList()", null, pluralizer);
+ return new ListValidatorImpl<>(scope, configuration, name + ".asList()", null, pluralizer, context,
+ failures);
}
- return new ListValidatorImpl<>(scope, this, name, new ArrayList<>(value), pluralizer);
+ return new ListValidatorImpl<>(scope, configuration, name, new ArrayList<>(value), pluralizer, context,
+ failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractObjectValidator.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractObjectValidator.java
index c0a72238b..360ab70b4 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractObjectValidator.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractObjectValidator.java
@@ -201,6 +201,7 @@ private BiFunction getEqualityFunction()
@Override
public StringValidatorImpl asString()
{
- return new StringValidatorImpl(scope, this, "String.valueOf(" + name + ")", String.valueOf(value));
+ return new StringValidatorImpl(scope, configuration, "String.valueOf(" + name + ")",
+ String.valueOf(value), context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractValidator.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractValidator.java
index 20e22bfba..fe3fd1cdc 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractValidator.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractValidator.java
@@ -49,7 +49,7 @@ public abstract class AbstractValidator implements Validator
* @param name the name of the value
* @param context the contextual information set by the user
* @param failures the list of validation failures
- * @throws NullPointerException if {@code name} is null
+ * @throws NullPointerException if any of the arguments are null
* @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractValidators.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractValidators.java
index 83a50653c..e706cbb7c 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractValidators.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/AbstractValidators.java
@@ -1,30 +1,38 @@
package com.github.cowwoc.requirements.java.internal.implementation;
+import com.github.cowwoc.requirements.annotation.CheckReturnValue;
import com.github.cowwoc.requirements.java.Configuration;
import com.github.cowwoc.requirements.java.ConfigurationUpdater;
import com.github.cowwoc.requirements.java.EqualityMethod;
import com.github.cowwoc.requirements.java.GlobalConfiguration;
import com.github.cowwoc.requirements.java.MutableStringMappers;
-import com.github.cowwoc.requirements.java.ScopedContext;
import com.github.cowwoc.requirements.java.StringMappers;
import com.github.cowwoc.requirements.java.Validators;
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.internal.util.CloseableLock;
import com.github.cowwoc.requirements.java.internal.util.ReentrantStampedLock;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
import java.util.function.Function;
+import static com.github.cowwoc.requirements.java.DefaultJavaValidators.assumeThat;
+
/**
- * @param the type of validator that the methods should return
+ * @param the type of the validator factory
*/
-public abstract class AbstractValidators implements Validators
+public abstract class AbstractValidators implements Validators
{
protected final ApplicationScope scope;
+ private final ReentrantStampedLock requireThatLock = new ReentrantStampedLock();
private final ReentrantStampedLock assumeThatLock = new ReentrantStampedLock();
private final ReentrantStampedLock checkIfLock = new ReentrantStampedLock();
- private Configuration configuration;
+ private Configuration requireThatConfiguration;
private Configuration assumeThatConfiguration;
private Configuration checkIfConfiguration;
+ protected final Map context = new HashMap<>();
/**
* Creates a new instance.
@@ -40,7 +48,15 @@ protected AbstractValidators(ApplicationScope scope, Configuration configuration
if (configuration == null)
throw new NullPointerException("configuration may not be null");
this.scope = scope;
- this.configuration = configuration;
+ setConfiguration(configuration);
+ }
+
+ /**
+ * @return the application configuration
+ */
+ public ApplicationScope getScope()
+ {
+ return scope;
}
/**
@@ -72,88 +88,91 @@ protected S self()
@Override
public Configuration configuration()
{
- return configuration;
+ return requireThatLock.optimisticRead(() -> this.requireThatConfiguration);
}
- @Override
- public ConfigurationUpdater updateConfiguration()
+ /**
+ * Returns the configuration for {@code assumeThat()} factory methods.
+ *
+ * @return the configuration for {@code assumeThat()} factory methods
+ */
+ protected Configuration getAssumeThatConfiguration()
{
- return new UpdatableConfigurationImpl();
+ return assumeThatLock.optimisticRead(() -> this.assumeThatConfiguration);
}
/**
- * Set the configuration used by new validators.
+ * Returns the configuration for {@code checkIf()} factory methods.
*
- * @param configuration the updated configuration
- * @throws NullPointerException if {@code configuration} is null
+ * @return the configuration for {@code checkIf()} factory methods
*/
- public void setConfiguration(Configuration configuration)
+ protected Configuration getCheckIfConfiguration()
{
- if (configuration == null)
- throw new NullPointerException("configuration may not be null");
- this.configuration = configuration;
- try (CloseableLock unused = assumeThatLock.write())
- {
- assumeThatConfiguration = null;
- }
- try (CloseableLock unused = checkIfLock.write())
- {
- checkIfConfiguration = null;
- }
+ return checkIfLock.optimisticRead(() -> this.checkIfConfiguration);
+ }
+
+ @Override
+ public ConfigurationUpdater updateConfiguration()
+ {
+ return updateConfiguration(this::setConfiguration);
}
/**
- * Returns the configuration for {@code requireThat()} factory methods.
+ * Updates the configuration used by new validators.
+ *
+ * NOTE : Changes are only applied when {@link ConfigurationUpdater#close()} is invoked.
*
- * @return the configuration for {@code requireThat()} factory methods
+ * @param setConfiguration a method that sets the validator factory's configuration
+ * @return the configuration updater
+ * @throws NullPointerException if {@code setConfiguration} is null
*/
- protected Configuration getRequireThatConfiguration()
+ @CheckReturnValue
+ public ConfigurationUpdater updateConfiguration(Consumer setConfiguration)
{
- return configuration();
+ return new UpdatableConfigurationImpl(setConfiguration);
}
/**
- * Returns the configuration for {@code assumeThat()} factory methods.
+ * Set the configuration used by new validators.
*
- * @return the configuration for {@code assumeThat()} factory methods
+ * @param configuration the updated configuration
+ * @throws NullPointerException if {@code configuration} is null
*/
- protected Configuration getAssumeThatConfiguration()
+ public final void setConfiguration(Configuration configuration)
{
- Configuration assumeThatConfiguration = assumeThatLock.optimisticRead(() ->
- this.assumeThatConfiguration);
- if (assumeThatConfiguration != null)
- return assumeThatConfiguration;
+ if (configuration == null)
+ throw new NullPointerException("configuration may not be null");
+ try (CloseableLock unused = requireThatLock.write())
+ {
+ this.requireThatConfiguration = configuration;
+ }
try (CloseableLock unused = assumeThatLock.write())
{
- this.assumeThatConfiguration = assumeThatConfiguration = MutableConfiguration.from(configuration()).
+ this.assumeThatConfiguration = MutableConfiguration.from(configuration).
exceptionTransformer(convertToAssertionError()).toImmutable();
}
- return assumeThatConfiguration;
- }
-
- /**
- * Returns the configuration for {@code checkIf()} factory methods.
- *
- * @return the configuration for {@code checkIf()} factory methods
- */
- protected Configuration getCheckIfConfiguration()
- {
- Configuration checkIfConfiguration = checkIfLock.optimisticRead(() ->
- this.checkIfConfiguration);
- if (checkIfConfiguration != null)
- return checkIfConfiguration;
try (CloseableLock unused = checkIfLock.write())
{
- this.checkIfConfiguration = checkIfConfiguration = MutableConfiguration.from(configuration()).
+ this.checkIfConfiguration = MutableConfiguration.from(configuration).
throwOnFailure(false).toImmutable();
}
- return checkIfConfiguration;
}
- @Override
- public ScopedContext threadContext()
+ /**
+ * Returns the contextual information for validators created out by this factory. The contextual information
+ * is a map of key-value pairs that can provide more details about validation failures. For example, if the
+ * message is "Password may not be empty" and the map contains the key-value pair
+ * {@code {"username": "john.smith"}}, the exception message would be:
+ *
+ * {@snippet lang = output:
+ * Password may not be empty
+ * username: john.smith}
+ *
+ * @return an unmodifiable map from each entry's name to its value
+ */
+ public Map getContext()
{
- return new ScopedContextImpl(scope);
+ return Collections.unmodifiableMap(context);
}
@Override
@@ -169,6 +188,7 @@ public final class UpdatableConfigurationImpl implements ConfigurationUpdater
{
// REMINDER: Per https://shipilev.net/blog/2014/safe-public-construction/ section
// "A final field was written" objects are safe for publication if they contain at least one final field.
+ private final Consumer setConfiguration;
private final MutableStringMappers mutableStringMappers;
private boolean cleanStackTrace;
private boolean includeDiff;
@@ -180,9 +200,15 @@ public final class UpdatableConfigurationImpl implements ConfigurationUpdater
/**
* Creates a new configuration updater.
+ *
+ * @param setConfiguration a method that sets the validator factory's configuration
+ * @throws NullPointerException if {@code setConfiguration} is null
*/
- private UpdatableConfigurationImpl()
+ private UpdatableConfigurationImpl(Consumer setConfiguration)
{
+ assert assumeThat(setConfiguration, "setConfiguration").isNotNull().elseThrow();
+ this.setConfiguration = setConfiguration;
+
Configuration configuration = AbstractValidators.this.configuration();
this.cleanStackTrace = configuration.cleanStackTrace();
this.includeDiff = configuration.includeDiff();
@@ -353,7 +379,7 @@ public void close()
changed |= !immutableStringMappers.equals(oldConfiguration.stringMappers());
if (!changed)
return;
- setConfiguration(new Configuration(cleanStackTrace, includeDiff,
+ this.setConfiguration.accept(new Configuration(cleanStackTrace, includeDiff,
equalityMethod, immutableStringMappers, lazyExceptions, oldConfiguration.throwOnFailure(),
exceptionTransformer));
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BigDecimalValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BigDecimalValidatorImpl.java
index 1ac9779bc..fe0e8807c 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BigDecimalValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BigDecimalValidatorImpl.java
@@ -13,50 +13,12 @@
import com.github.cowwoc.requirements.java.type.BigDecimalValidator;
import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class BigDecimalValidatorImpl extends AbstractObjectValidator
implements BigDecimalValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public BigDecimalValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- BigDecimal value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public BigDecimalValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- BigDecimal value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -69,7 +31,7 @@ public BigDecimalValidatorImpl(ApplicationScope scope, Configuration configurati
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private BigDecimalValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ public BigDecimalValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
BigDecimal value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
@@ -531,28 +493,37 @@ private boolean maximumFailed(BigDecimal maximum, boolean maximumInclusive)
public PrimitiveUnsignedIntegerValidatorImpl precision()
{
if (hasFailed())
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".precision()", 0, value, null);
+ {
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".precision()",
+ 0, name, value, null, context, failures);
+ }
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".precision()", 0, value, null);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".precision()",
+ 0, name, value, null, context, failures);
}
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this,
- name + ".precision()", value.precision(), value, null);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".precision()",
+ value.precision(), name, value, null, context, failures);
}
@Override
public PrimitiveIntegerValidatorImpl scale()
{
if (hasFailed())
- return new PrimitiveIntegerValidatorImpl(scope, this, name + ".scale()", 0);
+ {
+ return new PrimitiveIntegerValidatorImpl(scope, configuration, name + ".scale()", 0, context,
+ failures);
+ }
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new PrimitiveIntegerValidatorImpl(scope, this, name + ".scale()", 0);
+ return new PrimitiveIntegerValidatorImpl(scope, configuration, name + ".scale()", 0, context,
+ failures);
}
- return new PrimitiveIntegerValidatorImpl(scope, this, name + ".scale()", value.scale());
+ return new PrimitiveIntegerValidatorImpl(scope, configuration, name + ".scale()", value.scale(),
+ context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BigIntegerValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BigIntegerValidatorImpl.java
index fc7412f96..28c4b1297 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BigIntegerValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BigIntegerValidatorImpl.java
@@ -13,50 +13,12 @@
import com.github.cowwoc.requirements.java.type.BigIntegerValidator;
import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class BigIntegerValidatorImpl extends AbstractObjectValidator
implements BigIntegerValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public BigIntegerValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- BigInteger value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public BigIntegerValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- BigInteger value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -69,7 +31,7 @@ public BigIntegerValidatorImpl(ApplicationScope scope, Configuration configurati
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private BigIntegerValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ public BigIntegerValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
BigInteger value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BooleanValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BooleanValidatorImpl.java
index 7a72863d9..d15f9c2be 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BooleanValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/BooleanValidatorImpl.java
@@ -7,50 +7,12 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.BooleanValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class BooleanValidatorImpl extends AbstractObjectValidator
implements BooleanValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public BooleanValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- Boolean value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public BooleanValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Boolean value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -63,7 +25,7 @@ public BooleanValidatorImpl(ApplicationScope scope, Configuration configuration,
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private BooleanValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ public BooleanValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
Boolean value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ByteValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ByteValidatorImpl.java
index c45b7ad84..f3bef56fb 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ByteValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ByteValidatorImpl.java
@@ -8,50 +8,12 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.ByteValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class ByteValidatorImpl extends AbstractObjectValidator
implements ByteValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ByteValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- Byte value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ByteValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Byte value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -64,8 +26,8 @@ public ByteValidatorImpl(ApplicationScope scope, Configuration configuration, St
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private ByteValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Byte value, Map context, List failures)
+ public ByteValidatorImpl(ApplicationScope scope, Configuration configuration, String name, Byte value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/CharacterValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/CharacterValidatorImpl.java
index e7a3f64d3..10ead9a73 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/CharacterValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/CharacterValidatorImpl.java
@@ -7,50 +7,12 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.CharacterValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class CharacterValidatorImpl extends AbstractObjectValidator
implements CharacterValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public CharacterValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- Character value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public CharacterValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Character value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -63,7 +25,7 @@ public CharacterValidatorImpl(ApplicationScope scope, Configuration configuratio
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private CharacterValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ public CharacterValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
Character value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ClassValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ClassValidatorImpl.java
index bb3e8e0b9..cbd7cc90e 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ClassValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ClassValidatorImpl.java
@@ -10,8 +10,6 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.ClassValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -21,42 +19,6 @@
public final class ClassValidatorImpl extends AbstractObjectValidator, Class>
implements ClassValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ClassValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- Class value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ClassValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Class value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -69,8 +31,8 @@ public ClassValidatorImpl(ApplicationScope scope, Configuration configuration, S
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private ClassValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Class value, Map context, List failures)
+ public ClassValidatorImpl(ApplicationScope scope, Configuration configuration, String name, Class value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/CollectionValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/CollectionValidatorImpl.java
index d34cd30a9..b100afff8 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/CollectionValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/CollectionValidatorImpl.java
@@ -10,9 +10,7 @@
import com.github.cowwoc.requirements.java.internal.util.Pluralizer;
import com.github.cowwoc.requirements.java.type.CollectionValidator;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -24,44 +22,6 @@ public final class CollectionValidatorImpl>
extends AbstractCollectionValidator, E, T>
implements CollectionValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @param pluralizer the type of items in the collection
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public CollectionValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- T value, Pluralizer pluralizer)
- {
- this(scope, validator.configuration(), name, value, pluralizer, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @param pluralizer the type of items in the collection
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public CollectionValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value, Pluralizer pluralizer)
- {
- this(scope, configuration, name, value, pluralizer, HashMap.newHashMap(4), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -75,8 +35,8 @@ public CollectionValidatorImpl(ApplicationScope scope, Configuration configurati
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private CollectionValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value, Pluralizer pluralizer, Map context, List failures)
+ public CollectionValidatorImpl(ApplicationScope scope, Configuration configuration, String name, T value,
+ Pluralizer pluralizer, Map context, List failures)
{
super(scope, configuration, name, value, pluralizer, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ComparableValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ComparableValidatorImpl.java
index 472c24611..22737082c 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ComparableValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ComparableValidatorImpl.java
@@ -11,8 +11,6 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.ComparableValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -23,42 +21,6 @@ public final class ComparableValidatorImpl>
extends AbstractObjectValidator, T>
implements ComparableValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ComparableValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- T value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ComparableValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -71,8 +33,8 @@ public ComparableValidatorImpl(ApplicationScope scope, Configuration configurati
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- public ComparableValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value, Map context, List failures)
+ public ComparableValidatorImpl(ApplicationScope scope, Configuration configuration, String name, T value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/DoubleValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/DoubleValidatorImpl.java
index 76160eab2..bc9a24d43 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/DoubleValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/DoubleValidatorImpl.java
@@ -12,50 +12,12 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.DoubleValidator;
- import java.util.ArrayList;
- import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class DoubleValidatorImpl extends AbstractObjectValidator
implements DoubleValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public DoubleValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- Double value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public DoubleValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Double value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -68,7 +30,7 @@ public DoubleValidatorImpl(ApplicationScope scope, Configuration configuration,
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private DoubleValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ public DoubleValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
Double value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/FloatValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/FloatValidatorImpl.java
index b2f9a1c17..42bb77bad 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/FloatValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/FloatValidatorImpl.java
@@ -12,50 +12,12 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.FloatValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class FloatValidatorImpl extends AbstractObjectValidator
implements FloatValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public FloatValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- Float value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public FloatValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Float value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -68,8 +30,8 @@ public FloatValidatorImpl(ApplicationScope scope, Configuration configuration, S
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private FloatValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Float value, Map context, List failures)
+ public FloatValidatorImpl(ApplicationScope scope, Configuration configuration, String name, Float value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/InetAddressValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/InetAddressValidatorImpl.java
index 187b0dbe8..ba357391c 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/InetAddressValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/InetAddressValidatorImpl.java
@@ -14,50 +14,12 @@
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class InetAddressValidatorImpl extends AbstractObjectValidator
implements InetAddressValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public InetAddressValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- InetAddress value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public InetAddressValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- InetAddress value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -70,7 +32,7 @@ public InetAddressValidatorImpl(ApplicationScope scope, Configuration configurat
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private InetAddressValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ public InetAddressValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
InetAddress value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
@@ -129,6 +91,6 @@ public StringValidatorImpl asString()
// InetAddress.getByName(String). Instead, we use InetAddress.getHostName() which returns the desired
// format.
String hostName = value.getHostName();
- return new StringValidatorImpl(scope, this, name, hostName);
+ return new StringValidatorImpl(scope, configuration, name, hostName, context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/IntegerValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/IntegerValidatorImpl.java
index 1e918b0c9..e3324c03f 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/IntegerValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/IntegerValidatorImpl.java
@@ -8,50 +8,12 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.IntegerValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class IntegerValidatorImpl extends AbstractObjectValidator
implements IntegerValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public IntegerValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- Integer value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public IntegerValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Integer value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -64,8 +26,8 @@ public IntegerValidatorImpl(ApplicationScope scope, Configuration configuration,
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private IntegerValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Integer value, Map context, List failures)
+ public IntegerValidatorImpl(ApplicationScope scope, Configuration configuration, String name, Integer value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/JavaValidatorsImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/JavaValidatorsImpl.java
index c1dc2d80e..1138ee7c8 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/JavaValidatorsImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/JavaValidatorsImpl.java
@@ -2,6 +2,7 @@
import com.github.cowwoc.requirements.java.Configuration;
import com.github.cowwoc.requirements.java.JavaValidators;
+import com.github.cowwoc.requirements.java.ValidationFailure;
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.internal.util.Pluralizer;
import com.github.cowwoc.requirements.java.type.BigDecimalValidator;
@@ -50,12 +51,14 @@
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-public final class JavaValidatorsImpl extends AbstractValidators
+public final class JavaValidatorsImpl extends AbstractValidators
implements JavaValidators
{
/**
@@ -70,238 +73,250 @@ public JavaValidatorsImpl(ApplicationScope scope, Configuration configuration)
super(scope, configuration);
}
+ /**
+ * Creates a copy of an existing validator factory.
+ *
+ * @param other the factory to copy
+ * @throws NullPointerException if {@code other} is null
+ */
+ public JavaValidatorsImpl(JavaValidatorsImpl other)
+ {
+ this(other.scope, other.configuration());
+ this.context.putAll(other.context);
+ }
+
@Override
public PrimitiveByteValidator requireThat(byte value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public ByteValidator requireThat(Byte value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveShortValidator requireThat(short value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public ShortValidator requireThat(Short value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveIntegerValidator requireThat(int value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public IntegerValidator requireThat(Integer value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveLongValidator requireThat(long value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public LongValidator requireThat(Long value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveFloatValidator requireThat(float value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public FloatValidator requireThat(Float value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveDoubleValidator requireThat(double value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public DoubleValidator requireThat(Double value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveBooleanValidator requireThat(boolean value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public BooleanValidator requireThat(Boolean value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveCharacterValidator requireThat(char value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public CharacterValidator requireThat(Character value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public BigIntegerValidator requireThat(BigInteger value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public BigDecimalValidator requireThat(BigDecimal value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public > ComparableValidator requireThat(T value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public ObjectValidator requireThat(T value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public > CollectionValidator requireThat(T value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public > ListValidator requireThat(T value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveByteArrayValidator requireThat(byte[] value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveShortArrayValidator requireThat(short[] value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveIntegerArrayValidator requireThat(int[] value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveLongArrayValidator requireThat(long[] value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveFloatArrayValidator requireThat(float[] value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveDoubleArrayValidator requireThat(double[] value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveBooleanArrayValidator requireThat(boolean[] value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PrimitiveCharacterArrayValidator requireThat(char[] value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public ObjectArrayValidator requireThat(E[] value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public > MapValidator requireThat(T value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public PathValidator requireThat(Path value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public StringValidator requireThat(String value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public UriValidator requireThat(URI value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public UrlValidator requireThat(URL value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public ClassValidator requireThat(Class value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public OptionalValidator requireThat(Optional value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
public InetAddressValidator requireThat(InetAddress value, String name)
{
- return newInstance(value, name, getRequireThatConfiguration());
+ return newInstance(value, name, configuration());
}
@Override
@@ -1242,211 +1257,272 @@ public InetAddressValidator checkIf(InetAddress value)
private PrimitiveByteValidator newInstance(byte value, String name, Configuration configuration)
{
- return new PrimitiveByteValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveByteValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
+ }
+
+ private Map newValidatorContext()
+ {
+ HashMap context = HashMap.newHashMap(this.context.size() + 2);
+ context.putAll(this.context);
+ return context;
+ }
+
+ private List newValidatorFailures()
+ {
+ return new ArrayList<>(2);
}
private ByteValidator newInstance(Byte value, String name, Configuration configuration)
{
- return new ByteValidatorImpl(scope, configuration, name, value);
+ return new ByteValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
private PrimitiveShortValidator newInstance(short value, String name, Configuration configuration)
{
- return new PrimitiveShortValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveShortValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
private ShortValidator newInstance(Short value, String name, Configuration configuration)
{
- return new ShortValidatorImpl(scope, configuration, name, value);
+ return new ShortValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
private PrimitiveIntegerValidator newInstance(int value, String name, Configuration configuration)
{
- return new PrimitiveIntegerValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveIntegerValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
private IntegerValidator newInstance(Integer value, String name, Configuration configuration)
{
- return new IntegerValidatorImpl(scope, configuration, name, value);
+ return new IntegerValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
private PrimitiveLongValidator newInstance(long value, String name, Configuration configuration)
{
- return new PrimitiveLongValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveLongValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
private LongValidator newInstance(Long value, String name, Configuration configuration)
{
- return new LongValidatorImpl(scope, configuration, name, value);
+ return new LongValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
private PrimitiveFloatValidator newInstance(float value, String name, Configuration configuration)
{
- return new PrimitiveFloatValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveFloatValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
private FloatValidator newInstance(Float value, String name, Configuration configuration)
{
- return new FloatValidatorImpl(scope, configuration, name, value);
+ return new FloatValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public PrimitiveDoubleValidator newInstance(double value, String name, Configuration configuration)
{
- return new PrimitiveDoubleValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveDoubleValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
private DoubleValidator newInstance(Double value, String name, Configuration configuration)
{
- return new DoubleValidatorImpl(scope, configuration, name, value);
+ return new DoubleValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
- public PrimitiveBooleanValidator newInstance(boolean value, String name,
- Configuration configuration)
+ public PrimitiveBooleanValidator newInstance(boolean value, String name, Configuration configuration)
{
- return new PrimitiveBooleanValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveBooleanValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public BooleanValidator newInstance(Boolean value, String name, Configuration configuration)
{
- return new BooleanValidatorImpl(scope, configuration, name, value);
+ return new BooleanValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public PrimitiveCharacterValidator newInstance(char value, String name, Configuration configuration)
{
- return new PrimitiveCharacterValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveCharacterValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public CharacterValidator newInstance(Character value, String name, Configuration configuration)
{
- return new CharacterValidatorImpl(scope, configuration, name, value);
+ return new CharacterValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public BigIntegerValidator newInstance(BigInteger value, String name, Configuration configuration)
{
- return new BigIntegerValidatorImpl(scope, configuration, name, value);
+ return new BigIntegerValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public BigDecimalValidator newInstance(BigDecimal value, String name, Configuration configuration)
{
- return new BigDecimalValidatorImpl(scope, configuration, name, value);
+ return new BigDecimalValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public > ComparableValidator newInstance(T value, String name,
Configuration configuration)
{
- return new ComparableValidatorImpl<>(scope, configuration, name, value);
+ return new ComparableValidatorImpl<>(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public ObjectValidator newInstance(T value, String name, Configuration configuration)
{
- return new ObjectValidatorImpl<>(scope, configuration, name, value);
+ return new ObjectValidatorImpl<>(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public > CollectionValidator newInstance(T value, String name,
Configuration configuration)
{
- return new CollectionValidatorImpl<>(scope, configuration, name, value, Pluralizer.ELEMENT);
+ return new CollectionValidatorImpl<>(scope, configuration, name, value, Pluralizer.ELEMENT,
+ newValidatorContext(), newValidatorFailures());
}
public > ListValidator newInstance(T value, String name,
Configuration configuration)
{
- return new ListValidatorImpl<>(scope, configuration, name, value, Pluralizer.ELEMENT);
+ return new ListValidatorImpl<>(scope, configuration, name, value, Pluralizer.ELEMENT,
+ newValidatorContext(), newValidatorFailures());
}
- public PrimitiveByteArrayValidator newInstance(byte[] value, String name,
- Configuration configuration)
+ public PrimitiveByteArrayValidator newInstance(byte[] value, String name, Configuration configuration)
{
- return new PrimitiveByteArrayValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveByteArrayValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
- public PrimitiveShortArrayValidator newInstance(short[] value, String name,
- Configuration configuration)
+ public PrimitiveShortArrayValidator newInstance(short[] value, String name, Configuration configuration)
{
- return new PrimitiveShortArrayValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveShortArrayValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
- public PrimitiveIntegerArrayValidator newInstance(int[] value, String name,
- Configuration configuration)
+ public PrimitiveIntegerArrayValidator newInstance(int[] value, String name, Configuration configuration)
{
- return new PrimitiveIntegerArrayValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveIntegerArrayValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
- public PrimitiveLongArrayValidator newInstance(long[] value, String name,
- Configuration configuration)
+ public PrimitiveLongArrayValidator newInstance(long[] value, String name, Configuration configuration)
{
- return new PrimitiveLongArrayValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveLongArrayValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
- public PrimitiveFloatArrayValidator newInstance(float[] value, String name,
- Configuration configuration)
+ public PrimitiveFloatArrayValidator newInstance(float[] value, String name, Configuration configuration)
{
- return new PrimitiveFloatArrayValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveFloatArrayValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
- public PrimitiveDoubleArrayValidator newInstance(double[] value, String name,
- Configuration configuration)
+ public PrimitiveDoubleArrayValidator newInstance(double[] value, String name, Configuration configuration)
{
- return new PrimitiveDoubleArrayValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveDoubleArrayValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
- public PrimitiveBooleanArrayValidator newInstance(boolean[] value, String name,
- Configuration configuration)
+ public PrimitiveBooleanArrayValidator newInstance(boolean[] value, String name, Configuration configuration)
{
- return new PrimitiveBooleanArrayValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveBooleanArrayValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
- public PrimitiveCharacterArrayValidator newInstance(char[] value, String name,
- Configuration configuration)
+ public PrimitiveCharacterArrayValidator newInstance(char[] value, String name, Configuration configuration)
{
- return new PrimitiveCharacterArrayValidatorImpl(scope, configuration, name, value);
+ return new PrimitiveCharacterArrayValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
- public ObjectArrayValidator newInstance(E[] value, String name,
- Configuration configuration)
+ public ObjectArrayValidator newInstance(E[] value, String name, Configuration configuration)
{
- return new ObjectArrayValidatorImpl<>(scope, configuration, name, value);
+ return new ObjectArrayValidatorImpl<>(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public > MapValidator newInstance(T value, String name,
Configuration configuration)
{
- return new MapValidatorImpl<>(scope, configuration, name, value);
+ return new MapValidatorImpl<>(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public PathValidator newInstance(Path value, String name, Configuration configuration)
{
- return new PathValidatorImpl(scope, configuration, name, value);
+ return new PathValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public StringValidator newInstance(String value, String name, Configuration configuration)
{
- return new StringValidatorImpl(scope, configuration, name, value);
+ return new StringValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public UriValidator newInstance(URI value, String name, Configuration configuration)
{
- return new UriValidatorImpl(scope, configuration, name, value);
+ return new UriValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public UrlValidator newInstance(URL value, String name, Configuration configuration)
{
- return new UrlValidatorImpl(scope, configuration, name, value);
+ return new UrlValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public ClassValidator newInstance(Class value, String name, Configuration configuration)
{
- return new ClassValidatorImpl<>(scope, configuration, name, value);
+ return new ClassValidatorImpl<>(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public OptionalValidator newInstance(Optional value, String name, Configuration configuration)
{
- return new OptionalValidatorImpl<>(scope, configuration, name, value);
+ return new OptionalValidatorImpl<>(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
}
public InetAddressValidator newInstance(InetAddress value, String name, Configuration configuration)
{
- return new InetAddressValidatorImpl(scope, configuration, name, value);
+ return new InetAddressValidatorImpl(scope, configuration, name, value, newValidatorContext(),
+ newValidatorFailures());
+ }
+
+ @Override
+ public JavaValidatorsImpl copy()
+ {
+ return new JavaValidatorsImpl(this);
+ }
+
+ @Override
+ public JavaValidatorsImpl putContext(Object value, String name)
+ {
+ context.put(name, value);
+ return this;
+ }
+
+ @Override
+ public JavaValidatorsImpl removeContext(String name)
+ {
+ context.remove(name);
+ return this;
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ListValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ListValidatorImpl.java
index bf33229bf..829cc1553 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ListValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ListValidatorImpl.java
@@ -12,9 +12,7 @@
import com.github.cowwoc.requirements.java.internal.util.Pluralizer;
import com.github.cowwoc.requirements.java.type.ListValidator;
-import java.util.ArrayList;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -26,44 +24,6 @@ public final class ListValidatorImpl>
extends AbstractCollectionValidator, E, T>
implements ListValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @param pluralizer (optional) the type of items in the collection
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ListValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- T value, Pluralizer pluralizer)
- {
- this(scope, validator.configuration(), name, value, pluralizer, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @param pluralizer (optional) the type of items in the collection
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ListValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value, Pluralizer pluralizer)
- {
- this(scope, configuration, name, value, pluralizer, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -77,8 +37,8 @@ public ListValidatorImpl(ApplicationScope scope, Configuration configuration, St
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private ListValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value, Pluralizer pluralizer, Map context, List failures)
+ public ListValidatorImpl(ApplicationScope scope, Configuration configuration, String name, T value,
+ Pluralizer pluralizer, Map context, List failures)
{
super(scope, configuration, name, value, pluralizer, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/LongValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/LongValidatorImpl.java
index 0373aeaed..94fc76cbd 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/LongValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/LongValidatorImpl.java
@@ -8,49 +8,12 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.LongValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class LongValidatorImpl extends AbstractObjectValidator
implements LongValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public LongValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name, Long value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public LongValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Long value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -63,8 +26,8 @@ public LongValidatorImpl(ApplicationScope scope, Configuration configuration, St
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private LongValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Long value, Map context, List failures)
+ public LongValidatorImpl(ApplicationScope scope, Configuration configuration, String name, Long value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/MapValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/MapValidatorImpl.java
index 2b04e981e..6d380592a 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/MapValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/MapValidatorImpl.java
@@ -14,9 +14,7 @@
import com.github.cowwoc.requirements.java.type.MapValidator;
import com.github.cowwoc.requirements.java.type.PrimitiveUnsignedIntegerValidator;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -31,40 +29,6 @@ public final class MapValidatorImpl>
extends AbstractObjectValidator, T>
implements MapValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public MapValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name, T value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public MapValidatorImpl(ApplicationScope scope, Configuration configuration, String name, T value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(4), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -72,12 +36,12 @@ public MapValidatorImpl(ApplicationScope scope, Configuration configuration, Str
* @param value (optional) the value
* @param context the contextual information set by the user
* @param failures the list of validation failures
- * @throws NullPointerException if {@code name} is null
+ * @throws NullPointerException if any of the mandatory arguments are null
* @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private MapValidatorImpl(ApplicationScope scope, Configuration configuration, String name, T value,
+ public MapValidatorImpl(ApplicationScope scope, Configuration configuration, String name, T value,
Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
@@ -140,18 +104,18 @@ public PrimitiveUnsignedIntegerValidator size()
{
if (hasFailed())
{
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".size()", 0,
- null, Pluralizer.ENTRY);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".size()", 0,
+ name, null, Pluralizer.ENTRY, context, failures);
}
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new PrimitiveUnsignedIntegerValidatorImpl(scope, this, name + ".size()", 0,
- null, Pluralizer.ENTRY);
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".size()", 0,
+ name, null, Pluralizer.ENTRY, context, failures);
}
- return new PrimitiveUnsignedIntegerValidatorImpl(scope,
- this, name + ".size()", value.size(), value, Pluralizer.ENTRY).
+ return new PrimitiveUnsignedIntegerValidatorImpl(scope, configuration, name + ".size()", value.size(),
+ name, value, Pluralizer.ENTRY, context, failures).
putContext(value, name);
}
@@ -159,28 +123,38 @@ public PrimitiveUnsignedIntegerValidator size()
public CollectionValidator> keySet()
{
if (hasFailed())
- return new CollectionValidatorImpl<>(scope, this, name + ".keySet()", null, Pluralizer.KEY);
+ {
+ return new CollectionValidatorImpl<>(scope, configuration, name + ".keySet()", null, Pluralizer.KEY,
+ context, failures);
+ }
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new CollectionValidatorImpl<>(scope, this, name + ".keySet()", null, Pluralizer.KEY);
+ return new CollectionValidatorImpl<>(scope, configuration, name + ".keySet()", null, Pluralizer.KEY,
+ context, failures);
}
- return new CollectionValidatorImpl<>(scope, this, name + ".keySet()", value.keySet(), Pluralizer.KEY);
+ return new CollectionValidatorImpl<>(scope, configuration, name + ".keySet()", value.keySet(),
+ Pluralizer.KEY, context, failures);
}
@Override
public CollectionValidator> values()
{
if (hasFailed())
- return new CollectionValidatorImpl<>(scope, this, name + ".values()", null, Pluralizer.VALUE);
+ {
+ return new CollectionValidatorImpl<>(scope, configuration, name + ".values()", null, Pluralizer.VALUE,
+ context, failures);
+ }
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new CollectionValidatorImpl<>(scope, this, name + ".values()", null, Pluralizer.VALUE);
+ return new CollectionValidatorImpl<>(scope, configuration, name + ".values()", null, Pluralizer.VALUE,
+ context, failures);
}
- return new CollectionValidatorImpl<>(scope, this, name + ".values()", value.values(), Pluralizer.VALUE);
+ return new CollectionValidatorImpl<>(scope, configuration, name + ".values()", value.values(),
+ Pluralizer.VALUE, context, failures);
}
@Override
@@ -188,15 +162,17 @@ public CollectionValidator, Set>> entrySet()
{
if (hasFailed())
{
- return new CollectionValidatorImpl<>(scope, this, name + ".entrySet()", null, Pluralizer.ENTRY);
+ return new CollectionValidatorImpl<>(scope, configuration, name + ".entrySet()", null,
+ Pluralizer.ENTRY, context, failures);
}
if (value == null)
{
addNullPointerException(
ObjectMessages.isNotNull(scope, this, this.name).toString());
- return new CollectionValidatorImpl<>(scope, this, name + ".entrySet()", null, Pluralizer.ENTRY);
+ return new CollectionValidatorImpl<>(scope, configuration, name + ".entrySet()", null,
+ Pluralizer.ENTRY, context, failures);
}
- return new CollectionValidatorImpl<>(scope, this, name + ".entrySet()", value.entrySet(),
- Pluralizer.ENTRY);
+ return new CollectionValidatorImpl<>(scope, configuration, name + ".entrySet()", value.entrySet(),
+ Pluralizer.ENTRY, context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ObjectArrayValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ObjectArrayValidatorImpl.java
index c408d63cb..fb5aefb0e 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ObjectArrayValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ObjectArrayValidatorImpl.java
@@ -14,9 +14,7 @@
import com.github.cowwoc.requirements.java.internal.util.Arrays;
import com.github.cowwoc.requirements.java.type.ObjectArrayValidator;
-import java.util.ArrayList;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -28,42 +26,6 @@
public final class ObjectArrayValidatorImpl extends AbstractArrayValidator, E, E[]>
implements ObjectArrayValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ObjectArrayValidatorImpl(ApplicationScope scope, AbstractValidator> validator,
- String name, E[] value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ObjectArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, E[] value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(4), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -76,8 +38,8 @@ public ObjectArrayValidatorImpl(ApplicationScope scope, Configuration configurat
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private ObjectArrayValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- E[] value, Map context, List failures)
+ public ObjectArrayValidatorImpl(ApplicationScope scope, Configuration configuration, String name, E[] value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ObjectValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ObjectValidatorImpl.java
index a59398e22..eff52469a 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ObjectValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/ObjectValidatorImpl.java
@@ -31,9 +31,7 @@
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -44,41 +42,6 @@
public final class ObjectValidatorImpl extends AbstractObjectValidator, T>
implements ObjectValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ObjectValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name, T value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public ObjectValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -91,8 +54,8 @@ public ObjectValidatorImpl(ApplicationScope scope, Configuration configuration,
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private ObjectValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- T value, Map context, List failures)
+ public ObjectValidatorImpl(ApplicationScope scope, Configuration configuration, String name, T value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
@@ -107,7 +70,7 @@ public T getValue()
public PrimitiveByteValidatorImpl isByte()
{
if (hasFailed())
- return new PrimitiveByteValidatorImpl(scope, this, name, (byte) 0);
+ return new PrimitiveByteValidatorImpl(scope, configuration, name, (byte) 0, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -118,16 +81,16 @@ else if (!(value instanceof Byte))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Byte.class).
toString());
- return new PrimitiveByteValidatorImpl(scope, this, name, (byte) 0);
+ return new PrimitiveByteValidatorImpl(scope, configuration, name, (byte) 0, context, failures);
}
- return new PrimitiveByteValidatorImpl(scope, this, name, (byte) value);
+ return new PrimitiveByteValidatorImpl(scope, configuration, name, (byte) value, context, failures);
}
@Override
public PrimitiveShortValidatorImpl isShort()
{
if (hasFailed())
- return new PrimitiveShortValidatorImpl(scope, this, name, (short) 0);
+ return new PrimitiveShortValidatorImpl(scope, configuration, name, (short) 0, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -138,16 +101,16 @@ else if (!(value instanceof Short))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Short.class).
toString());
- return new PrimitiveShortValidatorImpl(scope, this, name, (short) 0);
+ return new PrimitiveShortValidatorImpl(scope, configuration, name, (short) 0, context, failures);
}
- return new PrimitiveShortValidatorImpl(scope, this, name, (short) value);
+ return new PrimitiveShortValidatorImpl(scope, configuration, name, (short) value, context, failures);
}
@Override
public PrimitiveIntegerValidatorImpl isInt()
{
if (hasFailed())
- return new PrimitiveIntegerValidatorImpl(scope, this, name, 0);
+ return new PrimitiveIntegerValidatorImpl(scope, configuration, name, 0, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -158,16 +121,16 @@ else if (!(value instanceof Integer))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Integer.class).
toString());
- return new PrimitiveIntegerValidatorImpl(scope, this, name, 0);
+ return new PrimitiveIntegerValidatorImpl(scope, configuration, name, 0, context, failures);
}
- return new PrimitiveIntegerValidatorImpl(scope, this, name, (int) value);
+ return new PrimitiveIntegerValidatorImpl(scope, configuration, name, (int) value, context, failures);
}
@Override
public PrimitiveLongValidatorImpl isLong()
{
if (hasFailed())
- return new PrimitiveLongValidatorImpl(scope, this, name, 0L);
+ return new PrimitiveLongValidatorImpl(scope, configuration, name, 0L, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -178,16 +141,16 @@ else if (!(value instanceof Long))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Long.class).
toString());
- return new PrimitiveLongValidatorImpl(scope, this, name, 0L);
+ return new PrimitiveLongValidatorImpl(scope, configuration, name, 0L, context, failures);
}
- return new PrimitiveLongValidatorImpl(scope, this, name, (long) value);
+ return new PrimitiveLongValidatorImpl(scope, configuration, name, (long) value, context, failures);
}
@Override
public PrimitiveFloatValidatorImpl isFloat()
{
if (hasFailed())
- return new PrimitiveFloatValidatorImpl(scope, this, name, 0.0f);
+ return new PrimitiveFloatValidatorImpl(scope, configuration, name, 0.0f, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -198,16 +161,16 @@ else if (!(value instanceof Float))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Float.class).
toString());
- return new PrimitiveFloatValidatorImpl(scope, this, name, 0.0f);
+ return new PrimitiveFloatValidatorImpl(scope, configuration, name, 0.0f, context, failures);
}
- return new PrimitiveFloatValidatorImpl(scope, this, name, (float) value);
+ return new PrimitiveFloatValidatorImpl(scope, configuration, name, (float) value, context, failures);
}
@Override
public PrimitiveDoubleValidatorImpl isDouble()
{
if (hasFailed())
- return new PrimitiveDoubleValidatorImpl(scope, this, name, 0.0);
+ return new PrimitiveDoubleValidatorImpl(scope, configuration, name, 0.0, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -218,16 +181,16 @@ else if (!(value instanceof Double))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Double.class).
toString());
- return new PrimitiveDoubleValidatorImpl(scope, this, name, 0.0);
+ return new PrimitiveDoubleValidatorImpl(scope, configuration, name, 0.0, context, failures);
}
- return new PrimitiveDoubleValidatorImpl(scope, this, name, (double) value);
+ return new PrimitiveDoubleValidatorImpl(scope, configuration, name, (double) value, context, failures);
}
@Override
public PrimitiveBooleanValidatorImpl isBoolean()
{
if (hasFailed())
- return new PrimitiveBooleanValidatorImpl(scope, this, name, false);
+ return new PrimitiveBooleanValidatorImpl(scope, configuration, name, false, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -238,16 +201,16 @@ else if (!(value instanceof Boolean))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Boolean.class).
toString());
- return new PrimitiveBooleanValidatorImpl(scope, this, name, false);
+ return new PrimitiveBooleanValidatorImpl(scope, configuration, name, false, context, failures);
}
- return new PrimitiveBooleanValidatorImpl(scope, this, name, (boolean) value);
+ return new PrimitiveBooleanValidatorImpl(scope, configuration, name, (boolean) value, context, failures);
}
@Override
public PrimitiveCharacterValidatorImpl isChar()
{
if (hasFailed())
- return new PrimitiveCharacterValidatorImpl(scope, this, name, '-');
+ return new PrimitiveCharacterValidatorImpl(scope, configuration, name, '-', context, failures);
else if (value == null)
{
addNullPointerException(
@@ -258,16 +221,16 @@ else if (!(value instanceof Character))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Character.class).
toString());
- return new PrimitiveCharacterValidatorImpl(scope, this, name, '-');
+ return new PrimitiveCharacterValidatorImpl(scope, configuration, name, '-', context, failures);
}
- return new PrimitiveCharacterValidatorImpl(scope, this, name, (char) value);
+ return new PrimitiveCharacterValidatorImpl(scope, configuration, name, (char) value, context, failures);
}
@Override
public BigIntegerValidatorImpl isBigInteger()
{
if (hasFailed())
- return new BigIntegerValidatorImpl(scope, this, name, null);
+ return new BigIntegerValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -278,16 +241,16 @@ else if (!(value instanceof BigInteger))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, BigInteger.class).
toString());
- return new BigIntegerValidatorImpl(scope, this, name, null);
+ return new BigIntegerValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new BigIntegerValidatorImpl(scope, this, name, (BigInteger) value);
+ return new BigIntegerValidatorImpl(scope, configuration, name, (BigInteger) value, context, failures);
}
@Override
public BigDecimalValidatorImpl isBigDecimal()
{
if (hasFailed())
- return new BigDecimalValidatorImpl(scope, this, name, null);
+ return new BigDecimalValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -298,16 +261,16 @@ else if (!(value instanceof BigDecimal))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, BigDecimal.class).
toString());
- return new BigDecimalValidatorImpl(scope, this, name, null);
+ return new BigDecimalValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new BigDecimalValidatorImpl(scope, this, name, (BigDecimal) value);
+ return new BigDecimalValidatorImpl(scope, configuration, name, (BigDecimal) value, context, failures);
}
@Override
public ComparableValidatorImpl> isComparable()
{
if (hasFailed())
- return new ComparableValidatorImpl<>(scope, this, name, null);
+ return new ComparableValidatorImpl<>(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -318,16 +281,19 @@ else if (!(value instanceof Comparable>))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Comparable.class).
toString());
- return new ComparableValidatorImpl<>(scope, this, name, null);
+ return new ComparableValidatorImpl<>(scope, configuration, name, null, context, failures);
}
- return new ComparableValidatorImpl<>(scope, this, name, (BigDecimal) value);
+ return new ComparableValidatorImpl<>(scope, configuration, name, (BigDecimal) value, context, failures);
}
@Override
public CollectionValidator, ? extends Collection>> isCollection()
{
if (hasFailed())
- return new CollectionValidatorImpl<>(scope, this, name, null, Pluralizer.ELEMENT);
+ {
+ return new CollectionValidatorImpl<>(scope, configuration, name, null, Pluralizer.ELEMENT, context,
+ failures);
+ }
else if (value == null)
{
addNullPointerException(
@@ -338,17 +304,21 @@ else if (!(value instanceof Collection>))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Collection.class).
toString());
- return new CollectionValidatorImpl<>(scope, this, name, null, Pluralizer.ELEMENT);
+ return new CollectionValidatorImpl<>(scope, configuration, name, null, Pluralizer.ELEMENT, context,
+ failures);
}
- return new CollectionValidatorImpl<>(scope, this, name, (Collection>) value,
- Pluralizer.ELEMENT);
+ return new CollectionValidatorImpl<>(scope, configuration, name, (Collection>) value,
+ Pluralizer.ELEMENT, context, failures);
}
@Override
public ListValidator, ? extends List>> isList()
{
if (hasFailed())
- return new ListValidatorImpl<>(scope, this, name, null, Pluralizer.ELEMENT);
+ {
+ return new ListValidatorImpl<>(scope, configuration, name, null, Pluralizer.ELEMENT, context,
+ failures);
+ }
else if (value == null)
{
addNullPointerException(
@@ -359,16 +329,18 @@ else if (!(value instanceof List>))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, List.class).
toString());
- return new ListValidatorImpl<>(scope, this, name, null, Pluralizer.ELEMENT);
+ return new ListValidatorImpl<>(scope, configuration, name, null, Pluralizer.ELEMENT, context,
+ failures);
}
- return new ListValidatorImpl<>(scope, this, name, (List>) value, Pluralizer.ELEMENT);
+ return new ListValidatorImpl<>(scope, configuration, name, (List>) value, Pluralizer.ELEMENT, context,
+ failures);
}
@Override
public PrimitiveByteArrayValidator isByteArray()
{
if (hasFailed())
- return new PrimitiveByteArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveByteArrayValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -379,16 +351,16 @@ else if (!(value instanceof byte[]))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, byte[].class).
toString());
- return new PrimitiveByteArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveByteArrayValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new PrimitiveByteArrayValidatorImpl(scope, this, name, (byte[]) value);
+ return new PrimitiveByteArrayValidatorImpl(scope, configuration, name, (byte[]) value, context, failures);
}
@Override
public PrimitiveShortArrayValidator isShortArray()
{
if (hasFailed())
- return new PrimitiveShortArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveShortArrayValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -399,16 +371,16 @@ else if (!(value instanceof short[]))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, short[].class).
toString());
- return new PrimitiveShortArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveShortArrayValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new PrimitiveShortArrayValidatorImpl(scope, this, name, (short[]) value);
+ return new PrimitiveShortArrayValidatorImpl(scope, configuration, name, (short[]) value, context, failures);
}
@Override
public PrimitiveIntegerArrayValidator isIntArray()
{
if (hasFailed())
- return new PrimitiveIntegerArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveIntegerArrayValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -419,16 +391,17 @@ else if (!(value instanceof int[]))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, int[].class).
toString());
- return new PrimitiveIntegerArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveIntegerArrayValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new PrimitiveIntegerArrayValidatorImpl(scope, this, name, (int[]) value);
+ return new PrimitiveIntegerArrayValidatorImpl(scope, configuration, name, (int[]) value, context,
+ failures);
}
@Override
public PrimitiveLongArrayValidator isLongArray()
{
if (hasFailed())
- return new PrimitiveLongArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveLongArrayValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -439,16 +412,16 @@ else if (!(value instanceof long[]))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, long[].class).
toString());
- return new PrimitiveLongArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveLongArrayValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new PrimitiveLongArrayValidatorImpl(scope, this, name, (long[]) value);
+ return new PrimitiveLongArrayValidatorImpl(scope, configuration, name, (long[]) value, context, failures);
}
@Override
public PrimitiveFloatArrayValidator isFloatArray()
{
if (hasFailed())
- return new PrimitiveFloatArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveFloatArrayValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -459,16 +432,17 @@ else if (!(value instanceof float[]))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, float[].class).
toString());
- return new PrimitiveFloatArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveFloatArrayValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new PrimitiveFloatArrayValidatorImpl(scope, this, name, (float[]) value);
+ return new PrimitiveFloatArrayValidatorImpl(scope, configuration, name, (float[]) value, context,
+ failures);
}
@Override
public PrimitiveDoubleArrayValidator isDoubleArray()
{
if (hasFailed())
- return new PrimitiveDoubleArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveDoubleArrayValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -479,16 +453,17 @@ else if (!(value instanceof double[]))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, double[].class).
toString());
- return new PrimitiveDoubleArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveDoubleArrayValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new PrimitiveDoubleArrayValidatorImpl(scope, this, name, (double[]) value);
+ return new PrimitiveDoubleArrayValidatorImpl(scope, configuration, name, (double[]) value, context,
+ failures);
}
@Override
public PrimitiveBooleanArrayValidator isBooleanArray()
{
if (hasFailed())
- return new PrimitiveBooleanArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveBooleanArrayValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -499,16 +474,17 @@ else if (!(value instanceof boolean[]))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, boolean[].class).
toString());
- return new PrimitiveBooleanArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveBooleanArrayValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new PrimitiveBooleanArrayValidatorImpl(scope, this, name, (boolean[]) value);
+ return new PrimitiveBooleanArrayValidatorImpl(scope, configuration, name, (boolean[]) value, context,
+ failures);
}
@Override
public PrimitiveCharacterArrayValidator isCharArray()
{
if (hasFailed())
- return new PrimitiveCharacterArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveCharacterArrayValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -519,16 +495,17 @@ else if (!(value instanceof char[]))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, char[].class).
toString());
- return new PrimitiveCharacterArrayValidatorImpl(scope, this, name, null);
+ return new PrimitiveCharacterArrayValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new PrimitiveCharacterArrayValidatorImpl(scope, this, name, (char[]) value);
+ return new PrimitiveCharacterArrayValidatorImpl(scope, configuration, name, (char[]) value, context,
+ failures);
}
@Override
public ObjectArrayValidator, ?> isObjectArray()
{
if (hasFailed())
- return new ObjectArrayValidatorImpl<>(scope, this, name, null);
+ return new ObjectArrayValidatorImpl<>(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -539,16 +516,16 @@ else if (!(value instanceof Object[]))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Object[].class).
toString());
- return new ObjectArrayValidatorImpl<>(scope, this, name, null);
+ return new ObjectArrayValidatorImpl<>(scope, configuration, name, null, context, failures);
}
- return new ObjectArrayValidatorImpl<>(scope, this, name, (Object[]) value);
+ return new ObjectArrayValidatorImpl<>(scope, configuration, name, (Object[]) value, context, failures);
}
@Override
public MapValidator, ?, ? extends Map, ?>> isMap()
{
if (hasFailed())
- return new MapValidatorImpl<>(scope, this, name, null);
+ return new MapValidatorImpl<>(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -559,16 +536,16 @@ else if (!(value instanceof Map, ?>))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Map.class).
toString());
- return new MapValidatorImpl<>(scope, this, name, null);
+ return new MapValidatorImpl<>(scope, configuration, name, null, context, failures);
}
- return new MapValidatorImpl<>(scope, this, name, (Map, ?>) value);
+ return new MapValidatorImpl<>(scope, configuration, name, (Map, ?>) value, context, failures);
}
@Override
public PathValidator isPath()
{
if (hasFailed())
- return new PathValidatorImpl(scope, this, name, null);
+ return new PathValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -579,16 +556,16 @@ else if (!(value instanceof Path))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Path.class).
toString());
- return new PathValidatorImpl(scope, this, name, null);
+ return new PathValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new PathValidatorImpl(scope, this, name, (Path) value);
+ return new PathValidatorImpl(scope, configuration, name, (Path) value, context, failures);
}
@Override
public StringValidatorImpl isString()
{
if (hasFailed())
- return new StringValidatorImpl(scope, this, name, null);
+ return new StringValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -599,16 +576,16 @@ else if (!(value instanceof String))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, String.class).
toString());
- return new StringValidatorImpl(scope, this, name, null);
+ return new StringValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new StringValidatorImpl(scope, this, name, (String) value);
+ return new StringValidatorImpl(scope, configuration, name, (String) value, context, failures);
}
@Override
public UriValidatorImpl isUri()
{
if (hasFailed())
- return new UriValidatorImpl(scope, this, name, null);
+ return new UriValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -619,16 +596,16 @@ else if (!(value instanceof URI))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, URI.class).
toString());
- return new UriValidatorImpl(scope, this, name, null);
+ return new UriValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new UriValidatorImpl(scope, this, name, (URI) value);
+ return new UriValidatorImpl(scope, configuration, name, (URI) value, context, failures);
}
@Override
public UrlValidatorImpl isUrl()
{
if (hasFailed())
- return new UrlValidatorImpl(scope, this, name, null);
+ return new UrlValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -639,16 +616,16 @@ else if (!(value instanceof URL))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, URL.class).
toString());
- return new UrlValidatorImpl(scope, this, name, null);
+ return new UrlValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new UrlValidatorImpl(scope, this, name, (URL) value);
+ return new UrlValidatorImpl(scope, configuration, name, (URL) value, context, failures);
}
@Override
public ClassValidatorImpl> isClass()
{
if (hasFailed())
- return new ClassValidatorImpl<>(scope, this, name, null);
+ return new ClassValidatorImpl<>(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -659,16 +636,16 @@ else if (!(value instanceof Class>))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Class.class).
toString());
- return new ClassValidatorImpl<>(scope, this, name, null);
+ return new ClassValidatorImpl<>(scope, configuration, name, null, context, failures);
}
- return new ClassValidatorImpl<>(scope, this, name, (Class>) value);
+ return new ClassValidatorImpl<>(scope, configuration, name, (Class>) value, context, failures);
}
@Override
public OptionalValidator> isOptional()
{
if (hasFailed())
- return new OptionalValidatorImpl<>(scope, this, name, null);
+ return new OptionalValidatorImpl<>(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -679,16 +656,16 @@ else if (!(value instanceof Optional>))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, Optional.class).
toString());
- return new OptionalValidatorImpl<>(scope, this, name, null);
+ return new OptionalValidatorImpl<>(scope, configuration, name, null, context, failures);
}
- return new OptionalValidatorImpl<>(scope, this, name, (Optional>) value);
+ return new OptionalValidatorImpl<>(scope, configuration, name, (Optional>) value, context, failures);
}
@Override
public InetAddressValidatorImpl isInetAddress()
{
if (hasFailed())
- return new InetAddressValidatorImpl(scope, this, name, null);
+ return new InetAddressValidatorImpl(scope, configuration, name, null, context, failures);
else if (value == null)
{
addNullPointerException(
@@ -699,8 +676,8 @@ else if (!(value instanceof InetAddress))
addIllegalArgumentException(
ObjectMessages.isInstanceOf(scope, this, this.name, value, true, InetAddress.class).
toString());
- return new InetAddressValidatorImpl(scope, this, name, null);
+ return new InetAddressValidatorImpl(scope, configuration, name, null, context, failures);
}
- return new InetAddressValidatorImpl(scope, this, name, (InetAddress) value);
+ return new InetAddressValidatorImpl(scope, configuration, name, (InetAddress) value, context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/OptionalValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/OptionalValidatorImpl.java
index 72a41bd4d..b4a465baf 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/OptionalValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/OptionalValidatorImpl.java
@@ -12,8 +12,6 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.OptionalValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -22,42 +20,6 @@
public final class OptionalValidatorImpl extends AbstractObjectValidator, Optional>
implements OptionalValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public OptionalValidatorImpl(ApplicationScope scope, AbstractValidator> validator,
- String name, Optional value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public OptionalValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, Optional value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -70,7 +32,7 @@ public OptionalValidatorImpl(ApplicationScope scope, Configuration configuration
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private OptionalValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ public OptionalValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
Optional value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PathValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PathValidatorImpl.java
index 7c321f19b..cde7c35e1 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PathValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PathValidatorImpl.java
@@ -17,50 +17,12 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class PathValidatorImpl extends AbstractObjectValidator
implements PathValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PathValidatorImpl(ApplicationScope scope, AbstractValidator> validator,
- String name, Path value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PathValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, Path value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -73,8 +35,8 @@ public PathValidatorImpl(ApplicationScope scope, Configuration configuration,
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private PathValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- Path value, Map context, List failures)
+ public PathValidatorImpl(ApplicationScope scope, Configuration configuration, String name, Path value,
+ Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveBooleanArrayValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveBooleanArrayValidatorImpl.java
index 62e19809e..14c4cfece 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveBooleanArrayValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveBooleanArrayValidatorImpl.java
@@ -8,9 +8,7 @@
import com.github.cowwoc.requirements.java.internal.util.Arrays;
import com.github.cowwoc.requirements.java.type.PrimitiveBooleanArrayValidator;
-import java.util.ArrayList;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -20,42 +18,6 @@ public final class PrimitiveBooleanArrayValidatorImpl
extends AbstractArrayValidator
implements PrimitiveBooleanArrayValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveBooleanArrayValidatorImpl(ApplicationScope scope, AbstractValidator> validator,
- String name, boolean[] value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveBooleanArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, boolean[] value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(4), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -68,8 +30,8 @@ public PrimitiveBooleanArrayValidatorImpl(ApplicationScope scope, Configuration
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private PrimitiveBooleanArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, boolean[] value, Map context, List failures)
+ public PrimitiveBooleanArrayValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ boolean[] value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveBooleanValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveBooleanValidatorImpl.java
index 248a64ddf..0c3b4def4 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveBooleanValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveBooleanValidatorImpl.java
@@ -7,8 +7,6 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.PrimitiveBooleanValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -17,42 +15,6 @@ public final class PrimitiveBooleanValidatorImpl extends AbstractValidator validator, String name,
- boolean value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveBooleanValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, boolean value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -65,8 +27,8 @@ public PrimitiveBooleanValidatorImpl(ApplicationScope scope, Configuration confi
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private PrimitiveBooleanValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, boolean value, Map context, List failures)
+ public PrimitiveBooleanValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ boolean value, Map context, List failures)
{
super(scope, configuration, name, context, failures);
this.value = value;
@@ -164,6 +126,7 @@ private PrimitiveBooleanValidator isNotEqualToImpl(boolean unwanted, String name
@Override
public StringValidatorImpl asString()
{
- return new StringValidatorImpl(scope, this, "String.valueOf(" + name + ")", String.valueOf(value));
+ return new StringValidatorImpl(scope, configuration, "String.valueOf(" + name + ")",
+ String.valueOf(value), context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveByteArrayValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveByteArrayValidatorImpl.java
index 346282a2c..ed67dc463 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveByteArrayValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveByteArrayValidatorImpl.java
@@ -8,9 +8,7 @@
import com.github.cowwoc.requirements.java.internal.util.Arrays;
import com.github.cowwoc.requirements.java.type.PrimitiveByteArrayValidator;
-import java.util.ArrayList;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -20,42 +18,6 @@ public final class PrimitiveByteArrayValidatorImpl
extends AbstractArrayValidator
implements PrimitiveByteArrayValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveByteArrayValidatorImpl(ApplicationScope scope, AbstractValidator> validator, String name,
- byte[] value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveByteArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, byte[] value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(4), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -68,8 +30,8 @@ public PrimitiveByteArrayValidatorImpl(ApplicationScope scope, Configuration con
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private PrimitiveByteArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, byte[] value, Map context, List failures)
+ public PrimitiveByteArrayValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ byte[] value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveByteValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveByteValidatorImpl.java
index 5dd79d8d5..fc1c059ca 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveByteValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveByteValidatorImpl.java
@@ -8,8 +8,6 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.PrimitiveByteValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -18,42 +16,6 @@ public final class PrimitiveByteValidatorImpl extends AbstractValidator validator, String name,
- byte value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveByteValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
- byte value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -66,7 +28,7 @@ public PrimitiveByteValidatorImpl(ApplicationScope scope, Configuration configur
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private PrimitiveByteValidatorImpl(ApplicationScope scope, Configuration configuration,
+ public PrimitiveByteValidatorImpl(ApplicationScope scope, Configuration configuration,
String name, byte value, Map context, List failures)
{
super(scope, configuration, name, context, failures);
@@ -470,6 +432,7 @@ private boolean maximumFailed(byte maximum, boolean maximumInclusive)
@Override
public StringValidatorImpl asString()
{
- return new StringValidatorImpl(scope, this, "String.valueOf(" + name + ")", String.valueOf(value));
+ return new StringValidatorImpl(scope, configuration, "String.valueOf(" + name + ")",
+ String.valueOf(value), context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveCharacterArrayValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveCharacterArrayValidatorImpl.java
index 58cb1fed8..cd38da319 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveCharacterArrayValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveCharacterArrayValidatorImpl.java
@@ -8,9 +8,7 @@
import com.github.cowwoc.requirements.java.internal.util.Arrays;
import com.github.cowwoc.requirements.java.type.PrimitiveCharacterArrayValidator;
-import java.util.ArrayList;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -20,43 +18,6 @@ public final class PrimitiveCharacterArrayValidatorImpl
extends AbstractArrayValidator
implements PrimitiveCharacterArrayValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveCharacterArrayValidatorImpl(ApplicationScope scope, AbstractValidator> validator,
- String name,
- char[] value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveCharacterArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, char[] value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(4), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -69,7 +30,7 @@ public PrimitiveCharacterArrayValidatorImpl(ApplicationScope scope, Configuratio
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private PrimitiveCharacterArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
+ public PrimitiveCharacterArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
String name, char[] value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveCharacterValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveCharacterValidatorImpl.java
index cf5f17469..06d87a991 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveCharacterValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveCharacterValidatorImpl.java
@@ -7,8 +7,6 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.PrimitiveCharacterValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -17,42 +15,6 @@ public final class PrimitiveCharacterValidatorImpl extends AbstractValidator validator, String name,
- char value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveCharacterValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, char value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -65,8 +27,8 @@ public PrimitiveCharacterValidatorImpl(ApplicationScope scope, Configuration con
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private PrimitiveCharacterValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, char value, Map context, List failures)
+ public PrimitiveCharacterValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ char value, Map context, List failures)
{
super(scope, configuration, name, context, failures);
this.value = value;
@@ -305,6 +267,7 @@ private boolean maximumFailed(char maximum, boolean maximumInclusive)
@Override
public StringValidatorImpl asString()
{
- return new StringValidatorImpl(scope, this, "String.valueOf(" + name + ")", String.valueOf(value));
+ return new StringValidatorImpl(scope, configuration, "String.valueOf(" + name + ")",
+ String.valueOf(value), context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveDoubleArrayValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveDoubleArrayValidatorImpl.java
index 304a9922f..485ffc518 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveDoubleArrayValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveDoubleArrayValidatorImpl.java
@@ -8,9 +8,7 @@
import com.github.cowwoc.requirements.java.internal.util.Arrays;
import com.github.cowwoc.requirements.java.type.PrimitiveDoubleArrayValidator;
-import java.util.ArrayList;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -20,42 +18,6 @@ public final class PrimitiveDoubleArrayValidatorImpl
extends AbstractArrayValidator
implements PrimitiveDoubleArrayValidator
{
- /**
- * Creates a new validator as a result of a validation.
- *
- * @param scope the application configuration
- * @param validator the validator
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveDoubleArrayValidatorImpl(ApplicationScope scope, AbstractValidator> validator,
- String name, double[] value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveDoubleArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, double[] value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(4), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -68,8 +30,8 @@ public PrimitiveDoubleArrayValidatorImpl(ApplicationScope scope, Configuration c
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private PrimitiveDoubleArrayValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, double[] value, Map context, List failures)
+ public PrimitiveDoubleArrayValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ double[] value, Map context, List failures)
{
super(scope, configuration, name, value, context, failures);
}
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveDoubleValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveDoubleValidatorImpl.java
index 75ade1828..7c2f7073f 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveDoubleValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveDoubleValidatorImpl.java
@@ -8,8 +8,6 @@
import com.github.cowwoc.requirements.java.internal.scope.ApplicationScope;
import com.github.cowwoc.requirements.java.type.PrimitiveDoubleValidator;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -18,42 +16,6 @@ public final class PrimitiveDoubleValidatorImpl extends AbstractValidator validator, String name,
- double value)
- {
- this(scope, validator.configuration(), name, value, validator.context, validator.failures);
- }
-
- /**
- * Creates a new validator.
- *
- * @param scope the application configuration
- * @param configuration the validator configuration
- * @param name the name of the value
- * @param value (optional) the value
- * @throws NullPointerException if {@code name} is null
- * @throws IllegalArgumentException if {@code name} contains leading or trailing whitespace, or is empty
- * @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
- * leading or trailing whitespace, or is empty.
- */
- public PrimitiveDoubleValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, double value)
- {
- this(scope, configuration, name, value, HashMap.newHashMap(2), new ArrayList<>(1));
- }
-
/**
* @param scope the application configuration
* @param configuration the validator configuration
@@ -66,8 +28,8 @@ public PrimitiveDoubleValidatorImpl(ApplicationScope scope, Configuration config
* @throws AssertionError if any of the mandatory arguments are null. If {@code name} contains
* leading or trailing whitespace, or is empty.
*/
- private PrimitiveDoubleValidatorImpl(ApplicationScope scope, Configuration configuration,
- String name, double value, Map context, List failures)
+ public PrimitiveDoubleValidatorImpl(ApplicationScope scope, Configuration configuration, String name,
+ double value, Map context, List failures)
{
super(scope, configuration, name, context, failures);
this.value = value;
@@ -577,6 +539,7 @@ private boolean maximumFailed(double maximum, boolean maximumInclusive)
@Override
public StringValidatorImpl asString()
{
- return new StringValidatorImpl(scope, this, "String.valueOf(" + name + ")", String.valueOf(value));
+ return new StringValidatorImpl(scope, configuration, "String.valueOf(" + name + ")",
+ String.valueOf(value), context, failures);
}
}
\ No newline at end of file
diff --git a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveFloatArrayValidatorImpl.java b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveFloatArrayValidatorImpl.java
index 2fa802a24..648fbcd03 100644
--- a/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveFloatArrayValidatorImpl.java
+++ b/java/src/main/java/com/github/cowwoc/requirements/java/internal/implementation/PrimitiveFloatArrayValidatorImpl.java
@@ -8,9 +8,7 @@
import com.github.cowwoc.requirements.java.internal.util.Arrays;
import com.github.cowwoc.requirements.java.type.PrimitiveFloatArrayValidator;
-import java.util.ArrayList;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -20,42 +18,6 @@ public final class PrimitiveFloatArrayValidatorImpl
extends AbstractArrayValidator