Package io.permazen.core.util
Class ObjIdBiMultiMap
java.lang.Object
io.permazen.core.util.ObjIdBiMultiMap
- All Implemented Interfaces:
Serializable
,Cloneable
A bi-directional, many-to-many mapping between
ObjId
s.
Instances can be thought of as containing a set of source, target ordered pairs. The many-to-many mapping can be efficiently queried and modified from either direction.
Instances of this class are thread-safe.
- See Also:
-
Constructor Summary
ConstructorDescriptionDefault constructor.ObjIdBiMultiMap
(int sourceCapacity, int targetCapacity) Constructs an instance with the given initial capacities. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add an association.boolean
Add multiple associations with a given source.void
clear()
Clear this instance.clone()
Clone this instance.boolean
containsSource
(ObjId source) Determine if this instance has any targets associated with the specified source.boolean
containsTarget
(ObjId target) Determine if this instance has any sources associated with the specified target.boolean
Compare for equality.int
Get the the number of sources that have one or more associated targets.int
Get the the number of targets that have one or more associated sources.Get all sources associated with this instance that have one or more associated targets.getSources
(ObjId target) Get the sources associated with the given target, if any.Get all targets associated with this instance that have one or more associated sources.getTargets
(ObjId source) Get the targets associated with the given source, if any.int
hashCode()
Calculate a hash code value for this instance.inverse()
Get an inverse view backed by this instance.boolean
Remove an association.boolean
Remove multiple associations with a given source.boolean
removeSource
(ObjId source) Remove all associations involving the specified source.boolean
removeTarget
(ObjId target) Remove all associations involving the specified target.toString()
Create aString
representation.
-
Constructor Details
-
ObjIdBiMultiMap
public ObjIdBiMultiMap()Default constructor. -
ObjIdBiMultiMap
public ObjIdBiMultiMap(int sourceCapacity, int targetCapacity) Constructs an instance with the given initial capacities.- Parameters:
sourceCapacity
- initial capacity for the number of sourcestargetCapacity
- initial capacity for the number of targets- Throws:
IllegalArgumentException
- if either value is negative
-
-
Method Details
-
getNumSources
public int getNumSources()Get the the number of sources that have one or more associated targets.- Returns:
- the number of sources contained in this instance
-
getNumTargets
public int getNumTargets()Get the the number of targets that have one or more associated sources.- Returns:
- the number of targets contained in this instance
-
getSources
Get all sources associated with this instance that have one or more associated targets.The returned
ObjIdSet
is mutable, but changes to it do not affect this instance.- Returns:
- all source ID's associated with this instance, possibly empty
-
getTargets
Get all targets associated with this instance that have one or more associated sources.The returned
ObjIdSet
is mutable, but changes to it do not affect this instance.- Returns:
- all targets ID's associated with this instance, possibly empty
-
getSources
Get the sources associated with the given target, if any.The returned
ObjIdSet
is mutable, but changes to it do not affect this instance.- Parameters:
target
- target ID- Returns:
- one or more source ID's associated with
target
, or null if there are none - Throws:
IllegalArgumentException
- iftarget
is null
-
getTargets
Get the targets associated with the given source, if any.The returned
ObjIdSet
is mutable, but changes to it do not affect this instance.- Parameters:
source
- source ID- Returns:
- one or more target ID's associated with
source
, or null if there are none - Throws:
IllegalArgumentException
- ifsource
is null
-
containsSource
Determine if this instance has any targets associated with the specified source.- Parameters:
source
- source ID- Returns:
- true if any target ID's are associated with
source
, otherwise false - Throws:
IllegalArgumentException
- ifsource
is null
-
containsTarget
Determine if this instance has any sources associated with the specified target.- Parameters:
target
- target ID- Returns:
- true if any source ID's are associated with
target
, otherwise false - Throws:
IllegalArgumentException
- iftarget
is null
-
add
Add an association.- Parameters:
source
- source IDtarget
- target ID- Returns:
- true if association was added, false if the association already existed
- Throws:
IllegalArgumentException
- ifsource
ortarget
is null
-
addAll
Add multiple associations with a given source.- Parameters:
source
- source IDtargets
- target ID's- Returns:
- true if any association was added, false if all associations already existed
- Throws:
IllegalArgumentException
- ifsource
,targets
, or any target in the iteration is null
-
remove
Remove an association.- Parameters:
source
- source IDtarget
- target ID- Returns:
- true if association was removed, false if the association did not exist
- Throws:
IllegalArgumentException
- ifsource
ortarget
is null
-
removeAll
Remove multiple associations with a given source.- Parameters:
source
- source IDtargets
- target ID's- Returns:
- true if any association was removed, false if none of the specified associations existed
- Throws:
IllegalArgumentException
- ifsource
,targets
, or any target in the iteration is null
-
removeSource
Remove all associations involving the specified source.- Parameters:
source
- source ID- Returns:
- true if any
source
association(s) were removed, false ifsource
had no target associations - Throws:
IllegalArgumentException
- ifsource
is null
-
removeTarget
Remove all associations involving the specified target.- Parameters:
target
- target ID- Returns:
- true if any
target
association(s) were removed, false iftarget
had no source associations - Throws:
IllegalArgumentException
- iftarget
is null
-
clear
public void clear()Clear this instance. -
inverse
Get an inverse view backed by this instance.The returned
ObjIdBiMultiMap
is a view in which sources become targets and vice-versa; any changes are reflected back in this instance.This method is efficient, requiring only constant time.
- Returns:
- inverse view of this instance
-
hashCode
public int hashCode()Calculate a hash code value for this instance. -
equals
Compare for equality. -
toString
Create aString
representation. -
clone
Clone this instance.
-