OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 pub.transcript; | |
6 | |
7 import 'dart:collection'; | 5 import 'dart:collection'; |
8 | 6 |
9 /// A rolling transcript of entries of type [T]. | 7 /// A rolling transcript of entries of type [T]. |
10 /// | 8 /// |
11 /// It has a maximum number of entries. If entries are added that exceed that | 9 /// It has a maximum number of entries. If entries are added that exceed that |
12 /// it discards entries from the *middle* of the transcript. Generally, in logs, | 10 /// it discards entries from the *middle* of the transcript. Generally, in logs, |
13 /// the first and last entries are the most important, so it maintains those. | 11 /// the first and last entries are the most important, so it maintains those. |
14 class Transcript<T> { | 12 class Transcript<T> { |
15 /// The maximum number of transcript entries. | 13 /// The maximum number of transcript entries. |
16 final int max; | 14 final int max; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 /// invoke [onGap]. | 62 /// invoke [onGap]. |
65 void forEach(void onEntry(T entry), [void onGap(int)]) { | 63 void forEach(void onEntry(T entry), [void onGap(int)]) { |
66 if (_oldest.isNotEmpty) { | 64 if (_oldest.isNotEmpty) { |
67 _oldest.forEach(onEntry); | 65 _oldest.forEach(onEntry); |
68 if (onGap != null) onGap(discarded); | 66 if (onGap != null) onGap(discarded); |
69 } | 67 } |
70 | 68 |
71 _newest.forEach(onEntry); | 69 _newest.forEach(onEntry); |
72 } | 70 } |
73 } | 71 } |
OLD | NEW |