#include <coherence/util/TypedCollections.hpp>
Essentially these are auto-casting collections.
Each typed collection is templated based on one or more handle types to a const coherence::lang::Object Object. For instance: TypedCollection<String::View>
or TypedMap<String::View, Integer32::View>
Alternate handle types may also be used for added functionality, for example: TypedMap<String::View, BoxHandle<const Integer32> >
produces a TypedMap which will auto-box the supplied values to Integer32, making statements such as hMap->put("abc", 456)
possible.
These typed wrappers only provide a convenience over the underlying collection. Thus they cannot guarantee that external usage of the the underlying collection will not violate the restrictions imposed by the wrapper. For instance Objects of a type other then those specified by this template may exist within the collection. Any retrieval of those elements from the wrapper will result in ClassCastException. External usage is possible anytime the typed wrapper is passed by its inherited collection interface, i.e. passing a TypedMap as a plain Map.
Member functions which take no input parameters cannot have their return type changed. Instead there will be an auxiliary function with the same name plus a "Typed" suffix, e.g. TypedMap::keySetTyped().
Example usage:
typedef TypedCollections::TypedMap<String::View, Integer32::Handle> StringIntMap; StringIntMap::Handle hMap = StringIntMap::create(HashMap::create()); hMap->put("abc", Integer32::create(123)); // String's auto-boxing is utilized Integer32::Handle hInt = hMap->get("abc"); // no cast of return type required
Classes | |
class | TypedCollection |
Typed wrapper over Collection interface. More... | |
class | TypedEntry |
Typed wrapper over Map::Entry interface. More... | |
class | TypedIterator |
Typed wrapper over Iterator interface. More... | |
class | TypedList |
Typed wrapper over List interface. More... | |
class | TypedListIterator |
Typed wrapper over ListIterator interface. More... | |
class | TypedMap |
Typed wrapper over Map interface. More... | |
class | TypedSet |
Typed wrapper over Set interface. More... |