distinct.as

来自「用于flash/flex的 as3的 2D图形图像图表的动态生成」· AS 代码 · 共 51 行

AS
51
字号
package flare.query
{
	/**
	 * Aggregate (group-by) operator for counting the number of distinct
	 * values in a set of values.
	 */
	public class Distinct extends AggregateExpression
	{
		private var _map:Object;
		private var _count:int;
		
		/**
		 * Creates a new Distinct operator
		 * @param input the sub-expression of which to compute the distinct
		 *  values
		 */
		public function Distinct(input:*) {
			super(input);
		}
		
		/**
		 * @inheritDoc
		 */
		public override function reset():void
		{
			_map = {};
			_count = 0;
		}
		
		/**
		 * @inheritDoc
		 */
		public override function eval(o:Object=null):*
		{
			return _count;
		}
		
		/**
		 * @inheritDoc
		 */
		public override function aggregate(value:Object):void
		{
			value = _expr.eval(value);
			if (_map[value] == undefined) {
				_count++;
				_map[value] = 1;
			}
		}
		
	} // end of class Distinct
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?