@ThreadSafe public class ObjIdBiMultiMap extends Object implements Cloneable, Serializable
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.
Constructor and Description |
---|
ObjIdBiMultiMap()
Default constructor.
|
ObjIdBiMultiMap(int sourceCapacity,
int targetCapacity)
Constructs an instance with the given initial capacities.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(ObjId source,
ObjId target)
Add an association.
|
boolean |
addAll(ObjId source,
Iterable<? extends ObjId> targets)
Add multiple associations with a given source.
|
void |
clear()
Clear this instance.
|
ObjIdBiMultiMap |
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 |
equals(Object obj)
Compare for equality.
|
int |
getNumSources()
Get the the number of sources that have one or more associated targets.
|
int |
getNumTargets()
Get the the number of targets that have one or more associated sources.
|
ObjIdSet |
getSources()
Get all sources associated with this instance that have one or more associated targets.
|
ObjIdSet |
getSources(ObjId target)
Get the sources associated with the given target, if any.
|
ObjIdSet |
getTargets()
Get all targets associated with this instance that have one or more associated sources.
|
ObjIdSet |
getTargets(ObjId source)
Get the targets associated with the given source, if any.
|
int |
hashCode()
Calculate a hash code value for this instance.
|
ObjIdBiMultiMap |
inverse()
Get an inverse view backed by this instance.
|
boolean |
remove(ObjId source,
ObjId target)
Remove an association.
|
boolean |
removeAll(ObjId source,
Iterable<? extends ObjId> targets)
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.
|
String |
toString()
Create a
String representation. |
public ObjIdBiMultiMap()
public ObjIdBiMultiMap(int sourceCapacity, int targetCapacity)
sourceCapacity
- initial capacity for the number of sourcestargetCapacity
- initial capacity for the number of targetsIllegalArgumentException
- if either value is negativepublic int getNumSources()
public int getNumTargets()
public ObjIdSet getSources()
The returned ObjIdSet
is mutable, but changes to it do not affect this instance.
public ObjIdSet getTargets()
The returned ObjIdSet
is mutable, but changes to it do not affect this instance.
public ObjIdSet getSources(ObjId target)
The returned ObjIdSet
is mutable, but changes to it do not affect this instance.
target
- target IDtarget
, or null if there are noneIllegalArgumentException
- if target
is nullpublic ObjIdSet getTargets(ObjId source)
The returned ObjIdSet
is mutable, but changes to it do not affect this instance.
source
- source IDsource
, or null if there are noneIllegalArgumentException
- if source
is nullpublic boolean containsSource(ObjId source)
source
- source IDsource
, otherwise falseIllegalArgumentException
- if source
is nullpublic boolean containsTarget(ObjId target)
target
- target IDtarget
, otherwise falseIllegalArgumentException
- if target
is nullpublic boolean add(ObjId source, ObjId target)
source
- source IDtarget
- target IDIllegalArgumentException
- if source
or target
is nullpublic boolean addAll(ObjId source, Iterable<? extends ObjId> targets)
source
- source IDtargets
- target ID'sIllegalArgumentException
- if source
, targets
, or any target in the iteration is nullpublic boolean remove(ObjId source, ObjId target)
source
- source IDtarget
- target IDIllegalArgumentException
- if source
or target
is nullpublic boolean removeAll(ObjId source, Iterable<? extends ObjId> targets)
source
- source IDtargets
- target ID'sIllegalArgumentException
- if source
, targets
, or any target in the iteration is nullpublic boolean removeSource(ObjId source)
source
- source IDsource
association(s) were removed, false if source
had no target associationsIllegalArgumentException
- if source
is nullpublic boolean removeTarget(ObjId target)
target
- target IDtarget
association(s) were removed, false if target
had no source associationsIllegalArgumentException
- if target
is nullpublic void clear()
public ObjIdBiMultiMap inverse()
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.
public int hashCode()
public ObjIdBiMultiMap clone()
Copyright © 2022. All rights reserved.