com.googlecode.jbp.common.requirements
Class AbstractRequirements

java.lang.Object
  extended by com.googlecode.jbp.common.requirements.AbstractRequirements
All Implemented Interfaces:
IRequirements
Direct Known Subclasses:
ParamRequirements, PostCondition, PreCondition, Requirements

public abstract class AbstractRequirements
extends Object
implements IRequirements

Abstract implementation of IRequirements which provides the checks but not the action that has to be taken if a condition is not met. All methods that accept a vararg String... parameter will concatenate all elements of this array to each other and to the default message associated to the check and then transmit this String to the conditionNotMet methods. Thus, the user of these methods may specify additional information.

Author:
Yannick LOTH - yannick AT littlej.biz -

Constructor Summary
AbstractRequirements()
           
 
Method Summary
protected abstract  void onConditionNotMet(String messageParam)
          Called if a condition is not met.
<T extends Collection<?>>
T
requireAllInstanceOf(T collParam, Class<?> klassParam, String... messagesParam)
          Checks that all elements of the specified collection are instances of the specified class.
 boolean requireConjunction(boolean... predicatesParam)
          Requires that all predicates are true.
 File requireDirectory(File fileParam, String... messagesParam)
          Checks that the specified File instance refers to a directory.
 String requireDirectory(String filePathParam, String... messagesParam)
          Checks that the specified String instance is a path that refers to a directory.
 boolean requireDisjunction(boolean... predicatesParam)
          Checks that there is a disjunction between the specified predicates.
 boolean requireExclusiveDisjunction(boolean firstPredicateParam, boolean secondPredicateParam)
          Checks that there is a disjunction between the two specified predicates.
 File requireExistingFile(File fileParam, String... messagesParam)
          Checks that the specified File instance refers to an existing file.
 String requireExistingFile(String filePathParam, String... messagesParam)
          Checks that the specified String instance is a path that refers to an existing file.
 boolean requireFalse(boolean boolParam, String... messagesParam)
          Checks that the specified expression returns false.
 Calendar requireFutureInstant(Calendar calendarParam, String... messagesParam)
           
 Date requireFutureInstant(Date dateParam, String... messagesParam)
           
<T> T
requireInstanceOf(T objParam, Class<?> klassParam, String... messagesParam)
          Checks that the specified object is an instance of the specified class.
 Object[] requireNotAllSimultaneouslyNull(Object... objectsParam)
          Checks that at least one reference is not null.
<T extends Collection<?>>
T
requireNotAllSimultaneouslyNull(T coll, String... messagesParam)
          Checks that at least one of the specified objects is not null.
 String requireNotBlank(String strParam, String... messagesParam)
          Checks that a string object is not blank (null or empty or only spaces).
<T extends Collection<?>>
T
requireNotEmpty(T collParam, String... messagesParam)
          Checks that a collection is not empty.
 File requireNotExistingFile(File fileParam, String... messagesParam)
          Checks that the specified File instance refers to a non existing file.
 String requireNotExistingFile(String filePathParam, String... messagesParam)
          Checks that the specified String instance is a path that refers to a non existing file.
<T extends Number>
T
requireNotNegative(T n, String... messagesParam)
          Checks that the specified number is not negative (<0).
<T extends Number>
T
requireNotNegativeNorZero(T n, String... messagesParam)
          Checks that the specified number is not negative (<0) nor zero (0).
<T> T
requireNotNull(T objParam, String... messagesParam)
          Checks that an object is not null.
<T extends Number>
T
requireNotPositive(T n, String... messagesParam)
          Checks that the specified number is not positive (>0).
<T extends Number>
T
requireNotPositiveNorZero(T n, String... messagesParam)
          Checks that the specified number is not positive (>0) nor zero (0).
<T extends Number>
T
requireNotZero(T n, String... messagesParam)
          Checks that the specified number is not zero (0).
<T> T
requireNull(T objParam, String... messagesParam)
          Checks that the specified object is null.
 Calendar requirePastInstant(Calendar calendarParam, String... messagesParam)
           
 Date requirePastInstant(Date dateParam, String... messagesParam)
           
 boolean requireTrue(boolean boolParam, String... messagesParam)
          Checks that the specified expression returns true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRequirements

public AbstractRequirements()
Method Detail

onConditionNotMet

protected abstract void onConditionNotMet(String messageParam)
Called if a condition is not met. Usually throws a RequirementException.

Parameters:
messageParam - The associated message.

requireAllInstanceOf

public final <T extends Collection<?>> T requireAllInstanceOf(T collParam,
                                                              Class<?> klassParam,
                                                              String... messagesParam)
Description copied from interface: IRequirements
Checks that all elements of the specified collection are instances of the specified class.

Specified by:
requireAllInstanceOf in interface IRequirements
Parameters:
collParam - The specified collection.
klassParam - The class which all specified collection's elements should be instances of.
messagesParam - Additional messages with more detail.

requireConjunction

public final boolean requireConjunction(boolean... predicatesParam)
Description copied from interface: IRequirements
Requires that all predicates are true. At least one predicate must be specified.

Specified by:
requireConjunction in interface IRequirements
Parameters:
predicatesParam - The specified predicates.
Returns:
true if all predicates are true.

requireDirectory

public final File requireDirectory(File fileParam,
                                   String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified File instance refers to a directory.

Specified by:
requireDirectory in interface IRequirements
Parameters:
fileParam - The specified file. Must not be null.
messagesParam - Additional messages with more detail.
Returns:
The specified file.

requireDirectory

public final String requireDirectory(String filePathParam,
                                     String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified String instance is a path that refers to a directory.

Specified by:
requireDirectory in interface IRequirements
Parameters:
filePathParam - The specified file path. Must not be blank.
messagesParam - Additional messages with more detail.
Returns:
The specified file path.

requireDisjunction

public final boolean requireDisjunction(boolean... predicatesParam)
Description copied from interface: IRequirements
Checks that there is a disjunction between the specified predicates. In case there is only one predicate, the disjunction is present if the predicate is true. Remember that the values of the predicates are calculated eagerly, before the execution of the method.

Specified by:
requireDisjunction in interface IRequirements
Parameters:
predicatesParam - The specified predicates.
Returns:
Returns true if at least one predicate is true.

requireExclusiveDisjunction

public final boolean requireExclusiveDisjunction(boolean firstPredicateParam,
                                                 boolean secondPredicateParam)
Description copied from interface: IRequirements
Checks that there is a disjunction between the two specified predicates.

Specified by:
requireExclusiveDisjunction in interface IRequirements
Parameters:
firstPredicateParam - The first predicate.
secondPredicateParam - The second predicate.
Returns:
Returns true if exactly one predicate is true.

requireExistingFile

public final File requireExistingFile(File fileParam,
                                      String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified File instance refers to an existing file.

Specified by:
requireExistingFile in interface IRequirements
Parameters:
fileParam - The specified file. Must not be null.
messagesParam - Additional messages with more detail.
Returns:
The specified file.

requireExistingFile

public final String requireExistingFile(String filePathParam,
                                        String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified String instance is a path that refers to an existing file.

Specified by:
requireExistingFile in interface IRequirements
Parameters:
filePathParam - The specified file path. Must not be blank.
messagesParam - Additional messages with more detail.
Returns:
The specified file path.

requireFalse

public final boolean requireFalse(boolean boolParam,
                                  String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified expression returns false.

Specified by:
requireFalse in interface IRequirements
Parameters:
boolParam - The expression.
messagesParam - additional messages with more detail.

requireFutureInstant

public final Calendar requireFutureInstant(Calendar calendarParam,
                                           String... messagesParam)
Specified by:
requireFutureInstant in interface IRequirements

requireFutureInstant

public final Date requireFutureInstant(Date dateParam,
                                       String... messagesParam)
Specified by:
requireFutureInstant in interface IRequirements

requireInstanceOf

public final <T> T requireInstanceOf(T objParam,
                                     Class<?> klassParam,
                                     String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified object is an instance of the specified class.

Specified by:
requireInstanceOf in interface IRequirements
Parameters:
objParam - The specified object.
klassParam - The class which the specified object should be an instance of.
messagesParam - additional messages with more detail.

requireNotAllSimultaneouslyNull

public final Object[] requireNotAllSimultaneouslyNull(Object... objectsParam)
Description copied from interface: IRequirements
Checks that at least one reference is not null.

Specified by:
requireNotAllSimultaneouslyNull in interface IRequirements
Parameters:
objectsParam - The references to objects that may be null.

requireNotAllSimultaneouslyNull

public final <T extends Collection<?>> T requireNotAllSimultaneouslyNull(T coll,
                                                                         String... messagesParam)
Description copied from interface: IRequirements
Checks that at least one of the specified objects is not null.

Specified by:
requireNotAllSimultaneouslyNull in interface IRequirements
Type Parameters:
T - The type of the collection of specified objects.
Parameters:
coll - The collection of specified objects.
messagesParam - additional messages with more detail.
Returns:
The collection of specified objects.

requireNotBlank

public final String requireNotBlank(String strParam,
                                    String... messagesParam)
Description copied from interface: IRequirements
Checks that a string object is not blank (null or empty or only spaces).

Specified by:
requireNotBlank in interface IRequirements
Parameters:
strParam - The string.
messagesParam - additional messages with more detail.

requireNotEmpty

public final <T extends Collection<?>> T requireNotEmpty(T collParam,
                                                         String... messagesParam)
Description copied from interface: IRequirements
Checks that a collection is not empty. The specified collection must not be null.

Specified by:
requireNotEmpty in interface IRequirements
Parameters:
collParam - The collection to check for emptyness.
messagesParam - additional messages with more detail.

requireNotExistingFile

public final File requireNotExistingFile(File fileParam,
                                         String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified File instance refers to a non existing file.

Specified by:
requireNotExistingFile in interface IRequirements
Parameters:
fileParam - The specified file. Must not be null.
messagesParam - Additional messages with more detail.
Returns:
The specified file.

requireNotExistingFile

public final String requireNotExistingFile(String filePathParam,
                                           String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified String instance is a path that refers to a non existing file.

Specified by:
requireNotExistingFile in interface IRequirements
Parameters:
filePathParam - The specified file path. Must not be blank.
messagesParam - Additional messages with more detail.
Returns:
The specified file path.

requireNotNegative

public final <T extends Number> T requireNotNegative(T n,
                                                     String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified number is not negative (<0).

Specified by:
requireNotNegative in interface IRequirements
Parameters:
n - The specified number.
messagesParam - additional messages with more detail.

requireNotNegativeNorZero

public final <T extends Number> T requireNotNegativeNorZero(T n,
                                                            String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified number is not negative (<0) nor zero (0).

Specified by:
requireNotNegativeNorZero in interface IRequirements
Parameters:
n - The specified number.
messagesParam - additional messages with more detail.

requireNotNull

public final <T> T requireNotNull(T objParam,
                                  String... messagesParam)
Description copied from interface: IRequirements
Checks that an object is not null. Example:

 public Foo(Bar bar) {
     this.bar = Objects.requireNotNull(bar);
 }
 

Specified by:
requireNotNull in interface IRequirements
Type Parameters:
T - type of the object.
Parameters:
objParam - The object.
messagesParam - additional messages with more detail.

requireNotPositive

public final <T extends Number> T requireNotPositive(T n,
                                                     String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified number is not positive (>0).

Specified by:
requireNotPositive in interface IRequirements
Parameters:
n - The specified number.
messagesParam - additional messages with more detail.

requireNotPositiveNorZero

public final <T extends Number> T requireNotPositiveNorZero(T n,
                                                            String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified number is not positive (>0) nor zero (0).

Specified by:
requireNotPositiveNorZero in interface IRequirements
Parameters:
n - The specified number.
messagesParam - additional messages with more detail.

requireNotZero

public final <T extends Number> T requireNotZero(T n,
                                                 String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified number is not zero (0).

Specified by:
requireNotZero in interface IRequirements
Parameters:
n - The specified number.
messagesParam - additional messages with more detail.

requireNull

public final <T> T requireNull(T objParam,
                               String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified object is null.

Specified by:
requireNull in interface IRequirements
Type Parameters:
T - The object's type.
Parameters:
objParam - The specified object.
messagesParam - additional messages with more detail.
Returns:
The specified object.

requirePastInstant

public final Calendar requirePastInstant(Calendar calendarParam,
                                         String... messagesParam)
Specified by:
requirePastInstant in interface IRequirements

requirePastInstant

public final Date requirePastInstant(Date dateParam,
                                     String... messagesParam)
Specified by:
requirePastInstant in interface IRequirements

requireTrue

public final boolean requireTrue(boolean boolParam,
                                 String... messagesParam)
Description copied from interface: IRequirements
Checks that the specified expression returns true.

Specified by:
requireTrue in interface IRequirements
Parameters:
boolParam - The expression.
messagesParam - additional messages with more detail.


Copyright © 2011. All Rights Reserved.