|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.mit.jverbnet.util.Checks
public class Checks
Utilities for checking variables.
Nested Class Summary | |
---|---|
static class |
Checks.Check<S>
Abstract implementation of a check. |
static class |
Checks.Condition<S>
Abstract implementation of a condition. |
static interface |
Checks.ICheck<S>
A check object provides the ability to throw an exception when a specified object satisfies the condition. |
static interface |
Checks.ICondition<S>
A condition object defines a boolean condition over a set of objects. |
static interface |
Checks.IMask<S>
A mask object provides the ability to substitute different values for a specified object if it matches the condition. |
static interface |
Checks.IReallocationStrategy
A reallocation strategy defines if and how a collection should be reallocated. |
static class |
Checks.Mask<S>
Abstract implementation of a mask. |
Field Summary | |
---|---|
static Checks.IReallocationStrategy |
DoNotReallocate
A reallocation strategy that does nothing. |
static java.lang.String |
genericVarName
The default variable name to use in the exceptions thrown by this class, if the specific variable name is null, empty, or all whitespace. |
static Checks.Mask<java.lang.String> |
IsBlank
A mask/check with that deals with strings. |
static Checks.Mask<java.lang.String> |
IsEmpty
A mask/check with that deals with strings. |
static Checks.Mask<java.util.Collection<?>> |
IsEmptyCol
A mask/check object that deals with collections. |
static Checks.Mask<java.lang.String> |
IsEmptyOrBlank
A mask/check with that deals with strings. |
static Checks.Mask<java.lang.Object> |
IsNull
A mask/check with that deals with objects. |
static Checks.Mask<java.lang.String> |
IsNullEmptyOrBlank
A mask/check with that deals with strings. |
static Checks.Mask<java.lang.String> |
IsNullOrBlank
A mask/check with that deals with strings. |
static Checks.Mask<java.lang.String> |
IsNullOrEmpty
A mask/check with that deals with strings. |
static Checks.Mask<java.util.Collection<?>> |
IsNullOrEmptyCol
A mask/check object that deals with collections. |
static Checks.IReallocationStrategy |
ModifiableLeaveNulls
Reallocates collections as modifiable collections. |
static Checks.IReallocationStrategy |
ModifiableMaskNullWithEmpty
Reallocates collections as modifiable collections. |
static Checks.Mask<java.lang.String> |
NotBlank
A mask/check with that deals with strings. |
static Checks.Mask<java.lang.String> |
NotEmpty
A mask/check with that deals with strings. |
static Checks.Mask<java.util.Collection<?>> |
NotEmptyCol
A mask/check object that deals with collections. |
static Checks.Mask<java.lang.String> |
NotEmptyOrBlank
A mask/check with that deals with strings. |
static Checks.Mask<java.lang.Object> |
NotNull
A mask/check with that deals with objects. |
static Checks.Mask<java.lang.String> |
NotNullEmptyOrBlank
A mask/check with that deals with strings. |
static Checks.Mask<java.lang.String> |
NotNullOrBlank
A mask/check with that deals with strings. |
static Checks.Mask<java.lang.String> |
NotNullOrEmpty
A mask/check with that deals with strings. |
static Checks.Mask<java.util.Collection<?>> |
NotNullOrEmptyCol
A mask/check object that deals with collections. |
static Checks.IReallocationStrategy |
UnmodifiableLeaveNulls
Reallocates collections as unmodifiable collections. |
static Checks.IReallocationStrategy |
UnmodifiableMaskNullWithEmpty
Reallocates collections as unmodifiable collections. |
Constructor Summary | |
---|---|
Checks()
|
Method Summary | ||
---|---|---|
static
|
allElementsAre(Checks.ICheck<S> test,
java.lang.String varName,
java.util.List<E> list,
Checks.IReallocationStrategy r)
Runs the check object over all elements in the list. |
|
static
|
allElementsAre(Checks.ICheck<S> test,
java.lang.String varName,
java.util.Set<E> set,
Checks.IReallocationStrategy r)
Runs the check object over all elements in the set. |
|
static
|
allElementsAre(Checks.ICheck<S> test,
java.lang.String varName,
java.util.SortedSet<E> set,
Checks.IReallocationStrategy r)
Runs the check object over all elements in the set. |
|
static
|
allKeysAndValuesAre(Checks.ICheck<S> test,
java.lang.String varName,
java.util.Map<K,V> map,
Checks.IReallocationStrategy r)
Runs the check object over all keys and values in the map. |
|
static
|
allKeysAndValuesAre(Checks.ICheck<S> test,
java.lang.String varName,
java.util.SortedMap<K,V> map,
Checks.IReallocationStrategy r)
Runs the check object over all keys and values in the map. |
|
static
|
allKeysAre(Checks.ICheck<S> test,
java.lang.String varName,
java.util.Map<K,V> map,
Checks.IReallocationStrategy r)
Runs the check object over all keys in the map. |
|
static
|
allKeysAre(Checks.ICheck<S> test,
java.lang.String varName,
java.util.SortedMap<K,V> map,
Checks.IReallocationStrategy r)
Runs the check object over all keys in the map. |
|
static
|
allValuesAre(Checks.ICheck<S> test,
java.lang.String varName,
java.util.Map<K,V> map,
Checks.IReallocationStrategy r)
Runs the check object over all values in the map. |
|
static
|
allValuesAre(Checks.ICheck<V> test,
java.lang.String varName,
java.util.SortedMap<K,V> map,
Checks.IReallocationStrategy r)
Runs the check object over all values in the map. |
|
static
|
isNull()
Returns an IsNull mask object cast to the appropriate type. |
|
static Checks.Mask<java.util.Collection<?>> |
maxSizeAndNotNull(int size)
Returns a mask object whose condition is that the collection be non- null and have a size less than or equal to the specified
size. |
|
static Checks.Mask<java.util.Collection<?>> |
minSizeAndNotNull(int size)
Returns a mask object whose condition is that the collection be non- null and have a size equal to or greater than the specified
size. |
|
static java.lang.String |
normalizeVarName(java.lang.String varName)
Normalizes a variable name to either a trimmed version of itself, or returns the generic variable name. |
|
static
|
notNull()
Returns a NotNull mask object cast to the appropriate type. |
|
static
|
thisLineShouldNeverBeCalled()
Throws an exception if called. |
|
static
|
thisMethodShouldNeverBeCalled()
Throws an exception if called. |
|
static java.lang.String |
trim(Checks.ICondition<java.lang.Object> test,
java.lang.String value)
Trims the string if it matches the condition. |
|
static java.lang.String |
trimAndMask(Checks.ICondition<java.lang.Object> test,
java.lang.String value,
Checks.IMask<java.lang.String> mask,
java.lang.String maskValue)
First trims the string if it matches the condition, then applies the mask to the resulting value. |
|
static java.lang.String |
trimAndMaskNull(java.lang.String value,
java.lang.String maskValue)
Convenience implementation of the most common use case of the trimAndMask(ICondition, String, IMask, String) method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String genericVarName
public static final Checks.Mask<java.lang.Object> NotNull
public static final Checks.Mask<java.lang.Object> IsNull
public static final Checks.Mask<java.lang.String> IsEmpty
null
and of length zero.
public static final Checks.Mask<java.lang.String> IsBlank
null
, greater than length
zero, and all whitespace.
If the Checks.ICheck.check(String, Object)
method returns, it returns
the original string.
public static final Checks.Mask<java.lang.String> IsNullOrEmpty
null
or of length zero.
public static final Checks.Mask<java.lang.String> IsNullOrBlank
null
or
greater than length zero and contains only whitespace.
public static final Checks.Mask<java.lang.String> IsEmptyOrBlank
public static final Checks.Mask<java.lang.String> IsNullEmptyOrBlank
public static final Checks.Mask<java.lang.String> NotEmpty
Checks.ICheck.check(String, Object)
method returns, it returns a
trimmed version of the original string, or null
if the
original value was null
.
public static final Checks.Mask<java.lang.String> NotBlank
Checks.ICheck.check(String, Object)
method returns, it returns a
trimmed version of the original string, or null
if the
original value was null
.
public static final Checks.Mask<java.lang.String> NotNullOrEmpty
Checks.ICheck.check(String, Object)
method returns, it returns a
trimmed version of the original string.
public static final Checks.Mask<java.lang.String> NotNullOrBlank
Checks.ICheck.check(String, Object)
method returns, it returns a
trimmed version of the original string.
public static final Checks.Mask<java.lang.String> NotEmptyOrBlank
Checks.ICheck.check(String, Object)
method returns, it returns a
trimmed version of the original string, or null
if the
original value was null
.
public static final Checks.Mask<java.lang.String> NotNullEmptyOrBlank
Checks.ICheck.check(String, Object)
method returns, it returns a
trimmed version of the original string, or null
if the
original value was null
.
public static final Checks.Mask<java.util.Collection<?>> IsEmptyCol
null
and of size zero.
public static final Checks.Mask<java.util.Collection<?>> IsNullOrEmptyCol
null
or of
size zero.
public static final Checks.Mask<java.util.Collection<?>> NotEmptyCol
null
collection
is not considered of size zero.
public static final Checks.Mask<java.util.Collection<?>> NotNullOrEmptyCol
null
and have at least one element.
public static final Checks.IReallocationStrategy DoNotReallocate
public static final Checks.IReallocationStrategy ModifiableLeaveNulls
null
collections are passed back as null
s.
public static final Checks.IReallocationStrategy UnmodifiableLeaveNulls
null
collections are passed back as null
s.
public static final Checks.IReallocationStrategy ModifiableMaskNullWithEmpty
null
collections are passed back as modifiable empty collections.
public static final Checks.IReallocationStrategy UnmodifiableMaskNullWithEmpty
null
collections are passed back as unmodifiable empty collections.
Constructor Detail |
---|
public Checks()
Method Detail |
---|
public static java.lang.String normalizeVarName(java.lang.String varName)
varName
- the variable name to normalized
public static <T> Checks.Mask<T> notNull()
public static <T> Checks.Mask<T> isNull()
public static java.lang.String trim(Checks.ICondition<java.lang.Object> test, java.lang.String value)
test
- the condition to test; if the condition object is null, the
NotNull
object is used.value
- the string to test
null
, if the original string was null
);
otherwise the original objectpublic static java.lang.String trimAndMask(Checks.ICondition<java.lang.Object> test, java.lang.String value, Checks.IMask<java.lang.String> mask, java.lang.String maskValue)
test
- the condition to test; if the condition object is null, the
NotNull
object is used.value
- the string to testmask
- the mask to apply to the trimmed stringmaskValue
- the mask value to substitute if necessary
public static java.lang.String trimAndMaskNull(java.lang.String value, java.lang.String maskValue)
trimAndMask(ICondition, String, IMask, String)
method.
value
- the value to be trimmed then maskedmaskValue
- the mask value
null
public static final Checks.Mask<java.util.Collection<?>> minSizeAndNotNull(int size)
null
and have a size equal to or greater than the specified
size.
size
- the minimum size of the collection
null
and have a size equal to or greater than the
specified sizepublic static final Checks.Mask<java.util.Collection<?>> maxSizeAndNotNull(int size)
null
and have a size less than or equal to the specified
size.
size
- the maximum size of the collection
null
and have a size less than or equal to the
specified sizepublic static <S,E extends S> java.util.List<E> allElementsAre(Checks.ICheck<S> test, java.lang.String varName, java.util.List<E> list, Checks.IReallocationStrategy r)
null
, meaning the DoNotReallocate
strategy is used.
test
- the test to be appliedvarName
- the variable name to be used in the exception message; if the
name is null
, empty, or all whitespace, the
generic variable name is used.list
- the list to checkr
- the reallocation strategy to use; if null
, the
DoNotReallocate strategy is used
public static <S,E extends S> java.util.Set<E> allElementsAre(Checks.ICheck<S> test, java.lang.String varName, java.util.Set<E> set, Checks.IReallocationStrategy r)
null
, meaning the DoNotReallocate
strategy is used.
test
- the test to be appliedvarName
- the variable name to be used in the exception message; if the
name is null
, empty, or all whitespace, the
generic variable name is used.set
- the set to checkr
- the reallocation strategy to use; if null
, the
DoNotReallocate strategy is used
public static <S,E extends S> java.util.SortedSet<E> allElementsAre(Checks.ICheck<S> test, java.lang.String varName, java.util.SortedSet<E> set, Checks.IReallocationStrategy r)
null
, meaning the DoNotReallocate
strategy is used.
test
- the test to be appliedvarName
- the variable name to be used in the exception message; if the
name is null
, empty, or all whitespace, the
generic variable name is used.set
- the set to checkr
- the reallocation strategy to use; if null
, the
DoNotReallocate strategy is used
public static <S,K extends S,V> java.util.Map<K,V> allKeysAre(Checks.ICheck<S> test, java.lang.String varName, java.util.Map<K,V> map, Checks.IReallocationStrategy r)
null
, meaning the DoNotReallocate
strategy is used.
test
- the test to be appliedvarName
- the variable name to be used in the exception message; if the
name is null
, empty, or all whitespace, the
generic variable name is used.map
- the map to checkr
- the reallocation strategy to use; if null
, the
DoNotReallocate strategy is used
public static <S,K extends S,V> java.util.SortedMap<K,V> allKeysAre(Checks.ICheck<S> test, java.lang.String varName, java.util.SortedMap<K,V> map, Checks.IReallocationStrategy r)
null
, meaning the DoNotReallocate
strategy is used.
test
- the test to be appliedvarName
- the variable name to be used in the exception message; if the
name is null
, empty, or all whitespace, the
generic variable name is used.map
- the map to checkr
- the reallocation strategy to use; if null
, the
DoNotReallocate strategy is used
public static <S,K,V extends S> java.util.Map<K,V> allValuesAre(Checks.ICheck<S> test, java.lang.String varName, java.util.Map<K,V> map, Checks.IReallocationStrategy r)
null
, meaning the DoNotReallocate
strategy is used.
test
- the test to be appliedvarName
- the variable name to be used in the exception message; if the
name is null
, empty, or all whitespace, the
generic variable name is used.map
- the map to checkr
- the reallocation strategy to use; if null
, the
DoNotReallocate strategy is used
public static <S,K,V extends S> java.util.SortedMap<K,V> allValuesAre(Checks.ICheck<V> test, java.lang.String varName, java.util.SortedMap<K,V> map, Checks.IReallocationStrategy r)
null
, meaning the DoNotReallocate
strategy is used.
test
- the test to be appliedvarName
- the variable name to be used in the exception message; if the
name is null
, empty, or all whitespace, the
generic variable name is used.map
- the map to checkr
- the reallocation strategy to use; if null
, the
DoNotReallocate strategy is used
public static <S,K extends S,V extends S> java.util.Map<K,V> allKeysAndValuesAre(Checks.ICheck<S> test, java.lang.String varName, java.util.Map<K,V> map, Checks.IReallocationStrategy r)
null
, meaning the DoNotReallocate
strategy is used.
test
- the test to be appliedvarName
- the variable name to be used in the exception message; if the
name is null
, empty, or all whitespace, the
generic variable name is used.map
- the map to checkr
- the reallocation strategy to use; if null
, the
DoNotReallocate strategy is used
public static <S,K extends S,V extends S> java.util.SortedMap<K,V> allKeysAndValuesAre(Checks.ICheck<S> test, java.lang.String varName, java.util.SortedMap<K,V> map, Checks.IReallocationStrategy r)
null
, meaning the DoNotReallocate
strategy is used.
test
- the test to be appliedvarName
- the variable name to be used in the exception message; if the
name is null
, empty, or all whitespace, the
generic variable name is used.map
- the map to checkr
- the reallocation strategy to use; if null
, the
DoNotReallocate strategy is used
public static <T> T thisMethodShouldNeverBeCalled()
java.lang.IllegalStateException
- if this method is calledpublic static <T> T thisLineShouldNeverBeCalled() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if this method is called
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |