亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? query.as

?? 用于flash/flex的 as3的 2D圖形圖像圖表的動(dòng)態(tài)生成
?? AS
字號(hào):
package flare.query
{
	import flare.util.Filter;
	import flare.util.Property;
	import flare.util.Sort;
	
	/**
	 * Performs query processing over a collection of ActionScript objects.
	 * Queries can perform filtering, sorting, grouping, and aggregation
	 * operations over a data collection. Arbitrary data collections can
	 * be queried by providing a visitor function similar to the
	 * <code>Array.forEach<code> method to the query <code>eval</code> method.
	 * 
	 * <p>The <code>select</code> and <code>where</code> methods in the
	 * <code>flare.query.methods</code> package are useful shorthands
	 * for helping to construct queries in code.</p>
	 * 
	 * <p>Here is an example of a query. It uses helper methods defined in the
	 * <code>flare.query.methods</code> package. For example, the
	 * <code>sum</code> method creates a <code>Sum</code> query operator and
	 * the <code>_</code> method creates as a <code>Literal</code> expression
	 * for its input value.</p>
	 * 
	 * <pre>
	 * import flare.query.methods.*;
	 * 
	 * var data:Array = [
	 *  {cat:"a", val:1}, {cat:"a", val:2}, {cat:"b", val:3}, {cat:"b", val:4},
	 *  {cat:"c", val:5}, {cat:"c", val:6}, {cat:"d", val:7}, {cat:"d", val:8}
	 * ];
	 * 
	 * var r:Array = select("cat", {sum:sum("val")}) // sum of values
	 *               .where(neq("cat", _("d"))       // exclude category "d"
	 *               .groupby("cat")                 // group by category
	 *               .eval(data);                    // evaluate with data array
	 * 
	 * // r == [{cat:"a", sum:3}, {cat:"b", sum:7}, {cat:"c", sum:11}]
	 * </pre>
	 */
	public class Query
	{
		private var _select:Array;
		private var _orderby:Array;
		private var _groupby:Array;
		private var _where:Function;
		private var _sort:Sort;
		private var _aggrs:Array;
		private var _map:Boolean = false;
		private var _update:Boolean = false;
		
		/**
		 * Creates a new Query.
		 * @param select an array of select clauses. A select clause consists
		 *  of either a string representing the name of a variable to query or
		 *  an object of the form <code>{name:expr}</code>, where
		 *  <code>name</code> is the name of the query variable to include in
		 *  query result objects and <code>expr</code> is an Expression for
		 *  the actual query value. Expressions can be any legal expression, 
		 *  including aggregate operators.
		 * @param where a where expression for filtering an object collection
		 * @param orderby directives for sorting query results, using the
		 *  format of the <code>flare.util.Sort</code> class methods.
		 * @param groupby directives for grouping query results, using the
		 *  format of the <code>flare.util.Sort</code> class methods.
		 * @see flare.util.Sort
		 */
		public function Query(select:Array=null, where:*=null,
							  orderby:Array=null, groupby:Array=null)
		{
			if (select != null) setSelect(select);
			this.where(where);
			_orderby = orderby;
			_groupby = groupby;
		}
		
		// -- public methods --------------------------------------------------
		
		/**
		 * Sets the select clauses used by this query. A select clause consists
		 * of either a string representing the name of a variable to query or
		 * an object of the form <code>{name:expr}</code>, where
		 * <code>name</code> is the name of the query variable to include in
		 * query result objects and <code>expr</code> is an
		 * <code>Expression</code> for the actual query value.
		 * <p>Calling the <code>select</code> method will overwrite the effect
		 * of any previous calls to the <code>select</code> or
		 * <code>update</code> methods.</p>
		 * @param terms a list of query terms (select clauses). If the first
		 *  element is an array, it will be used as the term list.
		 * @return this query object
		 */
		public function select(...terms):Query
		{
			if (terms.length > 0 && terms[0] is Array) {
				terms = terms[0];
			}
			setSelect(terms);
			_update = false;
			return this;
		}
		
		/**
		 * Sets the select clauses used by this query to update the values
		 * of the input set. An update clause consists of an object of the
		 * form <code>{name:expr}</code>, where <code>name</code> is the name
		 * of the data variable to set and <code>expr</code> is an
		 * <code>Expression</code> for computing the value. When
		 * <code>eval</code> is invoked for an update query, the values of the
		 * input objects are updated and the returned result set is an array
		 * containing these input objects.
		 * <p>Calling the <code>update</code> method will overwrite the effect
		 * of any previous calls to the <code>select</code> or
		 * <code>update</code> methods.</p>
		 * @param terms a list of query terms (update clauses). If the first
		 *  element is an array, it will be used as the term list.
		 * @return this query object
		 */
		public function update(...terms):Query
		{
			if (terms==null || terms.length==0) {
				throw new Error("Nothing to update!");
			} else if (terms[0] is Array) {
				terms = terms[0];
			}
			setSelect(terms);
			_update = true;
			return this;
		}
		
		/**
		 * Sets the where clause (filter conditions) used by this query.
		 * @param e the filter expression. This can be a string, a literal
		 *  value, or an <code>Expression</code> instance. This input value
		 *  will be run through the <code>Expression.expr</code> method.
		 * @return this query object
		 */
		public function where(e:*):Query
		{
			_where = Filter.$(e);
			return this;
		}
				
		/**
		 * Sets the sort order for query results.
		 * @param terms the sort terms as a list of field names to sort on.
		 *  By default, fields are sorted in ascending order. Add the prefix
		 *  "-" (negative sign) to the field name to sort in descending order.
		 * @return this query object
		 */
		public function orderby(...terms):Query
		{
			_orderby = (terms.length > 0 ? terms : null);
			return this;
		}
		
		/**
		 * Sets the group by terms for aggregate queries.
		 * @param terms an ordered list of terms to group by.
		 * @return this query object
		 */
		public function groupby(...terms):Query
		{
			_groupby = (terms.length > 0 ? terms : null);
			return this;
		}
		
		/**
		 * Sets whether or not aggregate functions will be mapped to all
		 * tuples in the data set. This allows the results of aggregate
		 * operators to be applied for all tuples. For example, the
		 * <code>map</code> directive allows queries of this form:
		 * <pre>
		 * var q:Query = select({a:div(a,sum(a))}).map().eval(...);
		 * </pre>
		 * <p>The result include normalized <code>a</code> values for
		 * all tuples in the input data. Without the map directive, a
		 * "group-by" for all data would be assumed and only a single tuple
		 * would be returned in the result set (matching the normal behavior
		 * of a SQL database). Map can also be specified with a
		 * group-by clause, in which case the aggregate operators will be
		 * handled separately for each group, but the result set will still
		 * contain a result for every tuple in the input set.</p>
		 * <p>The map directive has no effect on "update" queries, which 
		 * already apply map semantics. It only effects "select" queries.</p>
		 * @param value if true (the default), aggregate operators will be
		 *  applied (mapped) to all tuples; if false, normal group-by semantics
		 *  will be used.
		 * @return this query object
		 */
		public function map(value:Boolean=true):Query
		{
			_map = value;
			return this;
		}
		
		// -- helper methods --------------------------------------------------
		
		private function setSelect(a:Array):void {
			_select = [];
			for each (var o:Object in a) {
				if (o is String) {
					_select.push({
						name: o as String,
						expression: new Variable(o as String)
					});
				} else {
					for (var n:String in o) {
						_select.push({
							name: n,
							expression: Expression.expr(o[n])
						});
					}
				}
			}
		}
		
		private function sorter():Sort
		{
			var s:Array = [], i:int;
			if (_groupby != null) {
				for (i=0; i<_groupby.length; ++i)
					s.push(_groupby[i]);
			}
			if (_orderby != null) {
				for (i=0; i<_orderby.length; ++i)
					s.push(_orderby[i]);
			}
			return s.length==0 ? null : new Sort(s);
		}
		
		private function aggregates():Array
		{
			var aggrs:Array = [];
			for each (var pair:Object in _select) {
				var expr:Expression = pair.expression;
				expr.visit(function(e:Expression):void {
					if (e is AggregateExpression)
						aggrs.push(e);
				});
			}
			return aggrs.length==0 ? null : aggrs;
		}
		
		// -- query processing ------------------------------------------------
		
		/**
		 * Evaluates this query on an object collection. The input argument can
		 * either be an array of objects or a visitor function that takes 
		 * another function as input and applies it to all items in a
		 * collection.
		 * @param input either an array of objects or a visitor function
		 * @return an array of processed query results
		 */
		public function eval(input:*):Array
		{
			// check for initialization
			if (_sort  == null) _sort  = sorter();
			if (_aggrs == null) _aggrs = aggregates();
			
			// TODO -- evaluate any sub-queries in WHERE clause
			var results:Array = [];
			var visitor:Function;
			if (input is Array) {
				visitor = (input as Array).forEach;
			} else if (input is Function) {
				visitor = input as Function;
			} else if (Object(input).hasOwnProperty("visit") &&
					   Object(input).visit is Function) {
				visitor = Object(input).visit as Function;
			} else {
				throw new ArgumentError("Illegal input argument: "+input);
			}
			
			// collect and filter
			if (_where != null) {
				visitor(function(item:Object, ...rest):void {
					if (_where(item)) results.push(item);
				});
			} else {
				visitor(function(item:Object, ...rest):void {
					results.push(item);
				});
			}
			
			// sort the result set
			if (_sort != null) {
				_sort.sort(results);
			}
			
			if (_select == null) {
				return results;
			} else if (_update && _aggrs==null && _groupby==null) {
				return applyAll(results);
			} else if (_aggrs==null && _groupby==null) {
				return projectAll(results);
			} else {
				return aggregate(results);
			}
		}
		
		private function projectAll(results:Array):Array
		{					
			for (var i:int=0; i<results.length; ++i) {
				var item:Object = {};
				for each (var pair:Object in _select) {
					var p:Property = Property.$(pair.name);
					var expr:Expression = pair.expression;
					p.setValue(item, expr.eval(results[i]));
				}
				results[i] = item;
			}
			return results;
		}
		
		private function applyAll(results:Array):Array
		{
			var o:Object = {};
			for each (var item:Object in results) {
				for each (var pair:Object in _select) {
					var name:String = pair.name;
					var expr:Expression = pair.expression;
					o[name] = expr.eval(item);
				}
				for each (pair in _select) {
					name = pair.name;
					var p:Property = Property.$(name);
					p.setValue(item, o[name]);
				}
			}
			return results;
		}
		
		// -- group-by and aggregation ----------------------------------------
		
		/**
		 * Performs grouping and aggregation of query results.
		 * @param items the filtered query results array
		 * @return aggregated query results array
		 */
		private function aggregate(items:Array):Array
		{
			var h:int, i:int, j:int, item:Object;
			var results:Array = [], props:Array = [];
			
			// get group-by properties as key
			if (_groupby != null) {
				for (i=_groupby.length; --i>=0;) {
					if (_groupby[i] is String) {
						props.push(Property.$(_groupby[i]));
					}
				}
			}
			
			// process all groups
			reset(_aggrs);
			for (i=1, h=0, item=items[0]; i<=items.length; ++i) {
				// update the aggregate functions
				for each (var aggr:AggregateExpression in _aggrs) {
					aggr.aggregate(items[i-1]);
				}
				// handle change of group
				if (i==items.length || 
					!(_groupby==null || sameGroup(props, item, items[i])))
				{
					if (_update) {
						for (j=h; j<i; ++j)
							apply(items[j]);
					} else if (_map) {
						for (j=h; j<i; ++j)
							items[j] = project(items[j]);
					} else {
						results.push(project(item));
					}
					item = items[(h=i)];
					reset(_aggrs);
				}
			}
			
			return (_update || _map ? items : results);
		}
		
		private function reset(aggrs:Array):void
		{
			for each (var aggr:AggregateExpression in aggrs) {
				aggr.reset();
			}
		}
		
		private function apply(item:Object):Object
		{
			var o:Object = {};
			for each (var pair:Object in _select) {
				var name:String = pair.name;
				var expr:Expression = pair.expression;
				o[name] = expr.eval(item);
			}
			for each (pair in _select) {
				name = pair.name;
				var p:Property = Property.$(name);
				p.setValue(item, o[name]);
			}
			return item;
		}
		
		private function project(item:Object):Object
		{
			var result:Object = {};
			for each (var pair:Object in _select) {
				var p:Property = Property.$(pair.name);
				var expr:Expression = pair.expression;
				p.setValue(result, expr.eval(item));
			}
			return result;
		}
		
		private static function sameGroup(props:Array, x:Object, y:Object):Boolean
		{
			var a:*, b:*;
			for each (var p:Property in props) {
				a = p.getValue(x);
				b = p.getValue(y);
				
				if (a is Date && b is Date) {
					if ((a as Date).time != (b as Date).time)
						return false;
				} else if (a != b) {
					return false;
				}
			}
			return true;
		}
		
	} // end of class Query
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产原创一区二区| 五月激情六月综合| aaa欧美大片| 国产精品欧美久久久久一区二区 | 1024成人网| 99久久伊人久久99| 亚洲天堂网中文字| 91麻豆精品一区二区三区| 亚洲视频一区二区在线| 一本色道亚洲精品aⅴ| 亚洲精品日韩专区silk | 免费观看在线综合色| 日韩女优毛片在线| 国产精品主播直播| 久久久美女毛片| 粉嫩av一区二区三区在线播放| 国产精品蜜臀av| 91蜜桃网址入口| 一片黄亚洲嫩模| 欧美久久久久久久久中文字幕| 日本一不卡视频| 91精品国产色综合久久ai换脸| 麻豆国产91在线播放| 久久夜色精品一区| 成人网在线播放| 亚洲视频免费看| 97aⅴ精品视频一二三区| 亚洲美女一区二区三区| 欧美日韩国产一级二级| 久久国产精品无码网站| 日韩三级视频在线观看| 国产**成人网毛片九色 | 亚洲国产日韩av| 91精品国产免费| 国产电影一区在线| 亚洲老司机在线| 欧美久久一区二区| 国产精品中文字幕一区二区三区| 亚洲国产经典视频| 欧美揉bbbbb揉bbbbb| 久久成人麻豆午夜电影| 国产欧美精品一区| 色综合一区二区| 日韩成人精品在线| 欧美国产日韩精品免费观看| 91天堂素人约啪| 日韩成人午夜电影| 国产欧美日韩精品a在线观看| 色国产精品一区在线观看| 奇米影视7777精品一区二区| 国产亚洲福利社区一区| 日本韩国欧美三级| 久色婷婷小香蕉久久| 久久久亚洲精品石原莉奈| 欧美在线免费观看亚洲| 国产三级一区二区| 91久久精品日日躁夜夜躁欧美| 天天色综合成人网| 久久精品免视看| 欧美视频一区二| 国内精品久久久久影院薰衣草| 亚洲欧美日韩在线不卡| 精品欧美久久久| 色系网站成人免费| 九九视频精品免费| 一区二区三区在线观看视频| 久久综合九色欧美综合狠狠| 欧美又粗又大又爽| 国产激情一区二区三区四区| 午夜精品成人在线视频| 国产精品久久久久久久久免费丝袜| 911国产精品| 99久久亚洲一区二区三区青草| 日本中文字幕一区二区视频 | 亚洲裸体在线观看| 2017欧美狠狠色| 欧美日韩免费观看一区二区三区| 国产成人精品亚洲777人妖 | 国产精品久久久久久久久免费桃花| 777亚洲妇女| av亚洲精华国产精华| 美腿丝袜一区二区三区| 亚洲视频网在线直播| 久久亚洲春色中文字幕久久久| 欧美亚洲另类激情小说| 国产美女精品人人做人人爽| 日韩精品一级二级| 夜夜精品浪潮av一区二区三区| 久久精品免视看| 日韩精品一区二区三区三区免费| 欧美在线免费播放| 99久久99久久精品免费观看| 韩国视频一区二区| 国产专区综合网| 国内精品写真在线观看| 久久成人久久鬼色| 激情欧美一区二区| 久草中文综合在线| 狠狠色综合播放一区二区| 久久99国内精品| 精品一区二区三区av| 韩日欧美一区二区三区| 国产一区二区按摩在线观看| 国产精品99久久久久久久vr| 国产福利91精品一区| 粉嫩久久99精品久久久久久夜| 国产成人免费在线视频| 成人性生交大片免费看中文网站| 丁香六月久久综合狠狠色| 成人一区二区三区视频在线观看 | 国产成人av影院| 国产精品18久久久久久vr| 国产精品影视网| 国产91富婆露脸刺激对白| 成人av电影免费在线播放| 波多野结衣91| 色一情一伦一子一伦一区| 91国在线观看| 欧美日韩国产综合久久 | 国产精品国产自产拍高清av| 亚洲欧洲国产专区| 一区二区三区四区精品在线视频| 亚洲国产日韩在线一区模特| 日本成人在线视频网站| 美腿丝袜亚洲一区| 国产美女av一区二区三区| 成人高清视频在线| 91高清视频在线| 欧美日韩aaa| 精品国产亚洲在线| 国产精品麻豆99久久久久久| 亚洲欧美激情一区二区| 午夜视黄欧洲亚洲| 九一九一国产精品| 本田岬高潮一区二区三区| 在线观看www91| 日韩精品专区在线影院重磅| 国产欧美一区二区三区鸳鸯浴| 最近中文字幕一区二区三区| 午夜精品一区二区三区电影天堂| 久久精品免费看| 成人黄色av电影| 欧美亚洲一区三区| 精品国产91乱码一区二区三区| 欧美极品少妇xxxxⅹ高跟鞋| 一区二区激情小说| 美国十次综合导航| 成人的网站免费观看| 欧美日韩五月天| 久久免费美女视频| 亚洲精品v日韩精品| 蜜桃av噜噜一区二区三区小说| 国产成人丝袜美腿| 欧美日韩一级黄| 国产亚洲欧美一级| 亚洲综合色婷婷| 韩国女主播成人在线| 色综合天天综合网国产成人综合天| 欧美理论电影在线| 国产精品丝袜在线| 丝袜诱惑亚洲看片| 成人综合激情网| 69久久99精品久久久久婷婷| 中文字幕不卡在线观看| 亚洲国产精品人人做人人爽| 国产一二精品视频| 欧美少妇xxx| 欧美激情综合网| 日韩主播视频在线| 成人激情动漫在线观看| 欧美一区二区精品| 亚洲品质自拍视频| 国产在线看一区| 欧美主播一区二区三区美女| 久久亚洲春色中文字幕久久久| 亚洲丶国产丶欧美一区二区三区| 国产一区二区成人久久免费影院| 欧美色综合网站| 国产精品区一区二区三| 裸体在线国模精品偷拍| 色婷婷激情一区二区三区| 欧美精品一区二区不卡| 午夜天堂影视香蕉久久| av日韩在线网站| 26uuu久久综合| 午夜一区二区三区视频| 本田岬高潮一区二区三区| 精品欧美一区二区三区精品久久| 亚洲一区二区三区免费视频| 国产成人免费在线观看| 日韩一级片在线观看| 亚洲精品五月天| 成人黄色小视频| 久久婷婷色综合| 午夜一区二区三区在线观看| 91麻豆精品一区二区三区| 国产日韩精品一区二区浪潮av| 免费在线看一区| 欧美日韩在线播放三区四区| 中文字幕一区二区三区在线观看|