Packagenet.guttershark.util
Classpublic class Assert

The Assert class assists with validating arguments and is a relief mechanism for having to write the same logic over and over when checking arguments.

The default error that's thrown when a condition is not met is an ArgumentError. You can change what error is thrown by providing the exceptionType parameter.


Example
Using the Assert class:
 
  public function setItems(array:Array, maxCount:int)
  {
      Assert.NotNullOrEmpty(array, "Parameter array cannot be null or empty");
      Assert.NotNull(maxCount, "Parameter maxCount cannot be null");
  }
  



Public Methods
 MethodDefined by
  
Compatible(object:*, type:Class, message:String, exceptionType:Class = null):void
[static] Check that an object is a compatible instance, or interface of a certain class.
Assert
  
DictionaryKeysOfType(dictionary:Dictionary, type:Class, message:String, exceptionType:Class = null):void
[static] Assert that a dictionary has keys that are only of the specified type.
Assert
  
False(val:Boolean, message:String, exceptionType:Class = null):Boolean
[static] Assert that the passed value is false.
Assert
  
GreaterThan(target:Number, minimum:Number, message:String, exceptionType:Class = null):void
[static] Check that a target number is greater than a minimum amount.
Assert
  
NotNull(object:*, message:String, exceptionType:Class = null):void
[static] Check that the object is not null.
Assert
  
NotNullOrEmpty(array:Array, message:String, exceptionType:Class = null):void
[static] Check to see if an array is null or empty.
Assert
  
State(expression:Boolean, message:String, exceptionType:Class = null):void
[static] Assert a boolean expression.
Assert
  
True(val:Boolean, message:String, exceptionType:Class = null):Boolean
[static] Assert that the passed value is true.
Assert
Method detail
Compatible()method
public static function Compatible(object:*, type:Class, message:String, exceptionType:Class = null):void

Check that an object is a compatible instance, or interface of a certain class.

Parameters
object:* — The object to check.
 
type:Class — The Class that object needs to be an instance of in order to pass the test.
 
message:String — A message to use for an ArgumentError.
 
exceptionType:Class (default = null) — The class of the exception type you want to throw. Default is ArgumentError if not specified.

Throws
— If object is null.
 
— ArgumentError If message is null.
DictionaryKeysOfType()method 
public static function DictionaryKeysOfType(dictionary:Dictionary, type:Class, message:String, exceptionType:Class = null):void

Assert that a dictionary has keys that are only of the specified type.

Parameters
dictionary:Dictionary — The dictionary to validate.
 
type:Class — The class type that each key should be.
 
message:String — A message to use for an Error.
 
exceptionType:Class (default = null) — The class of the exception type you want to throw. Default is ArgumentError if not specified.

Throws
— ArgumentError If message is null.
 
— If a key in the dictionary is not of the specified type.
False()method 
public static function False(val:Boolean, message:String, exceptionType:Class = null):Boolean

Assert that the passed value is false.

Parameters
val:Boolean — The boolean value to assert.
 
message:String — The message to throw if the assertion is false.
 
exceptionType:Class (default = null) — The exception type to throw if there is an error.

Returns
Boolean
GreaterThan()method 
public static function GreaterThan(target:Number, minimum:Number, message:String, exceptionType:Class = null):void

Check that a target number is greater than a minimum amount.

Parameters
target:Number — The target number.
 
minimum:Number — The minimum the target can be.
 
message:String — A message to use for an ArgumentError.
 
exceptionType:Class (default = null) — The class of the exception type you want to throw. Default is ArgumentError if not specified.

Throws
— If object is null.
 
— ArgumentError If message is null.
NotNull()method 
public static function NotNull(object:*, message:String, exceptionType:Class = null):void

Check that the object is not null.

Parameters
object:* — The object to check.
 
message:String — A message to use for an ArgumentError.
 
exceptionType:Class (default = null) — The class of the exception type you want to throw. Default is ArgumentError if not specified.

Throws
— If object is null.
 
— ArgumentError If message is null.
NotNullOrEmpty()method 
public static function NotNullOrEmpty(array:Array, message:String, exceptionType:Class = null):void

Check to see if an array is null or empty.

Parameters
array:Array — An array to validate that it's not null, and not empty.
 
message:String — A message to use for an ArgumentError.
 
exceptionType:Class (default = null) — The class of the exception type you want to throw. Default is ArgumentError if not specified.

Throws
— If array is null.
 
— ArgumentError If message is null.
State()method 
public static function State(expression:Boolean, message:String, exceptionType:Class = null):void

Assert a boolean expression. If the expression is false an error is raised.

Parameters
expression:Boolean — An expression as a boolean.
 
message:String — A message to use for an Error.
 
exceptionType:Class (default = null) — The class of the exception type you want to throw. Default is ArgumentError if not specified.

Throws
— If object is null.
 
— ArgumentError If message is null.
True()method 
public static function True(val:Boolean, message:String, exceptionType:Class = null):Boolean

Assert that the passed value is true.

Parameters
val:Boolean — The boolean value to assert.
 
message:String — The message to throw if the assertion is false.
 
exceptionType:Class (default = null) — The exception type to throw if there is an error.

Returns
Boolean