public LeakDetector(int minPortCount, double maxDifference, int maxPortCount,
                            int shortSampleSize = DefaultShortSampleSize, int longSampleSize = DefaultLongSampleSize)
        {
            MinPortCount = minPortCount;
            if (MinPortCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(minPortCount),
                                                      "MinPortCount must be at least 1");
            }

            MaxDifference = maxDifference;
            if (MaxDifference <= 0.0d)
            {
                throw new ArgumentOutOfRangeException(nameof(maxDifference), "MaxDifference must be greater than 0.0");
            }

            MaxPortCount = maxPortCount;
            if (MaxPortCount <= MinPortCount)
            {
                throw new ArgumentOutOfRangeException(nameof(maxPortCount),
                                                      "MaxPortCount must be greater than MinPortCount");
            }

            // default both EMWAs to the minimum port count.
            Short = EMWA.Init(shortSampleSize, minPortCount);
            Long  = EMWA.Init(longSampleSize, minPortCount);
        }
        /// <summary>
        ///     Feed the next port count into the <see cref="LeakDetector" />.
        /// </summary>
        /// <param name="newPortCount">The updated port count.</param>
        /// <returns>The current <see cref="LeakDetector" /> instance but with updated state.</returns>
        public LeakDetector Next(int newPortCount)
        {
            CurrentPortCount = newPortCount;
            if (CurrentPortCount >= MinPortCount) // time to start using samples
            {
                // Used to signal that we've crossed the threshold
                if (!_minThresholdBreached)
                {
                    _minThresholdBreached = true;
                }

                Long  += CurrentPortCount;
                Short += CurrentPortCount;
            }
            else if (_minThresholdBreached) // fell back below minimum for first time
            {
                _minThresholdBreached = false;

                // reset averages back to starting position
                Long  = new EMWA(Long.Alpha, CurrentPortCount);
                Short = new EMWA(Short.Alpha, CurrentPortCount);
            }

            return(this);
        }