getItem method
Get value by key pair (remote, local)
@param remote - remote address @param local - local address @return mapped value
Implementation
@override
V? getItem({K? remote, K? local}) {
K? key1, key2;
if (remote == null) {
assert(local != null, 'local & remote addresses should not empty at the same time');
key1 = local;
key2 = null;
} else {
key1 = remote;
key2 = local;
}
Map<K, V>? table = _map[key1];
if (table == null) {
return null;
}
V? value;
if (key2 != null) {
// mapping: (remote, local) => Connection
value = table[key2];
if (value != null) {
return value;
}
// take any Connection connected to remote
return table[_defaultKey];
}
// mapping: (remote, null) => Connection
// mapping: (local, null) => Connection
value = table[_defaultKey];
if (value != null) {
// take the value with empty key2
return value;
}
// take any Connection connected to remote / bound to local
for (V? v in table.values) {
if (v != null) {
return v;
}
}
return null;
}