| Package | net.guttershark.util |
| Class | public final class Assertions |
All of the methods can be used for conditional assertions.
var ast:Assertions = Assertions.gi();
var t:String = " ";
if(ast.emptyString(t)) trace("it's empty");
t = "word";
if(ast.emptyString(t)) trace("doh"); //this wont trace, because the assertion evaluates to false.
You can also use the assertion class as defense when checking for valid method arguments and throw errors.
Using the assertions class for method argument defense:
var ast:Assertions = Assertions.gi();
function setSomething(val:Number):void
{
ast.notNull(val,"Parameter val cannot be null"); //throws argument error if val is null
somthing = val;
}
You can also change the exception type that get's thrown if an assertion fails.
Changing the exception type:
var ast:Assertions = Assertions.gi();
function setSomething(mc:MovieClip):void
{
ast.compatible(mc,MovieClip,"Parameter val must be a MovieClip",TypeError);
}
public class MyMC extends CoreClip
{
//protected var ast:Assertion; //ast is a protected variable on CoreClip, and CoreSprite.
public function setSomeValue(value:Object):void
{
ast.notNil(value,"Parameter value cannot be null"); //argument error if value is null
}
public function setSomeArray(array:Array):void
{
ast.notNilOrEmpty(array,"Parameter array cannot be null"); //argument error if array is null or length==0
}
}
| Property | Defined by | ||
|---|---|---|---|
| onAssertionFail : Function
A function delegate you can define, which will
be called when an assertion fails - this is intended
to be used if you wanted to post the assertion
to an http service for logging errors.
| Assertions | ||
| Method | Defined by | ||
|---|---|---|---|
|
compatible(obj:*, type:Class, message:String = null, exceptionType:Class = null):Boolean
Assert if an object is compatible with another type.
| Assertions | ||
|
contains(str:String, pat:String, message:String = null, exceptionType:Class = null):Boolean
Assert that a string contains another string.
| Assertions | ||
|
different(value:*, otherValue:String, message:Class = null, exceptionType:* = null):Boolean
Assert that a value is defferent from another value.
| Assertions | ||
|
emptyString(str:String, message:String = null, exceptionType:Class = null):Boolean
Assert a string as being empty (zero characters or all spaces).
| Assertions | ||
|
equal(value:*, otherValue:String, message:Class = null, exceptionType:* = null):Boolean
Assert that a value is equal to another value.
| Assertions | ||
|
gi():Assertions
[static]
Singleton access.
| Assertions | ||
|
greater(value:Number, minimum:Number = -1, message:String = null, exceptionType:Class = null):Boolean
Assert that a value is greater than a minimum number.
| Assertions | ||
|
nil(obj:*, message:String = null, exceptionType:Class = null):Boolean
Assert if an object is nil.
| Assertions | ||
|
nilOrEmpty(array:Array, message:String = null, exceptionType:Class = null):Boolean
Assert if an Array is nil or empty.
| Assertions | ||
|
notCompatible(obj:*, type:Class, message:String = null, exceptionType:Class = null):Boolean
Assert if an object is not compatible with another type.
| Assertions | ||
|
notEmptyString(str:String, message:String = null, exceptionType:Class = null):Boolean
Assert a string as being not empty (zero characters or all spaces).
| Assertions | ||
|
notNil(object:*, message:String = null, exceptionType:Class = null):Boolean
Assert if an object is not nil.
| Assertions | ||
|
notNilOrEmpty(array:Array, message:String = null, exceptionType:Class = null):Boolean
Assert if an Array is not nil or empty.
| Assertions | ||
|
notNumberString(str:String, message:String = null, exceptionType:Class = null):Boolean
Assert that a string does not have all number characters.
| Assertions | ||
|
numberString(str:String, message:String = null, exceptionType:Class = null):Boolean
Assert that a string has all number characters.
| Assertions | ||
|
smaller(value:Number, maxmimum:Number = 0, message:String = null, exceptionType:Class = null):Boolean
Assert that a value is smaller than a maximum number.
| Assertions | ||
| onAssertionFail | property |
public var onAssertionFail:FunctionA function delegate you can define, which will be called when an assertion fails - this is intended to be used if you wanted to post the assertion to an http service for logging errors.
var ast:Assertions = Assertions.gi();
ast.onAssertionFail = onAssertionFail;
private function onAssertionFail(msg:String):void
{
trace(msg);
}
| compatible | () | method |
public function compatible(obj:*, type:Class, message:String = null, exceptionType:Class = null):BooleanAssert if an object is compatible with another type.
Parametersobj:* — The object to evaluate.
|
|
type:Class — A message to throw if the assertion evaluates to false.
|
|
message:String (default = null) — The exceptionType to throw if an exception is being thrown.
|
|
exceptionType:Class (default = null) |
Boolean |
| contains | () | method |
public function contains(str:String, pat:String, message:String = null, exceptionType:Class = null):BooleanAssert that a string contains another string.
Parametersstr:String — The string to search in.
|
|
pat:String — The pattern that will be searched for in str.
|
|
message:String (default = null) |
|
exceptionType:Class (default = null) |
Boolean |
| different | () | method |
public function different(value:*, otherValue:String, message:Class = null, exceptionType:* = null):BooleanAssert that a value is defferent from another value.
Parametersvalue:* — The value to test.
|
|
otherValue:String — The other value to compare with value (this is actually typed as *, but asdocs changes it to String for some reason).
|
|
message:Class (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:* (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| emptyString | () | method |
public function emptyString(str:String, message:String = null, exceptionType:Class = null):BooleanAssert a string as being empty (zero characters or all spaces).
Parametersstr:String — The string to evaluate.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| equal | () | method |
public function equal(value:*, otherValue:String, message:Class = null, exceptionType:* = null):BooleanAssert that a value is equal to another value.
Parametersvalue:* — The value to test.
|
|
otherValue:String — The other value to compare with value (this is actually typed as *, but asdocs changes it to String for some reason).
|
|
message:Class (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:* (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| gi | () | method |
| greater | () | method |
public function greater(value:Number, minimum:Number = -1, message:String = null, exceptionType:Class = null):BooleanAssert that a value is greater than a minimum number.
Parametersvalue:Number — The value to test.
|
|
minimum:Number (default = -1) — The minimum number that the value must be greater than.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| nil | () | method |
public function nil(obj:*, message:String = null, exceptionType:Class = null):BooleanAssert if an object is nil.
Parametersobj:* — The object to evaluate.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| nilOrEmpty | () | method |
public function nilOrEmpty(array:Array, message:String = null, exceptionType:Class = null):BooleanAssert if an Array is nil or empty.
Parametersarray:Array — The array to evaluate.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| notCompatible | () | method |
public function notCompatible(obj:*, type:Class, message:String = null, exceptionType:Class = null):BooleanAssert if an object is not compatible with another type.
Parametersobj:* — The object to evaluate.
|
|
type:Class — A message to throw if the assertion evaluates to false.
|
|
message:String (default = null) — The exceptionType to throw if an exception is being thrown.
|
|
exceptionType:Class (default = null) |
Boolean |
| notEmptyString | () | method |
public function notEmptyString(str:String, message:String = null, exceptionType:Class = null):BooleanAssert a string as being not empty (zero characters or all spaces).
Parametersstr:String — The string to evaluate.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| notNil | () | method |
public function notNil(object:*, message:String = null, exceptionType:Class = null):BooleanAssert if an object is not nil.
Parametersobject:* — The object to evaluate.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| notNilOrEmpty | () | method |
public function notNilOrEmpty(array:Array, message:String = null, exceptionType:Class = null):BooleanAssert if an Array is not nil or empty.
Parametersarray:Array — The array to evaluate.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| notNumberString | () | method |
public function notNumberString(str:String, message:String = null, exceptionType:Class = null):BooleanAssert that a string does not have all number characters.
Parametersstr:String — The string to evaluate.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| numberString | () | method |
public function numberString(str:String, message:String = null, exceptionType:Class = null):BooleanAssert that a string has all number characters.
Parametersstr:String — The string to evaluate.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |
| smaller | () | method |
public function smaller(value:Number, maxmimum:Number = 0, message:String = null, exceptionType:Class = null):BooleanAssert that a value is smaller than a maximum number.
Parametersvalue:Number — The value to test.
|
|
maxmimum:Number (default = 0) — The maximum number that the value must be smaller than.
|
|
message:String (default = null) — A message to throw if the assertion evaluates to false.
|
|
exceptionType:Class (default = null) — The exceptionType to throw if an exception is being thrown.
|
Boolean |