Collections
Summary
These are utilities found in the net.okapia.osid.torrefacto.collect package.
Classes
IdHashMap
IdHashMap is a an extension of HashMap using OSID Ids as keys.Â
IdHashMap<OsidObject> map = new IdHashMap<>(); map.put(object.getId(), object);
TypeHashMap
TypeHashMap is a an extension of HashMap using OSID Types as keys.Â
TypeHashMap<OsidObject> map = new TypeHashMap<>(); map.put(object.getGenusType(), object);
MultiMaps and MultiHashMaps
A MultiMap is similar to java.util.Map but manages multiple values per key. MultiHashMap is an implementation of this interface.
The difference between MultiMap and java.util.Map are the following methods.
public java.util.Collection<V> get(K key); public void putAll(K key, java.util.Collection<V> values); public void putAll(java.util.Map<K, java.util.Collection<V>> map); public void putAll(MultiMap<K, V> map); public void remove(K key, V value); public void removeValue(V value); public java.util.Map<K, java.util.Collection<V>> asMap();
IdMultiHashMap and TypeMultiHashMap are convenience wrappers defining the keys as Ids and Types respectively.
TypeMultiHashMap<OsidObject> map = new TypeMultiHashMap<>(); map.put(type, object1); map.put(type, object2); map.put(type, object3); for (OsidObject o : map.get(type)) { ... }
MultiMaps return an empty collection if the key is not known as opposed to a null.
This package contains its own Collections utility class that wraps MultiHashMaps to be synchronized or unmodifiable.
Sets
TypeSet is a collection of osid.type.Types and implements the Types interface. Types is Iterable and defines methods for the adding, removing, and conversions to arrays and Collection.Â
Types types = new TypeSet(); types.add(type1); types.add(type2); if (!types.contains(type1)) { throw new org.osid.UnsupportedException(type1 + " not supported"); } for (Type type : types) { ... }
TypeRefSet is a variant of TypeSet that maintains reference counts for managing type support in managers where type support is variant among other providers.