Package ubic.gemma.persistence.util
Class IdentifiableUtils
java.lang.Object
ubic.gemma.persistence.util.IdentifiableUtils
Utilities for
Identifiable
.- Author:
- poirigui
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Identifiable>
booleanequals
(T a, T b) Compare two identifiables of the same type without risking initializing them.static <T extends Identifiable>
Map<Long, T> getIdMap
(Collection<T> entities) Given a set of entities, create a map of their ids to the entities.static <T extends Identifiable>
List<Long> getIds
(Collection<T> entities) Convert a collection of identifiable to their IDs.static int
hash
(Identifiable... identifiables) Hash identifiables in a proxy-safe way using their IDs.static <T,
K extends Identifiable, U>
Collector<T, ?, Map<K, U>> toIdentifiableMap
(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) Collect results into an identifiable map.static <T extends Identifiable>
Collector<T, ?, Set<T>> Collect results into an identifiable set.static <T extends Identifiable>
StringConverts an identifiable to string, avoiding its initialization of it is a proxy.
-
Constructor Details
-
IdentifiableUtils
public IdentifiableUtils()
-
-
Method Details
-
getIds
Convert a collection of identifiable to their IDs.- Parameters:
entities
- entities- Returns:
- returns a collection of IDs. Avoids using reflection by requiring that the given entities all implement the Identifiable interface.
-
getIdMap
Given a set of entities, create a map of their ids to the entities.Note: If more than one entity share the same ID, there is no guarantee on which will be kept in the final mapping. If the collection is ordered, the first encountered entity will be kept.
- Type Parameters:
T
- the type- Parameters:
entities
- where id is called "id"- Returns:
- the created map
-
toIdentifiableSet
Collect results into an identifiable set.This uses
Identifiable.getId()
for comparing elements, making the collection safe for holding proxies unlike aHashSet
that relies onObject.hashCode()
.- See Also:
-
toIdentifiableMap
public static <T,K extends Identifiable, Collector<T,U> ?, toIdentifiableMapMap<K, U>> (Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) Collect results into an identifiable map.This uses
Identifiable.getId()
for comparing elements, making the collection safe for holding proxies unlike aHashMap
that relies onObject.hashCode()
.- See Also:
-
toString
Converts an identifiable to string, avoiding its initialization of it is a proxy. -
hash
Hash identifiables in a proxy-safe way using their IDs.Hashing an entity that does ont have an assigned ID is not allowed as its hash code would change once persisted.
-
equals
Compare two identifiables of the same type without risking initializing them.- Returns:
- true if they have the same ID or are equal according to
Objects.equals(Object, Object)
.
-