Class IdentifiableUtils


  • public class IdentifiableUtils
    extends Object
    Utilities for Identifiable.
    Author:
    poirigui
    • Constructor Detail

      • IdentifiableUtils

        public IdentifiableUtils()
    • Method Detail

      • getIds

        public static <T extends IdentifiableList<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 IdentifiableMap<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
      • toString

        public static <T extends IdentifiableString toString​(T identifiable,
                                                               Class<T> clazz)
        Converts an identifiable to string, avoiding its initialization of it is a proxy.
      • hash

        public static int hash​(Identifiable... identifiables)
        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.