AdaptableMap constructor
AdaptableMap()
A specialized map collection that can adapt itself or another source into a strongly-typed Map of keys and values.
The AdaptableMap extends HashMap<Object, Object> and provides a generic adapt method to convert:
- JetLeaf-specific HashMap
- Dart collection.HashMap
- Native Dart Map
into a
Map<K, V>.
Purpose
This class is intended to:
- Facilitate type-safe conversion for heterogeneous or dynamic maps.
- Allow seamless adaptation between JetLeaf and standard Dart map types.
- Support framework-level or service-level map transformation.
Features
- Generic adaptation: Converts keys and values to types
KandV. - Multiple source types: Supports HashMap, collection.HashMap, and Map.
- Exception safety: Throws IllegalArgumentException if adaptation is not possible.
Lifecycle and Usage
final adaptable = AdaptableMap();
adaptable['key'] = 42;
final typedMap = adaptable.adapt<String, int>(); // Map<String, int>
final source = collection.HashMap<dynamic, dynamic>();
source['name'] = 'JetLeaf';
final map = adaptable.adapt<String, String>(source); // Map<String, String>
Extensibility
- Subclass AdaptableMap to implement custom key/value conversion rules.
- Can integrate with conversion services or framework-specific registries.
Error Handling
- Throws IllegalArgumentException for unsupported sources.
See Also
Implementation
AdaptableMap();