Packagetwaver
Classpublic class QuickFinder
InheritanceQuickFinder Inheritance Object

This defines a quick finder for data box to help developer indexing and search data in a very quickly way. You can always iterate all data contains in the data box to find the data you want. However this is not always an efficient approach if that query is called very often and need the result returned very fast.

This quick finder can be defined in front of adding data into the data box. You can create quick finder by given property name and connect the quick finder with a data box. Later, every time when data of this data box is changed, this quick finder will catch up with this change, indexing all matched data and caches result inside. So quick finder always can execute the query and return the result very quickly.

See also

twaver.DataBox


Public Properties
 PropertyDefined By
  dataBox : DataBox
[read-only] Get the data box this quick finder connected.
QuickFinder
  filterFunction : Function
[read-only] Get search filter function.
QuickFinder
  propertyName : String
[read-only] The property name query condition of this finder.
QuickFinder
  propertyType : String
[read-only] Get the property type query condition.
QuickFinder
  valueFunction : Function
[read-only] Get the value generator function.
QuickFinder
Public Methods
 MethodDefined By
  
QuickFinder(dataBox:DataBox, propertyName:String, propertyType:String = accessor, valueFunction:Function = null, filterFunction:Function = null)
Constructor.
QuickFinder
  
dispose():void
Call this method to dispose all resources this quick finder used.
QuickFinder
  
find(value:Object):Array
Call this to execute the query by specified condition.
QuickFinder
  
findFirst(value:Object):IData
Find the first matched data.
QuickFinder
Protected Methods
 MethodDefined By
  
isInterested(data:IData):Boolean
Whether specified data is a data that current finder has interesting.
QuickFinder
Property Detail
dataBoxproperty
dataBox:DataBox  [read-only]

Get the data box this quick finder connected.


Implementation
    public function get dataBox():DataBox
filterFunctionproperty 
filterFunction:Function  [read-only]

Get search filter function.


Implementation
    public function get filterFunction():Function
propertyNameproperty 
propertyName:String  [read-only]

The property name query condition of this finder. Finder will search according to this property value.


Implementation
    public function get propertyName():String
propertyTypeproperty 
propertyType:String  [read-only]

Get the property type query condition. The property type of this query condition can be: Consts.PROPERTY_TYPE_ACCESSOR, Consts.PROPERTY_TYPE_CLIENT, Consts.PROPERTY_TYPE_STYLE.


Implementation
    public function get propertyType():String
valueFunctionproperty 
valueFunction:Function  [read-only]

Get the value generator function.


Implementation
    public function get valueFunction():Function
Constructor Detail
QuickFinder()Constructor
public function QuickFinder(dataBox:DataBox, propertyName:String, propertyType:String = accessor, valueFunction:Function = null, filterFunction:Function = null)

Constructor. Create quick finder and connect to the specified data box. The quick finder will search data by conditions of specified property name, property type, value generator function and filter function.

Parameters
dataBox:DataBox — the target data box this quick finder will search.
 
propertyName:String — the property name search condition.
 
propertyType:String (default = accessor) — the property type search condition. This can be: Consts.PROPERTY_TYPE_ACCESSOR, Consts.PROPERTY_TYPE_CLIENT, Consts.PROPERTY_TYPE_STYLE
 
valueFunction:Function (default = null) — a generator function. This function determines what value should be returned when try to find data in the data box.
 
filterFunction:Function (default = null) — a filter function. This will filter out the data that you don't want include in the query result.
Method Detail
dispose()method
public function dispose():void

Call this method to dispose all resources this quick finder used. When you distroy this quick finder, call this to release all resources.

find()method 
public function find(value:Object):Array

Call this to execute the query by specified condition.

Parameters

value:Object — the value condition of the query.

Returns
Array — all matched data of this query.
findFirst()method 
public function findFirst(value:Object):IData

Find the first matched data.

Parameters

value:Object — the value condition of this query.

Returns
IData — first matched data of this query.
isInterested()method 
protected function isInterested(data:IData):Boolean

Whether specified data is a data that current finder has interesting. Only the data this finder has interesting will be searched by this finder.

Parameters

data:IData — a data need to check

Returns
Boolean — true if has interesting in this data, false otherwise.