-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
StandardSortedSetSemantics.java
70 lines (60 loc) · 2.02 KB
/
StandardSortedSetSemantics.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.collection.internal;
import java.util.Comparator;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.persister.collection.CollectionPersister;
/**
* @author Steve Ebersole
*/
public class StandardSortedSetSemantics<E> extends AbstractSetSemantics<SortedSet<E>,E> {
/**
* Singleton access
*/
public static final StandardSortedSetSemantics<?> INSTANCE = new StandardSortedSetSemantics<>();
private StandardSortedSetSemantics() {
}
@Override
public CollectionClassification getCollectionClassification() {
return CollectionClassification.SORTED_SET;
}
@Override
public Class<SortedSet> getCollectionJavaType() {
return SortedSet.class;
}
@Override
public SortedSet<E> instantiateRaw(
int anticipatedSize,
CollectionPersister collectionDescriptor) {
return new TreeSet<E>( (Comparator) collectionDescriptor.getSortingComparator() );
}
@Override
public PersistentCollection<E> instantiateWrapper(
Object key,
CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) {
final PersistentSortedSet<E> result = new PersistentSortedSet<>( session );
result.setComparator( (Comparator<E>) collectionDescriptor.getSortingComparator() );
return result;
}
@Override
public PersistentCollection<E> wrap(
SortedSet<E> rawCollection,
CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) {
return new PersistentSortedSet<>( session, rawCollection );
}
@Override
public Iterator<E> getElementIterator(SortedSet<E> rawCollection) {
return rawCollection.iterator();
}
}