Skip to content

Commit

Permalink
v3.0.4
Browse files Browse the repository at this point in the history
- `collections`: improve Null Safety usage.
  • Loading branch information
gmpassos committed Mar 10, 2021
1 parent 780378c commit fbfa3fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.4

- `collections`: improve Null Safety usage.

## 3.0.3

- Null safety migration adjustments.
Expand Down
33 changes: 17 additions & 16 deletions lib/src/collections.dart
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ Map<String, String>? copyMapString(Map<String, String>? m) {
}

/// Gets a [map] entry ignoring key case.
MapEntry<String, V>? getEntryIgnoreCase<V>(Map<String, V> map, String? key) {
MapEntry<String, V?>? getEntryIgnoreCase<V>(Map<String, V?> map, String? key) {
if (key == null) return null;
var val = map[key];
if (val != null) return MapEntry(key, val);
Expand All @@ -591,8 +591,8 @@ MapEntry<String, V>? getEntryIgnoreCase<V>(Map<String, V> map, String? key) {

for (var k in map.keys) {
if (k.toLowerCase() == keyLC) {
V value = map[k]!;
return MapEntry<String, V>(k, value);
var value = map[k];
return MapEntry<String, V?>(k, value);
}
}

Expand Down Expand Up @@ -659,7 +659,7 @@ typedef CompareMapEntryFunction<K, V> = int Function(
MapEntry<K, V> entry1, MapEntry<K, V> entry2);

/// Returns a Map sorted by keys.
Map<K, V> sortMapEntriesByKey<K, V>(Map<K, V> map, [bool reversed = false]) =>
Map<K, V?> sortMapEntriesByKey<K, V>(Map<K, V?> map, [bool reversed = false]) =>
sortMapEntries(
map, (a, b) => parseComparable(a.key)!.compareTo(b.key), reversed);

Expand Down Expand Up @@ -1059,31 +1059,31 @@ Set<T> toNonNullSet<T>(Set? set, {bool forceTypeCast = true}) {
/// Finds in [map] a entry that has one of [keys].
///
/// [ignoreCase] If [true] ignores the case of the keys.
MapEntry<K, V>? findKeyEntry<K, V>(Map<K, V>? map, List<K>? keys,
MapEntry<K, V?>? findKeyEntry<K, V>(Map<K?, V?>? map, List<K>? keys,
[bool ignoreCase = false]) {
if (map == null || keys == null) return null;
if (map == null || keys == null || map.isEmpty || keys.isEmpty) return null;

if (ignoreCase) {
for (var key in keys) {
if (map.containsKey(key)) {
V value = map[key]!;
return MapEntry(key, value);
var value = map[key];
return MapEntry<K, V?>(key, value);
}

var keyLC = key.toString().toLowerCase();

for (var k in map.keys) {
for (var k in map.keys.whereType<K>()) {
if (k.toString().toLowerCase() == keyLC) {
V value = map[k]!;
return MapEntry<K, V>(k, value);
var value = map[k];
return MapEntry<K, V?>(k, value);
}
}
}
} else {
for (var key in keys) {
if (map.containsKey(key)) {
V value = map[key]!;
return MapEntry(key, value);
var value = map[key];
return MapEntry<K, V?>(key, value);
}
}
}
Expand All @@ -1094,7 +1094,7 @@ MapEntry<K, V>? findKeyEntry<K, V>(Map<K, V>? map, List<K>? keys,
/// Finds in [map] a value that has one of [keys].
///
/// [ignoreCase] If [true] ignores the case of the keys.
V? findKeyValue<K, V>(Map<K, V>? map, List<K>? keys,
V? findKeyValue<K, V>(Map<K?, V?>? map, List<K>? keys,
[bool ignoreCase = false]) {
var entry = findKeyEntry(map, keys, ignoreCase);
return entry != null ? entry.value : null;
Expand Down Expand Up @@ -1147,7 +1147,8 @@ V? findKeyPathValue<V>(Map? map, String? keyPath,
/// Finds in [map] a key that has one of [keys].
///
/// [ignoreCase] If [true] ignores the case of the keys.
K? findKeyName<K, V>(Map<K, V>? map, List<K>? keys, [bool ignoreCase = false]) {
K? findKeyName<K, V>(Map<K?, V?>? map, List<K>? keys,
[bool ignoreCase = false]) {
var entry = findKeyEntry(map, keys, ignoreCase);
return entry != null ? entry.key : null;
}
Expand Down Expand Up @@ -2171,7 +2172,7 @@ class NNField<T> {
final bool deepHashcode;

/// Optional value filter to apply before set.
final T Function(Object? value)? filter;
final T Function(dynamic value)? filter;

/// Optional value to apply before get.
final T Function(T value)? resolver;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: swiss_knife
description: Dart Useful Tools - collections, math, date, uri, json, events, resources, regexp, etc...
version: 3.0.3
version: 3.0.4
homepage: https://github.com/gmpassos/swiss_knife

environment:
Expand All @@ -13,7 +13,7 @@ dependencies:

dev_dependencies:
pedantic: ^1.11.0
test: ^1.16.5
test: ^1.16.7
#test_coverage: ^0.4.3

#dependency_overrides:
Expand Down

0 comments on commit fbfa3fd

Please sign in to comment.