Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The OSID Torrefacto package is a set of utilities to make one's life in Java a bit easier. These tools add a little sugar to some common Java interfaces to aid in their use with OSIDs.

Collections

These are utilities found in the net.okapia.osid.torrefacto.collect package.

IdHashMap

IdHashMap is a an extension of HashMap using OSID Ids as keys. 

Code Block
IdHashMap<OsidObject> map = new IdHashMap<>();
map.put(object.getId(), object);

TypeHashMap

TypeHashMap is a an extension of HashMap using OSID Types as keys. 

Code Block
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 Map are the following methods.

Code Block
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.

Code Block
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 Types and implements the Types interface. Types is Iterable and defines methods for the adding, removing, and conversions to arrays and Collection. 

Code Block
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.