OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /** | 5 /** |
6 * Returns the concatenation of the input [iterables]. | 6 * Returns the concatenation of the input [iterables]. |
7 * | 7 * |
8 * The returned iterable is a lazily-evaluated view on the input iterables. | 8 * The returned iterable is a lazily-evaluated view on the input iterables. |
9 */ | 9 */ |
10 Iterable/*<E>*/ concat/*<E>*/(Iterable<Iterable/*<E>*/ > iterables) => | 10 Iterable/*<E>*/ concat/*<E>*/(Iterable<Iterable/*<E>*/ > iterables) => |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 * It will never grow larger than [capacity]. It's a LIFO queue - the last item | 52 * It will never grow larger than [capacity]. It's a LIFO queue - the last item |
53 * added will be the first one returned from [items]. | 53 * added will be the first one returned from [items]. |
54 */ | 54 */ |
55 class RecentBuffer<T> { | 55 class RecentBuffer<T> { |
56 final int capacity; | 56 final int capacity; |
57 | 57 |
58 List<T> _buffer = []; | 58 List<T> _buffer = []; |
59 | 59 |
60 RecentBuffer(this.capacity); | 60 RecentBuffer(this.capacity); |
61 | 61 |
| 62 Iterable<T> get items => _buffer.reversed; |
| 63 |
62 void add(T item) { | 64 void add(T item) { |
63 _buffer.add(item); | 65 _buffer.add(item); |
64 | 66 |
65 if (_buffer.length > capacity) { | 67 if (_buffer.length > capacity) { |
66 _buffer.removeAt(0); | 68 _buffer.removeAt(0); |
67 } | 69 } |
68 } | 70 } |
69 | |
70 Iterable<T> get items => _buffer.reversed; | |
71 } | 71 } |
OLD | NEW |