Bläddra i källkod

migrated lru_map.dart to null safety

ashilkn 2 år sedan
förälder
incheckning
881353fde4
1 ändrade filer med 5 tillägg och 7 borttagningar
  1. 5 7
      lib/core/cache/lru_map.dart

+ 5 - 7
lib/core/cache/lru_map.dart

@@ -1,5 +1,3 @@
-// @dart=2.9
-
 import 'dart:collection';
 import 'dart:collection';
 
 
 typedef EvictionHandler<K, V> = Function(K key, V value);
 typedef EvictionHandler<K, V> = Function(K key, V value);
@@ -7,12 +5,12 @@ typedef EvictionHandler<K, V> = Function(K key, V value);
 class LRUMap<K, V> {
 class LRUMap<K, V> {
   final LinkedHashMap<K, V> _map = LinkedHashMap<K, V>();
   final LinkedHashMap<K, V> _map = LinkedHashMap<K, V>();
   final int _maxSize;
   final int _maxSize;
-  final EvictionHandler<K, V> _handler;
+  final EvictionHandler<K, V?>? _handler;
 
 
   LRUMap(this._maxSize, [this._handler]);
   LRUMap(this._maxSize, [this._handler]);
 
 
-  V get(K key) {
-    final V value = _map.remove(key);
+  V? get(K key) {
+    final V? value = _map.remove(key);
     if (value != null) {
     if (value != null) {
       _map[key] = value;
       _map[key] = value;
     }
     }
@@ -24,9 +22,9 @@ class LRUMap<K, V> {
     _map[key] = value;
     _map[key] = value;
     if (_map.length > _maxSize) {
     if (_map.length > _maxSize) {
       final K evictedKey = _map.keys.first;
       final K evictedKey = _map.keys.first;
-      final V evictedValue = _map.remove(evictedKey);
+      final V? evictedValue = _map.remove(evictedKey);
       if (_handler != null) {
       if (_handler != null) {
-        _handler(evictedKey, evictedValue);
+        _handler!(evictedKey, evictedValue);
       }
       }
     }
     }
   }
   }