Package ubic.gemma.persistence.util
Class IdentifiableUtils
- java.lang.Object
-
- ubic.gemma.persistence.util.IdentifiableUtils
-
public class IdentifiableUtils extends Object
Utilities forIdentifiable
.- Author:
- poirigui
-
-
Constructor Summary
Constructors Constructor Description IdentifiableUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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 <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>>toIdentifiableSet()
Collect results into an identifiable set.static <T extends Identifiable>
StringtoString(T identifiable, Class<T> clazz)
Converts an identifiable to string, avoiding its initialization of it is a proxy.
-
-
-
Method Detail
-
getIds
public static <T extends Identifiable> List<Long> getIds(Collection<T> entities)
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
public 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.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
public static <T extends Identifiable> Collector<T,?,Set<T>> 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:
Collectors.toSet()
-
toIdentifiableMap
public 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.This uses
Identifiable.getId()
for comparing elements, making the collection safe for holding proxies unlike aHashMap
that relies onObject.hashCode()
.
-
toString
public static <T extends Identifiable> String toString(T identifiable, Class<T> clazz)
Converts an identifiable to string, avoiding its initialization of it is a proxy.
-
equals
public static <T extends Identifiable> boolean equals(@Nullable T a, @Nullable T b)
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)
.
-
-