io.hypersistence.utils.hibernate.query.DistinctListTransformer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hypersistence-utils-hibernate-63 Show documentation
Show all versions of hypersistence-utils-hibernate-63 Show documentation
Utilities for Spring and Hibernate ORM 6.3, 6.4, and 6.5
package io.hypersistence.utils.hibernate.query;
import org.hibernate.query.ResultListTransformer;
import java.util.List;
import java.util.stream.Collectors;
/**
* The {@link DistinctListTransformer} removes duplicates from the {@link List}
* of elements that were transformed by the {@link org.hibernate.query.TupleTransformer}.
*
* This is similar to the {@code DistinctResultTransformer} that was available in Hibernate 5.
*
* @author Vlad Mihalcea
* @since 2.21.0
*/
public class DistinctListTransformer implements ResultListTransformer {
public static final DistinctListTransformer INSTANCE = new DistinctListTransformer();
/**
* Deduplicates the provided List.
*
* @param collection collections to be deduplicated
* @return deduplicated List
*/
@Override
public List transformList(List collection) {
return (List) collection.stream().distinct().collect(Collectors.toList());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy