ccc.api.types
Class DBC

java.lang.Object
  extended by ccc.api.types.DBC

public final class DBC
extends java.lang.Object

A helper class to support design-by-contract (DBC).

Author:
Civic Computing Ltd

Method Summary
 void containsNoBrackets(java.lang.String stringToTest)
          Assert that the specified string does not contain bracket < > characters.
static DBC ensure()
          Factory method.
 int greaterThan(int criteria, int value)
          Assert that the specified value is greater than the criteria.
 void maxLength(java.lang.String stringToTest, int maximumLength)
          Assert that the specified string is not longer than the specified length.
 void maxOccurrences(java.lang.String text, java.lang.String item, int max)
          Assert that the specified string does not occur more than specified in the text.
 void maxValue(long valueToTest, long maximum)
          Assert that the specified value is less than the criteria.
 void minLength(java.lang.String stringToTest, int minimumLength)
          Assert that the specified string contains at least the specified number of characters.
 void minValue(long valueToTest, long minimum)
          Assert that the specified value is greater than the criteria.
 java.lang.String notEmpty(java.lang.String string)
          Assert that the specified string is not empty.
<T> T
notNull(T object)
          Assert that the specified value is not null.
static DBC require()
          Factory method.
 void toBeFalse(boolean condition)
          Assert that the specified condition is false.
 void toBeNull(java.lang.Object object)
          Assert that the specified object is null.
 void toBeTrue(boolean condition)
          Assert that the specified condition is true.
 void toBeTrue(boolean condition, java.lang.String message)
          Assert that the specified condition is true.
 void toMatch(java.lang.String regex, java.lang.String stringToTest)
          Assert that the specified string matches with given regular expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

require

public static DBC require()
Factory method.

Returns:
An instance of DBC.

ensure

public static DBC ensure()
Factory method.

Returns:
An instance of DBC.

notNull

public <T> T notNull(T object)
Assert that the specified value is not null.

Type Parameters:
T - The type object to be checked.
Parameters:
object - The object to test for NULL.
Returns:
Returns the specified object.

notEmpty

public java.lang.String notEmpty(java.lang.String string)
Assert that the specified string is not empty. A string is considered empty if either:
1. It is NULL, or
2. It has a length of 0.

Parameters:
string - The string that may not be empty.
Returns:
Returns the specified string.

toBeFalse

public void toBeFalse(boolean condition)
Assert that the specified condition is false.

Parameters:
condition - The condition to check.

toBeTrue

public void toBeTrue(boolean condition)
Assert that the specified condition is true.

Parameters:
condition - The condition to check.

toBeTrue

public void toBeTrue(boolean condition,
                     java.lang.String message)
Assert that the specified condition is true.

Parameters:
condition - The condition to check.
message - The error message.

maxLength

public void maxLength(java.lang.String stringToTest,
                      int maximumLength)
Assert that the specified string is not longer than the specified length.

Parameters:
stringToTest - The string to test.
maximumLength - The length it should not exceed.

minLength

public void minLength(java.lang.String stringToTest,
                      int minimumLength)
Assert that the specified string contains at least the specified number of characters.

Parameters:
stringToTest - The string to test.
minimumLength - The minimal acceptable length.

toMatch

public void toMatch(java.lang.String regex,
                    java.lang.String stringToTest)
Assert that the specified string matches with given regular expression.

Parameters:
regex - The regular expression.
stringToTest - The string to test.

toBeNull

public void toBeNull(java.lang.Object object)
Assert that the specified object is null.

Parameters:
object - The object to test.

containsNoBrackets

public void containsNoBrackets(java.lang.String stringToTest)
Assert that the specified string does not contain bracket < > characters.

Parameters:
stringToTest - The string to test.

maxValue

public void maxValue(long valueToTest,
                     long maximum)
Assert that the specified value is less than the criteria.

Parameters:
valueToTest - The value to test.
maximum - The maximum acceptable value.

minValue

public void minValue(long valueToTest,
                     long minimum)
Assert that the specified value is greater than the criteria.

Parameters:
valueToTest - The value to test.
minimum - The minimum acceptable value.

greaterThan

public int greaterThan(int criteria,
                       int value)
Assert that the specified value is greater than the criteria.

Parameters:
criteria - The lower bound.
value - The value to test.

maxOccurrences

public void maxOccurrences(java.lang.String text,
                           java.lang.String item,
                           int max)
Assert that the specified string does not occur more than specified in the text.

Parameters:
text - The text to validate.
item - The string to search.
max - The maximum occurrences.


Copyright © 2010. All Rights Reserved.