// SSDLPediapackageil.ac.technion.cs.ssdl.collections;
importil.ac.technion.cs.ssdl.stereotypes.Canopy;
importjava.util.*;
/** * A 1-to-many mapping, that is: a relation where each source value is * associated with several "images". This class is in fact a façade for * an instance of the JRE's Map in which the mapping range is a * Set. * * Author: Itay Maman <[email protected]> * <K> Type of source values * <V> Type of images */@CanopypublicfinalclassMultiMap<K, V> implementsIterable<K> {
/** * Create a new empty MultiMap */publicMultiMap() {
implementation = newHashMap<K, Set<V>>();
}
/** * Create a new empty MultiMap with a given capacity * * initialCapacity initial capacity of the map */publicMultiMap(finalintinitialCapacity) {
this(initialCapacity, 0.75f);
}
/** * Create a new empty MultiMap with a given capacity and load factor * * initialCapacity initial capacity of the map * loadFactor recreate map if it is filled to this extent */publicMultiMap(finalintinitialCapacity, finalfloatloadFactor) {
implementation = newHashMap<K, Set<V>>(initialCapacity, loadFactor);
}
@OverridepublicStringtoString() {
finalStringBuilder$ = newStringBuilder();
for (finalKk : this)
$.append(k + "=>" + get(k) + '\n');
return$.toString();
}
/** * Obtain all images * * Return: Set of V objects */publicSet<V> values() {
finalSet<V> $ = newHashSet<V>();
for (finalSet<V> curr : implementation.values())
$.addAll(curr);
return$;
}
/** * Add an image to the given source value * * k Source value * v Image value */publicvoidput(finalKk, finalVv) {
get(k).add(v);
}
/** * Find the set of all images of the given source value. If this key does * not exist yet, add it with an empty set. * * k key value * Return: A non-null representing the set of images * associated with k */publicSet<V> get(finalKk) {
finalSet<V> $ = implementation.get(k);
return$ != null ? $ : clear(k);
}
/** * Clear the set of all images of the given source value * * k Source value * Return: the newly created set object */publicSet<V> clear(finalKk) {
finalSet<V> $ = newHashSet<V>();
implementation.put(k, $);
return$;
}
/** * Return an iterator over all keys * * Return: Iterator<K> object */publicIterator<K> iterator() {
returnimplementation.keySet().iterator();
}
/** * How many keys are stored in this map? * * Return: number of keys */publicintsize() {
returnimplementation.size();
}
/** * Actual implementation */privatefinalHashMap<K, Set<V>> implementation;
}
Metrics
Metric
Value
Acronym
Explanation
LOC
122
Lines Of Code
Total number of lines in the code
SCC
21
SemiColons Count
Total number of semicolon tokens found in the code.
NOT
366
Number Of Tokens
Comments, whitespace and text which cannot be made into a token not included.
VCC
2294
Visible Characters Count
The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters.
CCC
1053
Code Characters Count
Total number of non-white characters in tokens. White space characters in string and character literals are not counted.
UIC
38
Unique Identifiers Count
The number of different identifiers found in the code