Class IdentifiableMap<T extends Identifiable>
java.lang.Object
org.tentackle.misc.IdentifiableMap<T>
- Type Parameters:
T- the identifiable type
- All Implemented Interfaces:
Serializable
A map of
Identifiables.
By default, the map uses a hashing key composed by the class and object id.
The first invocation of one of the methods getAllSorted() or getAllSorted(Class)
changes the map to treemap (which is a bit slower).
- Author:
- harald
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates anIdentifiablemap.IdentifiableMap(T object) Creates an object map with a single object. -
Method Summary
Modifier and TypeMethodDescriptionintadd(Collection<? extends T> objects) Adds a collection to the map.Adds an object to the map.voidclear()Clears the map.<P extends T>
PRetrieves an object from the map.getAll()Gets all objects in the map.Gets all objects sorted by class + ID.<P extends T>
Collection<P> getAllSorted(Class<P> clazz) Gets all objects for a given class.<P extends T>
PRemoves an object from the map.intremove(Collection<? extends T> objects) Removes a collection from the map.Removes an object from the map.
-
Constructor Details
-
IdentifiableMap
public IdentifiableMap()Creates anIdentifiablemap. -
IdentifiableMap
Creates an object map with a single object.- Parameters:
object- the object to add
-
-
Method Details
-
clear
public void clear()Clears the map. -
add
-
add
Adds a collection to the map.Objects already in the map are replaced but not counted.
- Parameters:
objects- the collection- Returns:
- the number of objects added
-
remove
-
remove
-
remove
Removes a collection from the map.Objects not in the map are ignored and not counted.
- Parameters:
objects- the object collection to remove- Returns:
- the number of objects removed
-
get
-
getAll
Gets all objects in the map.The returned objects are in the order they were appended.
- Returns:
- all objects
-
getAllSorted
-
getAllSorted
Gets all objects for a given class.- Type Parameters:
P- the given class- Parameters:
clazz- the object class- Returns:
- the objects sorted by ID, empty collection if none
-