Helper library that generates type-safe generic shallow copies from:
- Raw non-generic collections; and
- Generic collections of unknown types
- The library guarantees type safety of the values, which eliminates heap pollution
- The need for
@SuppressWarnings("unchecked")
annotation is eliminated in the client code - Since generating a new type-safe collection has a
O(N)
running time, please execute caution before deciding to convert large collections
Gradle
repositories {
mavenCentral()
}
dependencies {
compile("io.github.azagniotov:collection-type-safe-converter:1.0.1")
}
Check the TypeSafeConverter class for the available APIs.
final Map<String, SomeType> checkedMap = TypeSafeConverter.asCheckedHashMap(rawMapObject, String.class, SomeType.class);
final Map<String, SomeType> checkedMap = TypeSafeConverter.asCheckedMap(rawMapObject, String.class, SomeType.class, new LinkedHashMap<>());
final Set<SomeType> checkedSet = TypeSafeConverter.asCheckedLinkedHashSet(rawSetObject, SomeType.class);
final Set<SomeType> checkedSet = TypeSafeConverter.asCheckedCollection(rawSetObject, SomeType.class, new HashSet<>());
final Iterable<AnotherType> checkedSet = TypeSafeConverter.asCheckedIterable(rawSetObject, AnotherType.class);
final SomeType someType = TypeSafeConverter.as(SomeType.class, objectInstance)
MIT