Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: pkg/analysis_server/lib/src/utilities/average.dart

Issue 2894883002: Remove more libraries directives from server (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analysis_server.src.utilities.average;
6
7 /// Simple rolling average sample counter. 5 /// Simple rolling average sample counter.
8 class Average { 6 class Average {
9 num _val; 7 num _val;
10 final int _sampleCount; 8 final int _sampleCount;
11 9
12 /// Create an average with the given (optional) sample count size. 10 /// Create an average with the given (optional) sample count size.
13 Average([this._sampleCount = 20]); 11 Average([this._sampleCount = 20]);
14 12
15 /// The current average. 13 /// The current average.
16 num get value => _val ?? 0; 14 num get value => _val ?? 0;
17 15
18 /// Add the given [sample]. 16 /// Add the given [sample].
19 void addSample(num sample) { 17 void addSample(num sample) {
20 if (_val == null) { 18 if (_val == null) {
21 _val = sample; 19 _val = sample;
22 } else { 20 } else {
23 _val = _val * ((_sampleCount - 1) / _sampleCount) + 21 _val = _val * ((_sampleCount - 1) / _sampleCount) +
24 sample * (1 / _sampleCount); 22 sample * (1 / _sampleCount);
25 } 23 }
26 } 24 }
27 25
28 @override 26 @override
29 String toString() => 'average: $value'; 27 String toString() => 'average: $value';
30 } 28 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/status/validator.dart ('k') | pkg/analysis_server/lib/src/utilities/documentation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698