Package org.wicketstuff.security.util
Class ManyToManyMap<L,R>
- java.lang.Object
-
- org.wicketstuff.security.util.ManyToManyMap<L,R>
-
public class ManyToManyMap<L,R> extends Object
Maps keys to lists of values and values to lists of keys. The whole concept of key value is a bit vague here because each value is also a key. Consider the following example: A maps to B and C, B maps to D. get(A) would return B and C, get(B) would return A and D, get(C) would return A, get(D) would return B. Each mapping is bidirectional.- Author:
- marrink
-
-
Constructor Summary
Constructors Constructor Description ManyToManyMap()Creates map with default initial size and load factor.ManyToManyMap(int initialCapacity)Creates map with default load factor and specified initial size.ManyToManyMap(int initialCapacity, float loadFactor)Creates map with specified initial size and load factor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(L left, R right)Adds a key value mapping in this map.voidclear()Removes all mappings.booleancontainsLeft(L left)Check if this map contains a key.booleancontainsRight(R right)Check if this map contains a key.booleanequals(Object obj)Set<L>getLeft(R right)Gets the bidirectional mappings for this object.Set<R>getRight(L left)Gets the bidirectional mappings for this object.inthashCode()booleanisEmpty()Check if this map contains any mappings.Iterator<L>leftIterator()Returns an Iterator over every left hand mapping in this map.intnumberOfmappingsForLeft(L left)Returns the number of keys mapped to a value.intnumberOfmappingsForRight(R right)Returns the number of keys mapped to a value.booleanremove(L left, R right)Removes a many to many mapping between two objects.Set<R>removeAllMappingsForLeft(L left)Remove all mappings for an object.Set<L>removeAllMappingsForRight(R right)Remove all mappings for an object.Iterator<R>rightIterator()Returns an Iterator over every rightt hand mapping in this map.intsize()Returns the number of mapped values, left or rightStringtoString()
-
-
-
Constructor Detail
-
ManyToManyMap
public ManyToManyMap()
Creates map with default initial size and load factor.
-
ManyToManyMap
public ManyToManyMap(int initialCapacity)
Creates map with default load factor and specified initial size.- Parameters:
initialCapacity-
-
ManyToManyMap
public ManyToManyMap(int initialCapacity, float loadFactor)Creates map with specified initial size and load factor. For more information about these seeHashMap- Parameters:
initialCapacity-loadFactor-
-
-
Method Detail
-
add
public void add(L left, R right)
Adds a key value mapping in this map. Since this maps many to many relations no previous mappings will be overridden. The size of the map may or may not change depending on whether both objects are already present or not- Parameters:
left-right-
-
remove
public boolean remove(L left, R right)
Removes a many to many mapping between two objects. The size of the map may or may not change depending on on whether or not both objects have other mappings.- Parameters:
left- left side of the mappingright- right side of the mapping- Returns:
- false if the mapping did not exist, true otherwise
-
removeAllMappingsForLeft
public Set<R> removeAllMappingsForLeft(L left)
Remove all mappings for an object. The size of the map will at least decrease by one (if the object is present) but possibly more.- Parameters:
left- the left side of the many to many mapping- Returns:
- the mappings that will be removed by this action
-
removeAllMappingsForRight
public Set<L> removeAllMappingsForRight(R right)
Remove all mappings for an object. The size of the map will at least decrease by one (if the object is present) but possibly more.- Parameters:
right- the right side of the many to many mapping- Returns:
- the mappings that will be removed by this action
-
getRight
public Set<R> getRight(L left)
Gets the bidirectional mappings for this object.- Parameters:
left-- Returns:
- the many to many mappings for this object
-
getLeft
public Set<L> getLeft(R right)
Gets the bidirectional mappings for this object.- Parameters:
right-- Returns:
- the many to many mappings for this object
-
size
public int size()
Returns the number of mapped values, left or right- Returns:
- the number of mapped values
-
numberOfmappingsForLeft
public int numberOfmappingsForLeft(L left)
Returns the number of keys mapped to a value.- Parameters:
left-- Returns:
- the number of keys mapped to this value
-
numberOfmappingsForRight
public int numberOfmappingsForRight(R right)
Returns the number of keys mapped to a value.- Parameters:
right-- Returns:
- the number of keys mapped to this value
-
containsLeft
public boolean containsLeft(L left)
Check if this map contains a key.- Parameters:
left- a mapped object- Returns:
- true if this map contains the key, false otherwise
-
containsRight
public boolean containsRight(R right)
Check if this map contains a key.- Parameters:
right- a mapped object- Returns:
- true if this map contains the key, false otherwise
-
isEmpty
public boolean isEmpty()
Check if this map contains any mappings. If this map does is empty size will be 0.- Returns:
- true if no mappings are present, false otherwise
-
clear
public void clear()
Removes all mappings.
-
leftIterator
public Iterator<L> leftIterator()
Returns an Iterator over every left hand mapping in this map. In no particular order.- Returns:
- an iterator over this map
-
rightIterator
public Iterator<R> rightIterator()
Returns an Iterator over every rightt hand mapping in this map. In no particular order.- Returns:
- an iterator over this map
-
equals
public boolean equals(Object obj)
- Overrides:
equalsin classObject- See Also:
Object.equals(java.lang.Object)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classObject- See Also:
Object.hashCode()
-
toString
public String toString()
- Overrides:
toStringin classObject- See Also:
Object.toString()
-
-