upcastToSet<E> method

Set<E> upcastToSet<E>()

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 is null, an empty set is returned.
  • If source is a Set, it is directly converted using Set<E>.from.
  • If source is a HashSet, 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);