--[[----------------------------------------------------------------------------

WFDiagnosticStatAccumulator.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2014 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

------------------------------------------------------------------------------]]

	-- RxLua
local Rx = require 'Rx'

	-- WF.core.utils
local WFArguments = require 'WFArguments'


--============================================================================--
--[[!
	\class WFDiagnosticStatAccumulator

	\brief This namespace provides a way to accumulate statistics for diagnostic
		log or similar purposes.
]]--

-- @mark WFDiagnosticStatAccumulator class

local accumulatorMethods = {

	_count = 0,
	_total = 0,

	_min = false,
	_max = false,

}

--------------------------------------------------------------------------------

function accumulatorMethods:add( number )

	WFArguments.check( 'WFDiagnosticStatAccumulator', 'number' )

	if self._count == 0 then

		self._count = 1
		self._total = number
		self._min = number
		self._max = number

	else

		self._count = self._count + 1
		self._total = self._total + number
		self._min = math.min( self._min, number )
		self._max = math.max( self._max, number )

	end

end

--------------------------------------------------------------------------------

function accumulatorMethods:dump()

	if self._count == 0 then

		return { count = 0 }

	else

		return {
			count = self._count,
			min = self._min,
			max = self._max,
			avg = self._total / self._count,
			total = self._total,
		}

	end

end

---------------------------------------------------------------------------------

return Rx.Class 'WFDiagnosticStatAccumulator'( accumulatorMethods )
