Pass sorted collection comparator as ctor argument

This commit is contained in:
Chris Cranford 2021-03-11 14:56:03 -05:00 committed by Christian Beikov
parent 5cf052775b
commit c2569bde4c
6 changed files with 16 additions and 18 deletions

View File

@ -41,20 +41,22 @@ public class PersistentSortedMap<K,E> extends PersistentMap<K,E> implements Sort
* Constructs a PersistentSortedMap.
*
* @param session The session
* @param comparator The sort comparator
*/
public PersistentSortedMap(SharedSessionContractImplementor session) {
public PersistentSortedMap(SharedSessionContractImplementor session, Comparator<K> comparator) {
super( session );
this.comparator = comparator;
}
/**
* Constructs a PersistentSortedMap.
*
* @param session The session
* @deprecated {@link #PersistentSortedMap(SharedSessionContractImplementor)} should be used instead.
* @deprecated {@link #PersistentSortedMap(SharedSessionContractImplementor, Comparator)} should be used instead.
*/
@Deprecated
public PersistentSortedMap(SessionImplementor session) {
this( (SharedSessionContractImplementor) session );
this( (SharedSessionContractImplementor) session, (Comparator<K>) null );
}
/**

View File

@ -38,20 +38,22 @@ public class PersistentSortedSet<E> extends PersistentSet<E> implements SortedSe
* Constructs a PersistentSortedSet
*
* @param session The session
* @param comparator The sort comparator
*/
public PersistentSortedSet(SharedSessionContractImplementor session) {
public PersistentSortedSet(SharedSessionContractImplementor session, Comparator<E> comparator) {
super( session );
this.comparator = comparator;
}
/**
* Constructs a PersistentSortedSet
*
* @param session The session
* @deprecated {@link #PersistentSortedSet(SharedSessionContractImplementor)} should be used instead.
* @deprecated {@link #PersistentSortedSet(SharedSessionContractImplementor, Comparator)} should be used instead.
*/
@Deprecated
public PersistentSortedSet(SessionImplementor session) {
this( (SharedSessionContractImplementor) session );
this( (SharedSessionContractImplementor) session, (Comparator<E>) null );
}
/**

View File

@ -49,9 +49,8 @@ public class StandardSortedMapSemantics<K,V> extends AbstractMapSemantics<Sorted
Object key,
CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) {
final PersistentSortedMap<K,V> result = new PersistentSortedMap<>( session );
result.setComparator( (Comparator<K>) collectionDescriptor.getSortingComparator() );
return result;
//noinspection unchecked
return new PersistentSortedMap<>( session, (Comparator<K>) collectionDescriptor.getSortingComparator() );
}
@Override

View File

@ -50,9 +50,8 @@ public class StandardSortedSetSemantics<E> extends AbstractSetSemantics<SortedSe
Object key,
CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) {
final PersistentSortedSet<E> result = new PersistentSortedSet<>( session );
result.setComparator( (Comparator<E>) collectionDescriptor.getSortingComparator() );
return result;
//noinspection unchecked
return new PersistentSortedSet<>( session, (Comparator<E>) collectionDescriptor.getSortingComparator() );
}
@Override

View File

@ -27,9 +27,7 @@ public class SortedMapType extends MapType {
@Override
public PersistentCollection instantiate(SharedSessionContractImplementor session, CollectionPersister persister, Object key) {
PersistentSortedMap map = new PersistentSortedMap(session);
map.setComparator(comparator);
return map;
return new PersistentSortedMap( session, comparator );
}
public Class getReturnedClass() {

View File

@ -26,9 +26,7 @@ public class SortedSetType extends SetType {
@Override
public PersistentCollection instantiate(SharedSessionContractImplementor session, CollectionPersister persister, Object key) {
PersistentSortedSet set = new PersistentSortedSet(session);
set.setComparator(comparator);
return set;
return new PersistentSortedSet( session, comparator );
}
public Class getReturnedClass() {