upcastToSet<E> method
A TypeAdapter
that adapts a raw Object into a strongly typed Set of
type E
.
Jetleaf’s conversion service may return Iterable<Object>
, Set<Object>
,
or HashSet
. This adapter ensures that the raw input is converted into a
Dart Set<E>
.
- If
source
isnull
, an empty set is returned. - If
source
is aSet
, it is directly converted usingSet<E>.from
. - If
source
is aHashSet
, elements are cast and added to a new set. - Otherwise, an
IllegalArgumentException
is thrown.
Example
final adapter = SetAdapter<int>();
final set = adapter.adapt({1, 2, 3}); // {1, 2, 3}
final rawHashSet = HashSet()..addAll([5, 6, 7]);
final adapted = adapter.adapt(rawHashSet); // {5, 6, 7}
final empty = adapter.adapt(null); // {}
Implementation
Set<E> upcastToSet<E>() => SetAdapter<E>().adapt(this);