KeyedJsonTable<T extends Comparable> class

A class representing a keyed JSON table.

This class extends the Iterable class and provides functionality for working with a table of JSON rows. Each row in the table is associated with a unique key value.

The KeyedJsonTable class has the following properties and methods:

  • keyName: The name of the key field in each JSON row.
  • table: The underlying JsonTable that holds the JSON rows.
  • operator []: Retrieves the JSON row with the specified key.
  • operator []=: Sets the JSON row with the specified key.
  • addAll: Adds multiple JSON rows to the table.
  • add: Adds a single JSON row to the table.
  • containsKey: Checks if a JSON row with the specified key exists in the table.
  • remove: Removes the JSON row with the specified key from the table.
  • clear: Clears all the JSON rows from the table.

Example usage:

var table = KeyedJsonTable<int>(keyName: 'id');
table.addAll(JsonTable.fromList([
  {'id': 1, 'name': 'John'},
  {'id': 2, 'name': 'Jane'},
]));

var row = table[1];
print(row); // {'id': 1, 'name': 'John'}

table[2] = {'id': 2, 'name': 'Jane Doe'};

print(table.containsKey(2)); // true

table.remove(1);
print(table.length); // 1

table.clear();
print(table.isEmpty); // true
Inheritance

Constructors

KeyedJsonTable({required string keyName, JsonTable items = const []})
Constructs a KeyedJsonTable with the specified keyName and items.

Properties

first → JsonRow
The first element.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
isEmpty → bool
Whether this collection has no elements.
no setterinherited
isNotEmpty → bool
Whether this collection has at least one element.
no setterinherited
iterator → Iterator<JsonRow>
Returns an iterator over the elements in the list.
no setteroverride
keyName → string
final
last → JsonRow
The last element.
no setterinherited
length → int
The number of elements in this Iterable.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
single → JsonRow
Checks that this iterable has only one element, and returns that element.
no setterinherited

Methods

add(JsonRow row, [bool override = false]) → T?
Add a row to this JsonTable. Only rows with valid Ids will be added. Return the ID
addAll(JsonTable rows, [bool override = false]) → Iterable<T>
Add rows to this JsonTable. Only rows with valid Ids will be added. Return a list of IDs
any(bool test(JsonRow element)) → bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() → Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
clear() → void
Removes all elements from the list.
contains(Object? element) → bool
Whether the collection contains an element equal to element.
inherited
containsKey(T key) → bool
Checks if the list contains the specified key. Returns true if the key is found, false otherwise.
elementAt(int index) → JsonRow
Returns the indexth element.
inherited
every(bool test(JsonRow element)) → bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(JsonRow element)) → Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(JsonRow element), {JsonRow orElse()?}) → JsonRow
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, JsonRow element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<JsonRow> other) → Iterable<JsonRow>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(JsonRow element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
getKey(JsonRow row) → T
Returns the value associated with the specified key in the JsonRow. The key must be of type T.
getMap<T1, T2>(T1 keyFunc(JsonRow), T2 valueFunc(JsonRow)) → Map<T1, T2>
Returns a map computed from the elements in the table using the provided keyFunc and valueFunc. The keyFunc is a function that takes a JsonRow and returns a value of type T1. The valueFunc is a function that takes a JsonRow and returns a value of type T2.
getMapEntry<T1, T2>(T key, T1 keyFunc(JsonRow), T2 valueFunc(JsonRow)) → MapEntry<T1, T2>
Returns a MapEntry with the key and value computed from the given key using the provided keyFunc and valueFunc. The keyFunc is a function that takes a JsonRow and returns a value of type T1. The valueFunc is a function that takes a JsonRow and returns a value of type T2.
getPair<T1, T2>(T key, (T1, T2) func(JsonRow)) → (T1, T2)
Returns a pair of values computed from the given key using the provided func and valueFunc. The func is a function that takes a JsonRow and returns a value of type T1. The valueFunc is a function that takes a JsonRow and returns a value of type T2.
getPairs<T1, T2>((T1, T2) func(JsonRow)) → List<(T1, T2)>
Returns a list of pairs computed from the elements in the table using the provided keyFunc and valueFunc. The keyFunc is a function that takes a JsonRow and returns a value of type T1. The valueFunc is a function that takes a JsonRow and returns a value of type T2.
join([String separator = ""]) → String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(JsonRow element), {JsonRow orElse()?}) → JsonRow
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(JsonRow e)) → Iterable<T>
The current elements of this iterable modified by toElement.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(JsonRow combine(JsonRow value, JsonRow element)) → JsonRow
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
reloadWith(JsonTable rows) → Iterable<T>
Reload the table with the provided rows. Only rows with valid Ids will be added.
remove(T key) → JsonRow?
Removes the JsonRow with the specified key from the list. Returns the removed JsonRow, or null if the key is not found.
singleWhere(bool test(JsonRow element), {JsonRow orElse()?}) → JsonRow
The single element that satisfies test.
inherited
skip(int count) → Iterable<JsonRow>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(JsonRow element)) → Iterable<JsonRow>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
take(int count) → Iterable<JsonRow>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(JsonRow element)) → Iterable<JsonRow>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable = true}) → List<JsonRow>
Creates a List containing the elements of this Iterable.
inherited
toSet() → Set<JsonRow>
Creates a Set containing the same elements as this iterable.
inherited
toString() → string
Returns a string representation of (some of) the elements of this.
inherited
where(bool test(JsonRow element)) → Iterable<JsonRow>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() → Iterable<R>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited
operator [](T key) → JsonRow?
Returns the JsonRow with the specified key, or null if not found.
operator []=(T key, JsonRow values) → void
Sets the JsonRow with the specified key to the given values.