From 222837df9563a480d74fc09ad8077ae1a1ebc7b4 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Mon, 22 Feb 2021 17:55:50 +0100 Subject: [PATCH] properly genericize CollectionSemantics hierarchy --- .../internal/AbstractBagSemantics.java | 19 ++++++-------- .../internal/AbstractMapSemantics.java | 20 ++++++-------- .../internal/AbstractSetSemantics.java | 12 ++++----- .../internal/PersistentArrayHolder.java | 2 +- .../collection/internal/PersistentBag.java | 2 +- .../internal/StandardArraySemantics.java | 23 ++++++++-------- .../internal/StandardBagSemantics.java | 14 +++++----- .../StandardCollectionSemanticsResolver.java | 1 - .../StandardIdentifierBagSemantics.java | 14 +++++----- .../internal/StandardListSemantics.java | 21 +++++++-------- .../internal/StandardMapSemantics.java | 16 ++++++------ .../internal/StandardOrderedMapSemantics.java | 18 ++++++------- .../internal/StandardOrderedSetSemantics.java | 25 +++++++++--------- .../internal/StandardSetSemantics.java | 16 ++++++------ .../internal/StandardSortedMapSemantics.java | 24 ++++++++--------- .../internal/StandardSortedSetSemantics.java | 26 +++++++++---------- .../collection/spi/BagSemantics.java | 4 ++- .../collection/spi/CollectionSemantics.java | 16 ++++++------ .../collection/spi/MapSemantics.java | 9 ++++--- .../mapping/CollectionMappingType.java | 2 +- .../spi/CollectionJavaTypeDescriptor.java | 6 ++--- 21 files changed, 140 insertions(+), 150 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractBagSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractBagSemantics.java index 39539f972f..312cf14994 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractBagSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractBagSemantics.java @@ -28,28 +28,26 @@ /** * @author Steve Ebersole */ -public abstract class AbstractBagSemantics> implements BagSemantics { +public abstract class AbstractBagSemantics implements BagSemantics,E> { @Override - public Class getCollectionJavaType() { - //noinspection unchecked - return (Class) Collection.class; + public Class getCollectionJavaType() { + return Collection.class; } @Override - @SuppressWarnings("unchecked") - public B instantiateRaw( + public Collection instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor) { if ( anticipatedSize < 1 ) { - return (B) new ArrayList(); + return new ArrayList<>(); } else { - return (B) CollectionHelper.arrayList( anticipatedSize ); + return CollectionHelper.arrayList( anticipatedSize ); } } @Override - public Iterator getElementIterator(B rawCollection) { + public Iterator getElementIterator(Collection rawCollection) { if ( rawCollection == null ) { return null; } @@ -57,8 +55,7 @@ public Iterator getElementIterator(B rawCollection) { } @Override - @SuppressWarnings("unchecked") - public void visitElements(B rawCollection, Consumer action) { + public void visitElements(Collection rawCollection, Consumer action) { if ( rawCollection != null ) { rawCollection.forEach( action ); } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractMapSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractMapSemantics.java index 87071f8045..ade746b2f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractMapSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractMapSemantics.java @@ -27,15 +27,14 @@ /** * @author Steve Ebersole */ -public abstract class AbstractMapSemantics> implements MapSemantics { +public abstract class AbstractMapSemantics, K, V> implements MapSemantics { @Override - public Class getCollectionJavaType() { - //noinspection unchecked - return (Class) Map.class; + public Class getCollectionJavaType() { + return Map.class; } @Override - public Iterator getKeyIterator(M rawMap) { + public Iterator getKeyIterator(MKV rawMap) { if ( rawMap == null ) { return null; } @@ -44,16 +43,14 @@ public Iterator getKeyIterator(M rawMap) { } @Override - @SuppressWarnings("unchecked") - public void visitKeys(M rawMap, Consumer action) { + public void visitKeys(MKV rawMap, Consumer action) { if ( rawMap != null ) { rawMap.keySet().forEach( action ); } } @Override - @SuppressWarnings("unchecked") - public void visitEntries(M rawMap, BiConsumer action) { + public void visitEntries(MKV rawMap, BiConsumer action) { if ( rawMap != null ) { rawMap.forEach( action ); } @@ -61,7 +58,7 @@ public void visitEntries(M rawMap, BiConsumer action) { @Override - public Iterator getElementIterator(Map rawMap) { + public Iterator getElementIterator(MKV rawMap) { if ( rawMap == null ) { return Collections.emptyIterator(); } @@ -70,8 +67,7 @@ public Iterator getElementIterator(Map rawMap) { } @Override - @SuppressWarnings("unchecked") - public void visitElements(M rawMap, Consumer action) { + public void visitElements(MKV rawMap, Consumer action) { if ( rawMap != null ) { rawMap.values().forEach( action ); } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractSetSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractSetSemantics.java index 565b85cf2a..a7628caab9 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractSetSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractSetSemantics.java @@ -25,15 +25,14 @@ /** * @author Steve Ebersole */ -public abstract class AbstractSetSemantics> implements CollectionSemantics { +public abstract class AbstractSetSemantics,E> implements CollectionSemantics { @Override - public Class getCollectionJavaType() { - //noinspection unchecked - return (Class) Set.class; + public Class getCollectionJavaType() { + return Set.class; } @Override - public Iterator getElementIterator(Set rawCollection) { + public Iterator getElementIterator(SE rawCollection) { if ( rawCollection == null ) { return null; } @@ -41,8 +40,7 @@ public Iterator getElementIterator(Set rawCollection) { } @Override - @SuppressWarnings("unchecked") - public void visitElements(S rawCollection, Consumer action) { + public void visitElements(SE rawCollection, Consumer action) { if ( rawCollection != null ) { rawCollection.forEach( action ); } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentArrayHolder.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentArrayHolder.java index f26e071974..50a25c2bb4 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentArrayHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentArrayHolder.java @@ -31,7 +31,7 @@ * * @author Gavin King */ -public class PersistentArrayHolder extends AbstractPersistentCollection { +public class PersistentArrayHolder extends AbstractPersistentCollection { private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, PersistentArrayHolder.class.getName() diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentBag.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentBag.java index 458e4be194..76f2c35f5c 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentBag.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentBag.java @@ -126,7 +126,7 @@ public void injectLoadedState(PluralAttributeMapping attributeMapping, List l assert bag == null; final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor(); - final CollectionSemantics collectionSemantics = collectionDescriptor.getCollectionSemantics(); + final CollectionSemantics collectionSemantics = collectionDescriptor.getCollectionSemantics(); final int elementCount = loadingState == null ? 0 : loadingState.size(); diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardArraySemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardArraySemantics.java index 5a5226150d..cbce05551d 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardArraySemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardArraySemantics.java @@ -31,11 +31,11 @@ * * @author Steve Ebersole */ -public class StandardArraySemantics implements CollectionSemantics { +public class StandardArraySemantics implements CollectionSemantics { /** * Singleton access */ - public static final StandardArraySemantics INSTANCE = new StandardArraySemantics(); + public static final StandardArraySemantics INSTANCE = new StandardArraySemantics<>(); private StandardArraySemantics() { } @@ -51,7 +51,7 @@ public Class getCollectionJavaType() { } @Override - public Object[] instantiateRaw( + public E[] instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor) { // return (Object[]) Array.newInstance( @@ -63,34 +63,33 @@ public Object[] instantiateRaw( @Override - public PersistentCollection instantiateWrapper( + public PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentArrayHolder( session, collectionDescriptor ); + return new PersistentArrayHolder<>( session, collectionDescriptor ); } @Override - public PersistentCollection wrap( - Object rawCollection, + public PersistentCollection wrap( + E[] rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentArrayHolder( session, rawCollection ); + return new PersistentArrayHolder<>( session, rawCollection ); } @Override - public Iterator getElementIterator(Object[] rawCollection) { + public Iterator getElementIterator(E[] rawCollection) { return Arrays.stream( rawCollection ).iterator(); } @Override - @SuppressWarnings("unchecked") - public void visitElements(Object[] array, Consumer action) { + public void visitElements(E[] array, Consumer action) { if ( array == null ) { return; } - for ( Object element : array ) { + for ( E element : array ) { action.accept( element ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardBagSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardBagSemantics.java index aeba48da18..e3a785e9b4 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardBagSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardBagSemantics.java @@ -18,11 +18,11 @@ * * @author Steve Ebersole */ -public class StandardBagSemantics extends AbstractBagSemantics> { +public class StandardBagSemantics extends AbstractBagSemantics { /** * Singleton access */ - public static final StandardBagSemantics INSTANCE = new StandardBagSemantics(); + public static final StandardBagSemantics INSTANCE = new StandardBagSemantics<>(); private StandardBagSemantics() { } @@ -33,19 +33,19 @@ public CollectionClassification getCollectionClassification() { } @Override - public PersistentCollection instantiateWrapper( + public PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentBag( session ); + return new PersistentBag<>( session ); } @Override - public PersistentCollection wrap( - Object rawCollection, + public PersistentCollection wrap( + Collection rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentBag( session, (Collection) rawCollection ); + return new PersistentBag<>( session, rawCollection ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardCollectionSemanticsResolver.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardCollectionSemanticsResolver.java index 16635d82f8..a5de6c2450 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardCollectionSemanticsResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardCollectionSemanticsResolver.java @@ -7,7 +7,6 @@ package org.hibernate.collection.internal; import org.hibernate.MappingException; -import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.collection.spi.CollectionSemantics; import org.hibernate.collection.spi.CollectionSemanticsResolver; import org.hibernate.mapping.Array; diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardIdentifierBagSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardIdentifierBagSemantics.java index 1b403ca7a4..2bf7106bf2 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardIdentifierBagSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardIdentifierBagSemantics.java @@ -18,11 +18,11 @@ * * @author Steve Ebersole */ -public class StandardIdentifierBagSemantics extends AbstractBagSemantics> { +public class StandardIdentifierBagSemantics extends AbstractBagSemantics { /** * Singleton access */ - public static final StandardIdentifierBagSemantics INSTANCE = new StandardIdentifierBagSemantics(); + public static final StandardIdentifierBagSemantics INSTANCE = new StandardIdentifierBagSemantics<>(); private StandardIdentifierBagSemantics() { } @@ -33,18 +33,18 @@ public CollectionClassification getCollectionClassification() { } @Override - public PersistentCollection instantiateWrapper( + public PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentIdentifierBag( session ); + return new PersistentIdentifierBag<>( session ); } @Override - public PersistentCollection wrap( - Object rawCollection, + public PersistentCollection wrap( + Collection rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentIdentifierBag( session, (Collection) rawCollection ); + return new PersistentIdentifierBag<>( session, rawCollection ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardListSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardListSemantics.java index 75838cd75f..3e0cb1b573 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardListSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardListSemantics.java @@ -32,11 +32,11 @@ * * @author Steve Ebersole */ -public class StandardListSemantics implements CollectionSemantics { +public class StandardListSemantics implements CollectionSemantics, E> { /** * Singleton access */ - public static final StandardListSemantics INSTANCE = new StandardListSemantics(); + public static final StandardListSemantics INSTANCE = new StandardListSemantics<>(); private StandardListSemantics() { } @@ -52,20 +52,19 @@ public Class getCollectionJavaType() { } @Override - public List instantiateRaw( + public List instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor) { return CollectionHelper.arrayList( anticipatedSize ); } @Override - public Iterator getElementIterator(List rawCollection) { + public Iterator getElementIterator(List rawCollection) { return rawCollection.iterator(); } @Override - @SuppressWarnings("unchecked") - public void visitElements(List rawCollection, Consumer action) { + public void visitElements(List rawCollection, Consumer action) { rawCollection.forEach( action ); } @@ -142,18 +141,18 @@ public CollectionInitializerProducer createInitializerProducer( } @Override - public PersistentCollection instantiateWrapper( + public PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentList( session ); + return new PersistentList<>( session ); } @Override - public PersistentCollection wrap( - Object rawCollection, + public PersistentCollection wrap( + List rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentList( session, (List) rawCollection ); + return new PersistentList<>( session, rawCollection ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardMapSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardMapSemantics.java index 86b3436241..fb845e58f7 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardMapSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardMapSemantics.java @@ -19,11 +19,11 @@ * * @author Steve Ebersole */ -public class StandardMapSemantics extends AbstractMapSemantics> { +public class StandardMapSemantics extends AbstractMapSemantics,K,V> { /** * Singleton access */ - public static final StandardMapSemantics INSTANCE = new StandardMapSemantics(); + public static final StandardMapSemantics INSTANCE = new StandardMapSemantics<>(); private StandardMapSemantics() { } @@ -34,25 +34,25 @@ public CollectionClassification getCollectionClassification() { } @Override - public Map instantiateRaw( + public Map instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor) { return CollectionHelper.mapOfSize( anticipatedSize ); } @Override - public PersistentCollection instantiateWrapper( + public PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentMap( session ); + return new PersistentMap<>( session ); } @Override - public PersistentCollection wrap( - Object rawCollection, + public PersistentCollection wrap( + Map rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentMap( session, (Map) rawCollection ); + return new PersistentMap<>( session, rawCollection ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardOrderedMapSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardOrderedMapSemantics.java index 77211fef5d..a8ec28d553 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardOrderedMapSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardOrderedMapSemantics.java @@ -19,11 +19,11 @@ /** * @author Steve Ebersole */ -public class StandardOrderedMapSemantics extends AbstractMapSemantics> { +public class StandardOrderedMapSemantics extends AbstractMapSemantics,K,V> { /** * Singleton access */ - public static final StandardOrderedMapSemantics INSTANCE = new StandardOrderedMapSemantics(); + public static final StandardOrderedMapSemantics INSTANCE = new StandardOrderedMapSemantics<>(); private StandardOrderedMapSemantics() { } @@ -34,30 +34,30 @@ public CollectionClassification getCollectionClassification() { } @Override - public LinkedHashMap instantiateRaw( + public LinkedHashMap instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor) { return anticipatedSize < 1 ? CollectionHelper.linkedMap() : CollectionHelper.linkedMapOfSize( anticipatedSize ); } @Override - public PersistentCollection instantiateWrapper( + public PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentMap( session ); + return new PersistentMap<>( session ); } @Override - public PersistentCollection wrap( - Object rawCollection, + public PersistentCollection wrap( + LinkedHashMap rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentMap( session, (Map) rawCollection ); + return new PersistentMap<>( session, rawCollection ); } @Override - public Iterator getElementIterator(LinkedHashMap rawCollection) { + public Iterator getElementIterator(LinkedHashMap rawCollection) { return rawCollection.values().iterator(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardOrderedSetSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardOrderedSetSemantics.java index 5543410fee..412254c400 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardOrderedSetSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardOrderedSetSemantics.java @@ -6,24 +6,23 @@ */ 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.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.CollectionClassification; import org.hibernate.persister.collection.CollectionPersister; +import java.util.Iterator; +import java.util.LinkedHashSet; + /** * @author Steve Ebersole */ -public class StandardOrderedSetSemantics extends AbstractSetSemantics> { +public class StandardOrderedSetSemantics extends AbstractSetSemantics,E> { /** * Singleton access */ - public static final StandardOrderedSetSemantics INSTANCE = new StandardOrderedSetSemantics(); + public static final StandardOrderedSetSemantics INSTANCE = new StandardOrderedSetSemantics<>(); private StandardOrderedSetSemantics() { } @@ -34,30 +33,30 @@ public CollectionClassification getCollectionClassification() { } @Override - public LinkedHashSet instantiateRaw( + public LinkedHashSet instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor) { return anticipatedSize < 1 ? CollectionHelper.linkedSet() : CollectionHelper.linkedSetOfSize( anticipatedSize ); } @Override - public PersistentCollection instantiateWrapper( + public PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentSet( session ); + return new PersistentSet<>( session ); } @Override - public PersistentCollection wrap( - Object rawCollection, + public PersistentCollection wrap( + LinkedHashSet rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentSet( session, (Set) rawCollection ); + return new PersistentSet<>( session, rawCollection ); } @Override - public Iterator getElementIterator(LinkedHashSet rawCollection) { + public Iterator getElementIterator(LinkedHashSet rawCollection) { return rawCollection.iterator(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSetSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSetSemantics.java index 5a907a2c54..171e1c42a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSetSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSetSemantics.java @@ -17,11 +17,11 @@ /** * @author Steve Ebersole */ -public class StandardSetSemantics extends AbstractSetSemantics> { +public class StandardSetSemantics extends AbstractSetSemantics,E> { /** * Singleton access */ - public static final StandardSetSemantics INSTANCE = new StandardSetSemantics(); + public static final StandardSetSemantics INSTANCE = new StandardSetSemantics<>(); private StandardSetSemantics() { } @@ -32,26 +32,26 @@ public CollectionClassification getCollectionClassification() { } @Override - public Set instantiateRaw( + public Set instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor) { return anticipatedSize < 1 ? new HashSet<>() : CollectionHelper.setOfSize( anticipatedSize ); } @Override - public PersistentSet instantiateWrapper( + public PersistentSet instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentSet( session ); + return new PersistentSet<>( session ); } @Override - public PersistentSet wrap( - Object rawCollection, + public PersistentSet wrap( + Set rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentSet( session, (Set) rawCollection ); + return new PersistentSet<>( session, rawCollection ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedMapSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedMapSemantics.java index e12383f85e..3664d7afb4 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedMapSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedMapSemantics.java @@ -6,6 +6,7 @@ */ package org.hibernate.collection.internal; +import java.util.Comparator; import java.util.SortedMap; import java.util.TreeMap; @@ -17,11 +18,11 @@ /** * @author Steve Ebersole */ -public class StandardSortedMapSemantics extends AbstractMapSemantics> { +public class StandardSortedMapSemantics extends AbstractMapSemantics,K,V> { /** * Singleton access */ - public static final StandardSortedMapSemantics INSTANCE = new StandardSortedMapSemantics(); + public static final StandardSortedMapSemantics INSTANCE = new StandardSortedMapSemantics<>(); private StandardSortedMapSemantics() { } @@ -32,31 +33,30 @@ public CollectionClassification getCollectionClassification() { } @Override - public Class> getCollectionJavaType() { - //noinspection unchecked - return (Class) SortedMap.class; + public Class getCollectionJavaType() { + return SortedMap.class; } @Override - public TreeMap instantiateRaw( + public TreeMap instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor) { - return new TreeMap( collectionDescriptor.getSortingComparator() ); + return new TreeMap( (Comparator) collectionDescriptor.getSortingComparator() ); } @Override - public PersistentCollection instantiateWrapper( + public PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentSortedMap( session ); + return new PersistentSortedMap<>( session ); } @Override - public PersistentCollection wrap( - Object rawCollection, + public PersistentCollection wrap( + SortedMap rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentSortedMap( session, (SortedMap) rawCollection ); + return new PersistentSortedMap<>( session, rawCollection ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedSetSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedSetSemantics.java index 33f8d4c56d..4d4be32b19 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedSetSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedSetSemantics.java @@ -6,6 +6,7 @@ */ package org.hibernate.collection.internal; +import java.util.Comparator; import java.util.Iterator; import java.util.SortedSet; import java.util.TreeSet; @@ -18,11 +19,11 @@ /** * @author Steve Ebersole */ -public class StandardSortedSetSemantics extends AbstractSetSemantics> { +public class StandardSortedSetSemantics extends AbstractSetSemantics,E> { /** * Singleton access */ - public static final StandardSortedSetSemantics INSTANCE = new StandardSortedSetSemantics(); + public static final StandardSortedSetSemantics INSTANCE = new StandardSortedSetSemantics<>(); private StandardSortedSetSemantics() { } @@ -33,36 +34,35 @@ public CollectionClassification getCollectionClassification() { } @Override - public Class> getCollectionJavaType() { - //noinspection unchecked - return (Class) SortedSet.class; + public Class getCollectionJavaType() { + return SortedSet.class; } @Override - public SortedSet instantiateRaw( + public SortedSet instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor) { - return new TreeSet( collectionDescriptor.getSortingComparator() ); + return new TreeSet( (Comparator) collectionDescriptor.getSortingComparator() ); } @Override - public PersistentCollection instantiateWrapper( + public PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentSortedSet( session ); + return new PersistentSortedSet<>( session ); } @Override - public PersistentCollection wrap( - Object rawCollection, + public PersistentCollection wrap( + SortedSet rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session) { - return new PersistentSortedSet( session, (SortedSet) rawCollection ); + return new PersistentSortedSet<>( session, rawCollection ); } @Override - public Iterator getElementIterator(SortedSet rawCollection) { + public Iterator getElementIterator(SortedSet rawCollection) { return rawCollection.iterator(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/BagSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/BagSemantics.java index 6f240e9533..86110f14b8 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/BagSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/BagSemantics.java @@ -6,9 +6,11 @@ */ package org.hibernate.collection.spi; +import java.util.Collection; + /** * @author Andrea Boriero */ -public interface BagSemantics extends CollectionSemantics { +public interface BagSemantics, E> extends CollectionSemantics { } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/CollectionSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/CollectionSemantics.java index f808146399..95512479b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/CollectionSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/CollectionSemantics.java @@ -30,31 +30,31 @@ * @author Gavin King */ @Incubating -public interface CollectionSemantics { +public interface CollectionSemantics { /** * Get the classification of collections described by this semantic */ CollectionClassification getCollectionClassification(); - Class getCollectionJavaType(); + Class getCollectionJavaType(); - C instantiateRaw( + CE instantiateRaw( int anticipatedSize, CollectionPersister collectionDescriptor); - PersistentCollection instantiateWrapper( + PersistentCollection instantiateWrapper( Object key, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session); - PersistentCollection wrap( - Object rawCollection, + PersistentCollection wrap( + CE rawCollection, CollectionPersister collectionDescriptor, SharedSessionContractImplementor session); - Iterator getElementIterator(C rawCollection); + Iterator getElementIterator(CE rawCollection); - void visitElements(C rawCollection, Consumer action); + void visitElements(CE rawCollection, Consumer action); /** * todo (6.0) : clean this contract up! diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/MapSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/MapSemantics.java index 43b8ece7a7..b8c0491639 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/MapSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/MapSemantics.java @@ -7,6 +7,7 @@ package org.hibernate.collection.spi; import java.util.Iterator; +import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -15,10 +16,10 @@ * * @author Steve Ebersole */ -public interface MapSemantics extends CollectionSemantics { - Iterator getKeyIterator(M rawMap); +public interface MapSemantics,K,V> extends CollectionSemantics { + Iterator getKeyIterator(MKV rawMap); - void visitKeys(M rawMap, Consumer action); + void visitKeys(MKV rawMap, Consumer action); - void visitEntries(M rawMap, BiConsumer action); + void visitEntries(MKV rawMap, BiConsumer action); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/CollectionMappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/CollectionMappingType.java index 08775d3001..58d127a6d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/CollectionMappingType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/CollectionMappingType.java @@ -15,5 +15,5 @@ * @author Steve Ebersole */ public interface CollectionMappingType extends MappingType { - CollectionSemantics getCollectionSemantics(); + CollectionSemantics getCollectionSemantics(); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/CollectionJavaTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/CollectionJavaTypeDescriptor.java index 1fc4cded88..ec5210c756 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/CollectionJavaTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/CollectionJavaTypeDescriptor.java @@ -24,15 +24,15 @@ * @author Steve Ebersole */ public class CollectionJavaTypeDescriptor extends AbstractTypeDescriptor { - private final CollectionSemantics semantics; + private final CollectionSemantics semantics; @SuppressWarnings("unchecked") - public CollectionJavaTypeDescriptor(Class type, CollectionSemantics semantics) { + public CollectionJavaTypeDescriptor(Class type, CollectionSemantics semantics) { super( (Class) type ); this.semantics = semantics; } - public CollectionSemantics getSemantics() { + public CollectionSemantics getSemantics() { return semantics; }