properly genericize CollectionSemantics hierarchy

This commit is contained in:
Gavin King 2021-02-22 17:55:50 +01:00 committed by Christian Beikov
parent c44570757d
commit 222837df95
21 changed files with 140 additions and 150 deletions

View File

@ -28,28 +28,26 @@
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractBagSemantics<B extends Collection<?>> implements BagSemantics<B> { public abstract class AbstractBagSemantics<E> implements BagSemantics<Collection<E>,E> {
@Override @Override
public Class<B> getCollectionJavaType() { public Class<Collection> getCollectionJavaType() {
//noinspection unchecked return Collection.class;
return (Class) Collection.class;
} }
@Override @Override
@SuppressWarnings("unchecked") public Collection<E> instantiateRaw(
public B instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor) { CollectionPersister collectionDescriptor) {
if ( anticipatedSize < 1 ) { if ( anticipatedSize < 1 ) {
return (B) new ArrayList(); return new ArrayList<>();
} }
else { else {
return (B) CollectionHelper.arrayList( anticipatedSize ); return CollectionHelper.arrayList( anticipatedSize );
} }
} }
@Override @Override
public Iterator getElementIterator(B rawCollection) { public Iterator<E> getElementIterator(Collection<E> rawCollection) {
if ( rawCollection == null ) { if ( rawCollection == null ) {
return null; return null;
} }
@ -57,8 +55,7 @@ public Iterator getElementIterator(B rawCollection) {
} }
@Override @Override
@SuppressWarnings("unchecked") public void visitElements(Collection<E> rawCollection, Consumer<? super E> action) {
public void visitElements(B rawCollection, Consumer action) {
if ( rawCollection != null ) { if ( rawCollection != null ) {
rawCollection.forEach( action ); rawCollection.forEach( action );
} }

View File

@ -27,15 +27,14 @@
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractMapSemantics<M extends Map<?,?>> implements MapSemantics<M> { public abstract class AbstractMapSemantics<MKV extends Map<K,V>, K, V> implements MapSemantics<MKV,K,V> {
@Override @Override
public Class<M> getCollectionJavaType() { public Class<? extends Map> getCollectionJavaType() {
//noinspection unchecked return Map.class;
return (Class) Map.class;
} }
@Override @Override
public Iterator getKeyIterator(M rawMap) { public Iterator<K> getKeyIterator(MKV rawMap) {
if ( rawMap == null ) { if ( rawMap == null ) {
return null; return null;
} }
@ -44,16 +43,14 @@ public Iterator getKeyIterator(M rawMap) {
} }
@Override @Override
@SuppressWarnings("unchecked") public void visitKeys(MKV rawMap, Consumer<? super K> action) {
public void visitKeys(M rawMap, Consumer action) {
if ( rawMap != null ) { if ( rawMap != null ) {
rawMap.keySet().forEach( action ); rawMap.keySet().forEach( action );
} }
} }
@Override @Override
@SuppressWarnings("unchecked") public void visitEntries(MKV rawMap, BiConsumer<? super K, ? super V> action) {
public void visitEntries(M rawMap, BiConsumer action) {
if ( rawMap != null ) { if ( rawMap != null ) {
rawMap.forEach( action ); rawMap.forEach( action );
} }
@ -61,7 +58,7 @@ public void visitEntries(M rawMap, BiConsumer action) {
@Override @Override
public Iterator getElementIterator(Map rawMap) { public Iterator<V> getElementIterator(MKV rawMap) {
if ( rawMap == null ) { if ( rawMap == null ) {
return Collections.emptyIterator(); return Collections.emptyIterator();
} }
@ -70,8 +67,7 @@ public Iterator getElementIterator(Map rawMap) {
} }
@Override @Override
@SuppressWarnings("unchecked") public void visitElements(MKV rawMap, Consumer<? super V> action) {
public void visitElements(M rawMap, Consumer action) {
if ( rawMap != null ) { if ( rawMap != null ) {
rawMap.values().forEach( action ); rawMap.values().forEach( action );
} }

View File

@ -25,15 +25,14 @@
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractSetSemantics<S extends Set<?>> implements CollectionSemantics<S> { public abstract class AbstractSetSemantics<SE extends Set<E>,E> implements CollectionSemantics<SE,E> {
@Override @Override
public Class<S> getCollectionJavaType() { public Class<? extends Set> getCollectionJavaType() {
//noinspection unchecked return Set.class;
return (Class) Set.class;
} }
@Override @Override
public Iterator getElementIterator(Set rawCollection) { public Iterator<E> getElementIterator(SE rawCollection) {
if ( rawCollection == null ) { if ( rawCollection == null ) {
return null; return null;
} }
@ -41,8 +40,7 @@ public Iterator getElementIterator(Set rawCollection) {
} }
@Override @Override
@SuppressWarnings("unchecked") public void visitElements(SE rawCollection, Consumer<? super E> action) {
public void visitElements(S rawCollection, Consumer action) {
if ( rawCollection != null ) { if ( rawCollection != null ) {
rawCollection.forEach( action ); rawCollection.forEach( action );
} }

View File

@ -31,7 +31,7 @@
* *
* @author Gavin King * @author Gavin King
*/ */
public class PersistentArrayHolder extends AbstractPersistentCollection { public class PersistentArrayHolder<E> extends AbstractPersistentCollection<E> {
private static final CoreMessageLogger LOG = Logger.getMessageLogger( private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class, CoreMessageLogger.class,
PersistentArrayHolder.class.getName() PersistentArrayHolder.class.getName()

View File

@ -126,7 +126,7 @@ public void injectLoadedState(PluralAttributeMapping attributeMapping, List<?> l
assert bag == null; assert bag == null;
final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor(); final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor();
final CollectionSemantics<?> collectionSemantics = collectionDescriptor.getCollectionSemantics(); final CollectionSemantics<?,?> collectionSemantics = collectionDescriptor.getCollectionSemantics();
final int elementCount = loadingState == null ? 0 : loadingState.size(); final int elementCount = loadingState == null ? 0 : loadingState.size();

View File

@ -31,11 +31,11 @@
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardArraySemantics implements CollectionSemantics<Object[]> { public class StandardArraySemantics<E> implements CollectionSemantics<E[], E> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardArraySemantics INSTANCE = new StandardArraySemantics(); public static final StandardArraySemantics<?> INSTANCE = new StandardArraySemantics<>();
private StandardArraySemantics() { private StandardArraySemantics() {
} }
@ -51,7 +51,7 @@ public Class<Object[]> getCollectionJavaType() {
} }
@Override @Override
public Object[] instantiateRaw( public E[] instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor) { CollectionPersister collectionDescriptor) {
// return (Object[]) Array.newInstance( // return (Object[]) Array.newInstance(
@ -63,34 +63,33 @@ public Object[] instantiateRaw(
@Override @Override
public PersistentCollection instantiateWrapper( public PersistentCollection<E> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentArrayHolder( session, collectionDescriptor ); return new PersistentArrayHolder<>( session, collectionDescriptor );
} }
@Override @Override
public PersistentCollection wrap( public PersistentCollection<E> wrap(
Object rawCollection, E[] rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentArrayHolder( session, rawCollection ); return new PersistentArrayHolder<>( session, rawCollection );
} }
@Override @Override
public Iterator getElementIterator(Object[] rawCollection) { public Iterator<E> getElementIterator(E[] rawCollection) {
return Arrays.stream( rawCollection ).iterator(); return Arrays.stream( rawCollection ).iterator();
} }
@Override @Override
@SuppressWarnings("unchecked") public void visitElements(E[] array, Consumer<? super E> action) {
public void visitElements(Object[] array, Consumer action) {
if ( array == null ) { if ( array == null ) {
return; return;
} }
for ( Object element : array ) { for ( E element : array ) {
action.accept( element ); action.accept( element );
} }
} }

View File

@ -18,11 +18,11 @@
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardBagSemantics extends AbstractBagSemantics<Collection<?>> { public class StandardBagSemantics<E> extends AbstractBagSemantics<E> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardBagSemantics INSTANCE = new StandardBagSemantics(); public static final StandardBagSemantics<?> INSTANCE = new StandardBagSemantics<>();
private StandardBagSemantics() { private StandardBagSemantics() {
} }
@ -33,19 +33,19 @@ public CollectionClassification getCollectionClassification() {
} }
@Override @Override
public PersistentCollection instantiateWrapper( public PersistentCollection<E> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentBag( session ); return new PersistentBag<>( session );
} }
@Override @Override
public PersistentCollection wrap( public PersistentCollection<E> wrap(
Object rawCollection, Collection<E> rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentBag( session, (Collection) rawCollection ); return new PersistentBag<>( session, rawCollection );
} }
} }

View File

@ -7,7 +7,6 @@
package org.hibernate.collection.internal; package org.hibernate.collection.internal;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.collection.spi.CollectionSemantics; import org.hibernate.collection.spi.CollectionSemantics;
import org.hibernate.collection.spi.CollectionSemanticsResolver; import org.hibernate.collection.spi.CollectionSemanticsResolver;
import org.hibernate.mapping.Array; import org.hibernate.mapping.Array;

View File

@ -18,11 +18,11 @@
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardIdentifierBagSemantics<E> extends AbstractBagSemantics<Collection<?>> { public class StandardIdentifierBagSemantics<E> extends AbstractBagSemantics<E> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardIdentifierBagSemantics INSTANCE = new StandardIdentifierBagSemantics(); public static final StandardIdentifierBagSemantics<?> INSTANCE = new StandardIdentifierBagSemantics<>();
private StandardIdentifierBagSemantics() { private StandardIdentifierBagSemantics() {
} }
@ -33,18 +33,18 @@ public CollectionClassification getCollectionClassification() {
} }
@Override @Override
public PersistentCollection instantiateWrapper( public PersistentCollection<E> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentIdentifierBag( session ); return new PersistentIdentifierBag<>( session );
} }
@Override @Override
public PersistentCollection wrap( public PersistentCollection<E> wrap(
Object rawCollection, Collection<E> rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentIdentifierBag( session, (Collection) rawCollection ); return new PersistentIdentifierBag<>( session, rawCollection );
} }
} }

View File

@ -32,11 +32,11 @@
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardListSemantics implements CollectionSemantics<List> { public class StandardListSemantics<E> implements CollectionSemantics<List<E>, E> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardListSemantics INSTANCE = new StandardListSemantics(); public static final StandardListSemantics<?> INSTANCE = new StandardListSemantics<>();
private StandardListSemantics() { private StandardListSemantics() {
} }
@ -52,20 +52,19 @@ public Class<List> getCollectionJavaType() {
} }
@Override @Override
public List instantiateRaw( public List<E> instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor) { CollectionPersister collectionDescriptor) {
return CollectionHelper.arrayList( anticipatedSize ); return CollectionHelper.arrayList( anticipatedSize );
} }
@Override @Override
public Iterator getElementIterator(List rawCollection) { public Iterator<E> getElementIterator(List<E> rawCollection) {
return rawCollection.iterator(); return rawCollection.iterator();
} }
@Override @Override
@SuppressWarnings("unchecked") public void visitElements(List<E> rawCollection, Consumer<? super E> action) {
public void visitElements(List rawCollection, Consumer action) {
rawCollection.forEach( action ); rawCollection.forEach( action );
} }
@ -142,18 +141,18 @@ public CollectionInitializerProducer createInitializerProducer(
} }
@Override @Override
public PersistentCollection instantiateWrapper( public PersistentCollection<E> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentList( session ); return new PersistentList<>( session );
} }
@Override @Override
public PersistentCollection wrap( public PersistentCollection<E> wrap(
Object rawCollection, List<E> rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentList( session, (List) rawCollection ); return new PersistentList<>( session, rawCollection );
} }
} }

View File

@ -19,11 +19,11 @@
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardMapSemantics extends AbstractMapSemantics<Map<?,?>> { public class StandardMapSemantics<K,V> extends AbstractMapSemantics<Map<K,V>,K,V> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardMapSemantics INSTANCE = new StandardMapSemantics(); public static final StandardMapSemantics<?,?> INSTANCE = new StandardMapSemantics<>();
private StandardMapSemantics() { private StandardMapSemantics() {
} }
@ -34,25 +34,25 @@ public CollectionClassification getCollectionClassification() {
} }
@Override @Override
public Map<?, ?> instantiateRaw( public Map<K,V> instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor) { CollectionPersister collectionDescriptor) {
return CollectionHelper.mapOfSize( anticipatedSize ); return CollectionHelper.mapOfSize( anticipatedSize );
} }
@Override @Override
public PersistentCollection instantiateWrapper( public PersistentCollection<V> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentMap( session ); return new PersistentMap<>( session );
} }
@Override @Override
public PersistentCollection wrap( public PersistentCollection<V> wrap(
Object rawCollection, Map<K,V> rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentMap( session, (Map) rawCollection ); return new PersistentMap<>( session, rawCollection );
} }
} }

View File

@ -19,11 +19,11 @@
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardOrderedMapSemantics extends AbstractMapSemantics<LinkedHashMap<?,?>> { public class StandardOrderedMapSemantics<K,V> extends AbstractMapSemantics<LinkedHashMap<K,V>,K,V> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardOrderedMapSemantics INSTANCE = new StandardOrderedMapSemantics(); public static final StandardOrderedMapSemantics<?,?> INSTANCE = new StandardOrderedMapSemantics<>();
private StandardOrderedMapSemantics() { private StandardOrderedMapSemantics() {
} }
@ -34,30 +34,30 @@ public CollectionClassification getCollectionClassification() {
} }
@Override @Override
public LinkedHashMap<?, ?> instantiateRaw( public LinkedHashMap<K,V> instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor) { CollectionPersister collectionDescriptor) {
return anticipatedSize < 1 ? CollectionHelper.linkedMap() : CollectionHelper.linkedMapOfSize( anticipatedSize ); return anticipatedSize < 1 ? CollectionHelper.linkedMap() : CollectionHelper.linkedMapOfSize( anticipatedSize );
} }
@Override @Override
public PersistentCollection instantiateWrapper( public PersistentCollection<V> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentMap( session ); return new PersistentMap<>( session );
} }
@Override @Override
public PersistentCollection wrap( public PersistentCollection<V> wrap(
Object rawCollection, LinkedHashMap<K,V> rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentMap( session, (Map) rawCollection ); return new PersistentMap<>( session, rawCollection );
} }
@Override @Override
public Iterator getElementIterator(LinkedHashMap rawCollection) { public Iterator<V> getElementIterator(LinkedHashMap<K,V> rawCollection) {
return rawCollection.values().iterator(); return rawCollection.values().iterator();
} }
} }

View File

@ -6,24 +6,23 @@
*/ */
package org.hibernate.collection.internal; package org.hibernate.collection.internal;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.CollectionClassification; import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import java.util.Iterator;
import java.util.LinkedHashSet;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardOrderedSetSemantics extends AbstractSetSemantics<LinkedHashSet<?>> { public class StandardOrderedSetSemantics<E> extends AbstractSetSemantics<LinkedHashSet<E>,E> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardOrderedSetSemantics INSTANCE = new StandardOrderedSetSemantics(); public static final StandardOrderedSetSemantics<?> INSTANCE = new StandardOrderedSetSemantics<>();
private StandardOrderedSetSemantics() { private StandardOrderedSetSemantics() {
} }
@ -34,30 +33,30 @@ public CollectionClassification getCollectionClassification() {
} }
@Override @Override
public LinkedHashSet<?> instantiateRaw( public LinkedHashSet<E> instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor) { CollectionPersister collectionDescriptor) {
return anticipatedSize < 1 ? CollectionHelper.linkedSet() : CollectionHelper.linkedSetOfSize( anticipatedSize ); return anticipatedSize < 1 ? CollectionHelper.linkedSet() : CollectionHelper.linkedSetOfSize( anticipatedSize );
} }
@Override @Override
public PersistentCollection instantiateWrapper( public PersistentCollection<E> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentSet( session ); return new PersistentSet<>( session );
} }
@Override @Override
public PersistentCollection wrap( public PersistentCollection<E> wrap(
Object rawCollection, LinkedHashSet<E> rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentSet( session, (Set) rawCollection ); return new PersistentSet<>( session, rawCollection );
} }
@Override @Override
public Iterator getElementIterator(LinkedHashSet rawCollection) { public Iterator<E> getElementIterator(LinkedHashSet<E> rawCollection) {
return rawCollection.iterator(); return rawCollection.iterator();
} }
} }

View File

@ -17,11 +17,11 @@
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardSetSemantics extends AbstractSetSemantics<Set<?>> { public class StandardSetSemantics<E> extends AbstractSetSemantics<Set<E>,E> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardSetSemantics INSTANCE = new StandardSetSemantics(); public static final StandardSetSemantics<?> INSTANCE = new StandardSetSemantics<>();
private StandardSetSemantics() { private StandardSetSemantics() {
} }
@ -32,26 +32,26 @@ public CollectionClassification getCollectionClassification() {
} }
@Override @Override
public Set<?> instantiateRaw( public Set<E> instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor) { CollectionPersister collectionDescriptor) {
return anticipatedSize < 1 ? new HashSet<>() : CollectionHelper.setOfSize( anticipatedSize ); return anticipatedSize < 1 ? new HashSet<>() : CollectionHelper.setOfSize( anticipatedSize );
} }
@Override @Override
public PersistentSet instantiateWrapper( public PersistentSet<E> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentSet( session ); return new PersistentSet<>( session );
} }
@Override @Override
public PersistentSet wrap( public PersistentSet<E> wrap(
Object rawCollection, Set<E> rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentSet( session, (Set) rawCollection ); return new PersistentSet<>( session, rawCollection );
} }
} }

View File

@ -6,6 +6,7 @@
*/ */
package org.hibernate.collection.internal; package org.hibernate.collection.internal;
import java.util.Comparator;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
@ -17,11 +18,11 @@
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardSortedMapSemantics extends AbstractMapSemantics<SortedMap<?,?>> { public class StandardSortedMapSemantics<K,V> extends AbstractMapSemantics<SortedMap<K,V>,K,V> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardSortedMapSemantics INSTANCE = new StandardSortedMapSemantics(); public static final StandardSortedMapSemantics<?,?> INSTANCE = new StandardSortedMapSemantics<>();
private StandardSortedMapSemantics() { private StandardSortedMapSemantics() {
} }
@ -32,31 +33,30 @@ public CollectionClassification getCollectionClassification() {
} }
@Override @Override
public Class<SortedMap<?, ?>> getCollectionJavaType() { public Class<SortedMap> getCollectionJavaType() {
//noinspection unchecked return SortedMap.class;
return (Class) SortedMap.class;
} }
@Override @Override
public TreeMap<?, ?> instantiateRaw( public TreeMap<K,V> instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor) { CollectionPersister collectionDescriptor) {
return new TreeMap( collectionDescriptor.getSortingComparator() ); return new TreeMap<K,V>( (Comparator) collectionDescriptor.getSortingComparator() );
} }
@Override @Override
public PersistentCollection instantiateWrapper( public PersistentCollection<V> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentSortedMap( session ); return new PersistentSortedMap<>( session );
} }
@Override @Override
public PersistentCollection wrap( public PersistentCollection<V> wrap(
Object rawCollection, SortedMap<K,V> rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentSortedMap( session, (SortedMap) rawCollection ); return new PersistentSortedMap<>( session, rawCollection );
} }
} }

View File

@ -6,6 +6,7 @@
*/ */
package org.hibernate.collection.internal; package org.hibernate.collection.internal;
import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
@ -18,11 +19,11 @@
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class StandardSortedSetSemantics extends AbstractSetSemantics<SortedSet<?>> { public class StandardSortedSetSemantics<E> extends AbstractSetSemantics<SortedSet<E>,E> {
/** /**
* Singleton access * Singleton access
*/ */
public static final StandardSortedSetSemantics INSTANCE = new StandardSortedSetSemantics(); public static final StandardSortedSetSemantics<?> INSTANCE = new StandardSortedSetSemantics<>();
private StandardSortedSetSemantics() { private StandardSortedSetSemantics() {
} }
@ -33,36 +34,35 @@ public CollectionClassification getCollectionClassification() {
} }
@Override @Override
public Class<SortedSet<?>> getCollectionJavaType() { public Class<SortedSet> getCollectionJavaType() {
//noinspection unchecked return SortedSet.class;
return (Class) SortedSet.class;
} }
@Override @Override
public SortedSet instantiateRaw( public SortedSet<E> instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor) { CollectionPersister collectionDescriptor) {
return new TreeSet( collectionDescriptor.getSortingComparator() ); return new TreeSet<E>( (Comparator) collectionDescriptor.getSortingComparator() );
} }
@Override @Override
public PersistentCollection instantiateWrapper( public PersistentCollection<E> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentSortedSet( session ); return new PersistentSortedSet<>( session );
} }
@Override @Override
public PersistentCollection wrap( public PersistentCollection<E> wrap(
Object rawCollection, SortedSet<E> rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session) { SharedSessionContractImplementor session) {
return new PersistentSortedSet( session, (SortedSet) rawCollection ); return new PersistentSortedSet<>( session, rawCollection );
} }
@Override @Override
public Iterator getElementIterator(SortedSet<?> rawCollection) { public Iterator<E> getElementIterator(SortedSet<E> rawCollection) {
return rawCollection.iterator(); return rawCollection.iterator();
} }
} }

View File

@ -6,9 +6,11 @@
*/ */
package org.hibernate.collection.spi; package org.hibernate.collection.spi;
import java.util.Collection;
/** /**
* @author Andrea Boriero * @author Andrea Boriero
*/ */
public interface BagSemantics<B> extends CollectionSemantics<B> { public interface BagSemantics<BE extends Collection<E>, E> extends CollectionSemantics<BE,E> {
} }

View File

@ -30,31 +30,31 @@
* @author Gavin King * @author Gavin King
*/ */
@Incubating @Incubating
public interface CollectionSemantics<C> { public interface CollectionSemantics<CE, E> {
/** /**
* Get the classification of collections described by this semantic * Get the classification of collections described by this semantic
*/ */
CollectionClassification getCollectionClassification(); CollectionClassification getCollectionClassification();
Class<C> getCollectionJavaType(); Class<?> getCollectionJavaType();
C instantiateRaw( CE instantiateRaw(
int anticipatedSize, int anticipatedSize,
CollectionPersister collectionDescriptor); CollectionPersister collectionDescriptor);
PersistentCollection instantiateWrapper( PersistentCollection<E> instantiateWrapper(
Object key, Object key,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session); SharedSessionContractImplementor session);
PersistentCollection wrap( PersistentCollection<E> wrap(
Object rawCollection, CE rawCollection,
CollectionPersister collectionDescriptor, CollectionPersister collectionDescriptor,
SharedSessionContractImplementor session); SharedSessionContractImplementor session);
Iterator getElementIterator(C rawCollection); Iterator<E> getElementIterator(CE rawCollection);
void visitElements(C rawCollection, Consumer action); void visitElements(CE rawCollection, Consumer<? super E> action);
/** /**
* todo (6.0) : clean this contract up! * todo (6.0) : clean this contract up!

View File

@ -7,6 +7,7 @@
package org.hibernate.collection.spi; package org.hibernate.collection.spi;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -15,10 +16,10 @@
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface MapSemantics<M> extends CollectionSemantics<M> { public interface MapSemantics<MKV extends Map<K,V>,K,V> extends CollectionSemantics<MKV,V> {
Iterator getKeyIterator(M rawMap); Iterator<K> getKeyIterator(MKV rawMap);
void visitKeys(M rawMap, Consumer action); void visitKeys(MKV rawMap, Consumer<? super K> action);
void visitEntries(M rawMap, BiConsumer action); void visitEntries(MKV rawMap, BiConsumer<? super K,? super V> action);
} }

View File

@ -15,5 +15,5 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface CollectionMappingType<C> extends MappingType { public interface CollectionMappingType<C> extends MappingType {
CollectionSemantics<C> getCollectionSemantics(); CollectionSemantics<C,?> getCollectionSemantics();
} }

View File

@ -24,15 +24,15 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class CollectionJavaTypeDescriptor<C> extends AbstractTypeDescriptor<C> { public class CollectionJavaTypeDescriptor<C> extends AbstractTypeDescriptor<C> {
private final CollectionSemantics<C> semantics; private final CollectionSemantics<C,?> semantics;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CollectionJavaTypeDescriptor(Class<? extends C> type, CollectionSemantics<C> semantics) { public CollectionJavaTypeDescriptor(Class<? extends C> type, CollectionSemantics<C,?> semantics) {
super( (Class) type ); super( (Class) type );
this.semantics = semantics; this.semantics = semantics;
} }
public CollectionSemantics<C> getSemantics() { public CollectionSemantics<C,?> getSemantics() {
return semantics; return semantics;
} }