package flare.util { /** * Utility methods for creating filter functions. The static * $() method takes an arbitrary object and generates a * corresponding filter function. * *

Filter functions are functions that take one argument and return a * Boolean value. The input argument to a filter function * passes the filter if the function returns true and fails the * filter if the function returns false.

*/ public class Filter { /** * Constructor, throws an error if called, as this is an abstract class. */ public function Filter() { throw new Error("This is an abstract class."); } /** * Convenience method that returns a filter function determined by the * input object. * * @param f an input object specifying the filter criteria * @return the filter function */ public static function $(f:*):Function { if (f==null || f is Function) { return f; } else if (f is IPredicate) { return IPredicate(f).predicate; } else if (f is String) { return Property.$(f).predicate; } else if (f is Class) { return typeChecker(Class(f)); } else { throw new ArgumentError("Unrecognized filter type"); } } /** * Returns a filter function that performs type-checking. * @param type the Class type to check for * @return a Boolean-valued type checking filter function */ public static function typeChecker(type:Class):Function { return function(o:Object):Boolean { return o is type; } } } // end of class Filter }