- Fixes `FixedSizeList` to take a generic `T` type, rather than
explicitly a `String`
This commit is contained in:
2025-05-16 13:08:39 +02:00
parent 363fb20665
commit 176efdf458
3 changed files with 10 additions and 6 deletions
+5 -5
View File
@@ -2,20 +2,20 @@
///
/// When a new element is added and the list reaches its maximum capacity,
/// the oldest element in the list is automatically removed to make space.
class FixedSizeList {
class FixedSizeList<T> {
final int _capacity;
final List<String> _list;
final List<T?> _list;
/// Creates a [FixedSizeList] with the specified [capacity].
///
/// The initial list will be empty.
FixedSizeList(this._capacity) : _list = <String>[];
FixedSizeList(this._capacity) : _list = <T?>[];
/// Adds a new [element] to the list.
///
/// If the list is already at its maximum [capacity], the oldest element
/// will be removed before the new [element] is added.
void add(String element) {
void add(T? element) {
_list.add(element);
if (_list.length > _capacity) {
_list.removeAt(0);
@@ -25,5 +25,5 @@ class FixedSizeList {
/// Returns an unmodifiable view of the current items in the list.
///
/// This prevents external modification of the internal list.
List<String> get items => List.unmodifiable(_list);
List<T?> get items => List.unmodifiable(_list);
}