mirror of
https://github.com/hanskokx/arcane_helper_utils.git
synced 2026-05-14 02:19:09 +02:00
v1.4.3
- Fixes `FixedSizeList` to take a generic `T` type, rather than explicitly a `String`
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 1.4.3
|
||||||
|
|
||||||
|
- [FIX] Ensure that `FixedSizeList` takes any type of object.
|
||||||
|
|
||||||
## 1.4.2
|
## 1.4.2
|
||||||
|
|
||||||
- Added the `isLeapYear` extension to the `DateTime` and `int` objects.
|
- Added the `isLeapYear` extension to the `DateTime` and `int` objects.
|
||||||
|
|||||||
@@ -2,20 +2,20 @@
|
|||||||
///
|
///
|
||||||
/// When a new element is added and the list reaches its maximum capacity,
|
/// 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.
|
/// the oldest element in the list is automatically removed to make space.
|
||||||
class FixedSizeList {
|
class FixedSizeList<T> {
|
||||||
final int _capacity;
|
final int _capacity;
|
||||||
final List<String> _list;
|
final List<T?> _list;
|
||||||
|
|
||||||
/// Creates a [FixedSizeList] with the specified [capacity].
|
/// Creates a [FixedSizeList] with the specified [capacity].
|
||||||
///
|
///
|
||||||
/// The initial list will be empty.
|
/// The initial list will be empty.
|
||||||
FixedSizeList(this._capacity) : _list = <String>[];
|
FixedSizeList(this._capacity) : _list = <T?>[];
|
||||||
|
|
||||||
/// Adds a new [element] to the list.
|
/// Adds a new [element] to the list.
|
||||||
///
|
///
|
||||||
/// If the list is already at its maximum [capacity], the oldest element
|
/// If the list is already at its maximum [capacity], the oldest element
|
||||||
/// will be removed before the new [element] is added.
|
/// will be removed before the new [element] is added.
|
||||||
void add(String element) {
|
void add(T? element) {
|
||||||
_list.add(element);
|
_list.add(element);
|
||||||
if (_list.length > _capacity) {
|
if (_list.length > _capacity) {
|
||||||
_list.removeAt(0);
|
_list.removeAt(0);
|
||||||
@@ -25,5 +25,5 @@ class FixedSizeList {
|
|||||||
/// Returns an unmodifiable view of the current items in the list.
|
/// Returns an unmodifiable view of the current items in the list.
|
||||||
///
|
///
|
||||||
/// This prevents external modification of the internal list.
|
/// This prevents external modification of the internal list.
|
||||||
List<String> get items => List.unmodifiable(_list);
|
List<T?> get items => List.unmodifiable(_list);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
name: arcane_helper_utils
|
name: arcane_helper_utils
|
||||||
description: Provides a variety of helpful utilities and extensions for Flutter
|
description: Provides a variety of helpful utilities and extensions for Flutter
|
||||||
and Dart.
|
and Dart.
|
||||||
version: 1.4.2
|
version: 1.4.3
|
||||||
repository: https://github.com/hanskokx/arcane_helper_utils
|
repository: https://github.com/hanskokx/arcane_helper_utils
|
||||||
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues
|
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user