My Movies 1.0.0

hirondelle.movies.util
Class Args

Object
  extended by Args

public final class Args
extends Object

Utility methods for common argument validations.

Replace if statements at the start of a method with more compact method calls.


Constructor Summary
Args()
           
 
Method Summary
static void checkForContent(String aText)
          Throw an IllegalArgumentException if aText does not satisfy Util.textHasContent(java.lang.String).
static void checkForEmpty(Collection aCollection)
          Throw an IllegalArgumentException only if aCollection.isEmpty returns true.
static void checkForNull(Object aObject)
          If aObject is null, throw a NullPointerException.
static void checkForRange(int aNumber, int aLow, int aHigh)
          Throw an IllegalArgumentException if Util.isInRange(int, int, int) returns false.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Args

public Args()
Method Detail

checkForNull

public static void checkForNull(Object aObject)
If aObject is null, throw a NullPointerException.

Use cases :

   doSomething( SoccerBall aBall ){
     //call some method on the argument : 
     //if aBall is null, then exception is automatically thrown, so 
     //there is no need for an explicit check for null.
     aBall.inflate();

     //assign to a corresponding field (common in constructors): 
     //if aBall is null, no exception is immediately thrown, so 
     //an explicit check for null may be useful here
     Args.checkForNull( aBall );
     fBall = aBall;

     //passed on to some other method as param : 
     //it may or may not be appropriate to have an explicit check 
     //for null here, according the needs of the problem
     Args.checkForNull( aBall ); //??
     fReferee.verify( aBall );
   }
   


checkForContent

public static void checkForContent(String aText)
Throw an IllegalArgumentException if aText does not satisfy Util.textHasContent(java.lang.String).

Most text used in an application is meaningful only if it has visible content.


checkForRange

public static void checkForRange(int aNumber,
                                 int aLow,
                                 int aHigh)
Throw an IllegalArgumentException if Util.isInRange(int, int, int) returns false.

Parameters:
aLow - is less than or equal to aHigh.

checkForEmpty

public static void checkForEmpty(Collection aCollection)
Throw an IllegalArgumentException only if aCollection.isEmpty returns true.


My Movies 1.0.0

Copyright Hirondelle Systems - Generated 2008Dec30.15.53