Skip to content

Commit

Permalink
HSEARCH-1404 Rename IndexedTypesSets to IndexedTypeSets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Jun 13, 2017
1 parent 3e0ff48 commit afb48fc
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 74 deletions.
Expand Up @@ -49,7 +49,7 @@
import org.hibernate.search.spi.IndexedTypeIdentifier;
import org.hibernate.search.spi.IndexedTypeSet;
import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.spi.impl.IndexedTypesSets;
import org.hibernate.search.spi.impl.IndexedTypeSets;
import org.hibernate.search.util.StringHelper;
import org.hibernate.search.util.configuration.impl.ConfigurationParseHelper;
import org.hibernate.search.util.logging.impl.LoggerFactory;
Expand Down Expand Up @@ -90,11 +90,11 @@ public class ElasticsearchIndexManager implements IndexManager, IndexNameNormali
private Similarity similarity;

private ExtendedSearchIntegrator searchIntegrator;
private IndexedTypeSet containedEntityTypes = IndexedTypesSets.empty();
private IndexedTypeSet containedEntityTypes = IndexedTypeSets.empty();

private boolean indexInitialized = false;
private boolean indexCreatedByHibernateSearch = false;
private IndexedTypeSet initializedContainedEntityTypes = IndexedTypesSets.empty();
private IndexedTypeSet initializedContainedEntityTypes = IndexedTypeSets.empty();

private ServiceManager serviceManager;

Expand Down Expand Up @@ -252,17 +252,17 @@ private void initializeIndex() {
*/
indexCreatedByHibernateSearch = initializeIndex( containedEntityTypes );
indexInitialized = true;
initializedContainedEntityTypes = IndexedTypesSets.composite( initializedContainedEntityTypes, containedEntityTypes );
initializedContainedEntityTypes = IndexedTypeSets.composite( initializedContainedEntityTypes, containedEntityTypes );
}
else {
IndexedTypeSet notYetInitializedContainedEntityTypes = IndexedTypesSets.subtraction( containedEntityTypes, initializedContainedEntityTypes );
IndexedTypeSet notYetInitializedContainedEntityTypes = IndexedTypeSets.subtraction( containedEntityTypes, initializedContainedEntityTypes );

if ( notYetInitializedContainedEntityTypes.isEmpty() ) {
return; // Nothing to do
}

reinitializeIndex( notYetInitializedContainedEntityTypes );
initializedContainedEntityTypes = IndexedTypesSets.composite( initializedContainedEntityTypes, notYetInitializedContainedEntityTypes );
initializedContainedEntityTypes = IndexedTypeSets.composite( initializedContainedEntityTypes, notYetInitializedContainedEntityTypes );
}
}

Expand Down Expand Up @@ -376,7 +376,7 @@ private IndexMetadata createIndexMetadata(IndexedTypeSet entityTypes) {

@Override
public void addContainedEntity(IndexedTypeIdentifier entity) {
containedEntityTypes = IndexedTypesSets.composite( containedEntityTypes, entity );
containedEntityTypes = IndexedTypeSets.composite( containedEntityTypes, entity );
}

// Getters
Expand Down
Expand Up @@ -16,7 +16,7 @@
import org.hibernate.search.query.engine.spi.QueryDescriptor;
import org.hibernate.search.spi.BuildContext;
import org.hibernate.search.spi.IndexedTypeSet;
import org.hibernate.search.spi.impl.IndexedTypesSets;
import org.hibernate.search.spi.impl.IndexedTypeSets;

import com.google.gson.JsonObject;

Expand Down Expand Up @@ -57,7 +57,7 @@ private IndexedTypeSet getQueriedEntityTypes(IndexedTypeSet indexedTargetedEntit
return extendedIntegrator.getIndexBindings().keySet();
}
else {
return IndexedTypesSets.fromIdentifiers( indexedTargetedEntities );
return IndexedTypeSets.fromIdentifiers( indexedTargetedEntities );
}
}

Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.hibernate.search.query.engine.spi.HSQuery;
import org.hibernate.search.spi.DefaultInstanceInitializer;
import org.hibernate.search.spi.IndexedTypeIdentifier;
import org.hibernate.search.spi.impl.IndexedTypesSets;
import org.hibernate.search.spi.impl.IndexedTypeSets;
import org.hibernate.search.spi.impl.PojoIndexedTypeIdentifier;
import org.hibernate.search.testsupport.TestForIssue;
import org.hibernate.search.testsupport.junit.SearchFactoryHolder;
Expand Down Expand Up @@ -83,7 +83,7 @@ private void increaseRefreshTime(Class<?>... indexes) throws IOException {
}

private void flush(Class<?> clazz) {
sfHolder.getBatchBackend().flush( IndexedTypesSets.fromClass( clazz ) );
sfHolder.getBatchBackend().flush( IndexedTypeSets.fromClass( clazz ) );
}

private void indexAsStream(Serializable id, Object entity) throws InterruptedException {
Expand Down
Expand Up @@ -73,7 +73,7 @@
import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.spi.impl.ConcurrentIndexedTypeMap;
import org.hibernate.search.spi.impl.ExtendedSearchIntegratorWithShareableState;
import org.hibernate.search.spi.impl.IndexedTypesSets;
import org.hibernate.search.spi.impl.IndexedTypeSets;
import org.hibernate.search.spi.impl.PojoIndexedTypeIdentifier;
import org.hibernate.search.spi.impl.TypeHierarchy;
import org.hibernate.search.spi.impl.SearchFactoryState;
Expand Down Expand Up @@ -292,7 +292,7 @@ public void close() {

@Override
public HSQuery createHSQuery(Query luceneQuery, Class<?>... entityTypes) {
IndexedTypeSet newtypes = IndexedTypesSets.fromClasses( entityTypes );
IndexedTypeSet newtypes = IndexedTypeSets.fromClasses( entityTypes );
QueryDescriptor descriptor = createQueryDescriptor( luceneQuery, newtypes );
return descriptor.createHSQuery( this ).targetedEntities( newtypes );
}
Expand All @@ -302,7 +302,7 @@ public HSQuery createHSQuery(Query luceneQuery, CustomTypeMetadata... types) {
List<CustomTypeMetadata> typeList = Arrays.asList( types );
IndexedTypeSet entityTypes = typeList.stream()
.map( CustomTypeMetadata::getEntityType )
.collect( IndexedTypesSets.streamCollector() );
.collect( IndexedTypeSets.streamCollector() );
QueryDescriptor descriptor = createQueryDescriptor( luceneQuery, entityTypes );
return descriptor.createHSQuery( this ).targetedTypes( typeList );
}
Expand Down Expand Up @@ -495,7 +495,7 @@ public int getFilterCacheBitResultsSize() {
@Override
@Deprecated
public IndexedTypeSet getConfiguredTypesPolymorphic(Class<?>[] types) {
return getConfiguredTypesPolymorphic( IndexedTypesSets.fromClasses( types ) );
return getConfiguredTypesPolymorphic( IndexedTypeSets.fromClasses( types ) );
}

@Override
Expand All @@ -506,7 +506,7 @@ public IndexedTypeSet getConfiguredTypesPolymorphic(IndexedTypeSet types) {
@Override
@Deprecated
public IndexedTypeSet getIndexedTypesPolymorphic(Class<?>[] types) {
return getIndexedTypesPolymorphic( IndexedTypesSets.fromClasses( types ) );
return getIndexedTypesPolymorphic( IndexedTypeSets.fromClasses( types ) );
}

@Override
Expand Down
Expand Up @@ -27,7 +27,7 @@
import org.hibernate.search.spi.IndexedTypeIdentifier;
import org.hibernate.search.spi.IndexedTypeSet;
import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.spi.impl.IndexedTypesSets;
import org.hibernate.search.spi.impl.IndexedTypeSets;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.store.optimization.OptimizerStrategy;
import org.hibernate.search.util.logging.impl.Log;
Expand All @@ -51,7 +51,7 @@ public class DirectoryBasedIndexManager implements IndexManager {
private WorkspaceHolder workspaceHolder;
private OptimizerStrategy optimizer;
private LuceneIndexingParameters indexingParameters;
private IndexedTypeSet containedEntityTypes = IndexedTypesSets.empty();
private IndexedTypeSet containedEntityTypes = IndexedTypeSets.empty();
private LuceneWorkSerializer serializer;
private ExtendedSearchIntegrator boundSearchIntegrator = null;
private DirectoryBasedReaderProvider readers = null;
Expand Down Expand Up @@ -138,7 +138,7 @@ public void setSearchFactory(ExtendedSearchIntegrator boundSearchIntegrator) {
@Override
public void addContainedEntity(IndexedTypeIdentifier entity) {
final IndexedTypeSet oldSet = containedEntityTypes;
final IndexedTypeSet newSet = IndexedTypesSets.composite( oldSet, entity );
final IndexedTypeSet newSet = IndexedTypeSets.composite( oldSet, entity );
if ( ! oldSet.equals( newSet ) ) {
this.containedEntityTypes = newSet;
triggerWorkspaceReconfiguration();
Expand Down
Expand Up @@ -49,7 +49,7 @@
import org.hibernate.search.spi.IndexedTypeSet;
import org.hibernate.search.spi.SearchIntegrator;
import org.hibernate.search.spi.IndexedTypeMap;
import org.hibernate.search.spi.impl.IndexedTypesSets;
import org.hibernate.search.spi.impl.IndexedTypeSets;
import org.hibernate.search.util.StringHelper;
import org.hibernate.search.util.impl.ClassLoaderHelper;
import org.hibernate.search.util.impl.CollectionHelper;
Expand Down Expand Up @@ -126,7 +126,7 @@ public HSQuery tenantIdentifier(String tenantId) {

@Override
public final HSQuery targetedEntities(IndexedTypeSet types) {
setTargetedEntities( types == null ? IndexedTypesSets.empty() : types );
setTargetedEntities( types == null ? IndexedTypeSets.empty() : types );
this.customTypeMetadata = Collections.emptyList();
return this;
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public final HSQuery targetedTypes(List<CustomTypeMetadata> types) {

IndexedTypeSet typesSet = types.stream()
.map( CustomTypeMetadata::getEntityType )
.collect( IndexedTypesSets.streamCollector() );
.collect( IndexedTypeSets.streamCollector() );
setTargetedEntities( typesSet );
this.customTypeMetadata = new ArrayList<>( types );

Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.hibernate.search.engine.metadata.impl.SortableFieldMetadata;
import org.hibernate.search.spi.IndexedTypeIdentifier;
import org.hibernate.search.spi.IndexedTypeSet;
import org.hibernate.search.spi.impl.IndexedTypesSets;
import org.hibernate.search.spi.impl.IndexedTypeSets;
import org.hibernate.search.spi.impl.PojoIndexedTypeIdentifier;

/**
Expand Down Expand Up @@ -92,7 +92,7 @@ public List<String> getUncoveredSorts(IndexedTypeIdentifier entityType, Sort sor
}

public IndexedTypeSet getEntityTypes() {
return sortableFieldsByType.keySet().stream().collect( IndexedTypesSets.streamCollector() );
return sortableFieldsByType.keySet().stream().collect( IndexedTypeSets.streamCollector() );
}

public String getIndexName() {
Expand Down
Expand Up @@ -41,7 +41,7 @@ public V get(Class<?> legacyPojo) {

@Override
public IndexedTypeSet keySet() {
return IndexedTypesSets.fromIdentifiers( map.keySet() );
return IndexedTypeSets.fromIdentifiers( map.keySet() );
}

@Override
Expand Down
Expand Up @@ -21,9 +21,9 @@
import org.hibernate.search.spi.IndexedTypeIdentifier;
import org.hibernate.search.spi.IndexedTypeSet;

public final class IndexedTypesSets {
public final class IndexedTypeSets {

private IndexedTypesSets() {
private IndexedTypeSets() {
//Utility class: not to be constructed
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public BinaryOperator<HashSet<IndexedTypeIdentifier>> combiner() {

@Override
public Function<HashSet<IndexedTypeIdentifier>, IndexedTypeSet> finisher() {
return IndexedTypesSets::fromSafeHashSet;
return IndexedTypeSets::fromSafeHashSet;
}

@Override
Expand Down
Expand Up @@ -53,7 +53,7 @@ private void addClass(Class<?> superclass, Class<?> indexedClass) {

public IndexedTypeSet getConfiguredClasses(IndexedTypeSet types) {
if ( types == null ) {
return IndexedTypesSets.empty();
return IndexedTypeSets.empty();
}
Set<IndexedTypeIdentifier> indexedClasses = new HashSet<IndexedTypeIdentifier>();
for ( IndexedTypeIdentifier type : types ) {
Expand All @@ -68,6 +68,6 @@ public IndexedTypeSet getConfiguredClasses(IndexedTypeSet types) {
if ( log.isTraceEnabled() ) {
log.tracef( "Targeted indexed classes for %s: %s", types, indexedClasses );
}
return IndexedTypesSets.fromIdentifiers( indexedClasses );
return IndexedTypeSets.fromIdentifiers( indexedClasses );
}
}
Expand Up @@ -12,7 +12,7 @@

import org.hibernate.search.spi.IndexedTypeIdentifier;
import org.hibernate.search.spi.IndexedTypeSet;
import org.hibernate.search.spi.impl.IndexedTypesSets;
import org.hibernate.search.spi.impl.IndexedTypeSets;
import org.hibernate.search.spi.impl.PojoIndexedTypeIdentifier;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -24,96 +24,96 @@ public class BasicTypeCollectionsTest {

@Test
public void emptyStream() {
assertIsEmpty( Collections.<IndexedTypeIdentifier>emptyList().stream().collect( IndexedTypesSets.streamCollector() ) );
assertIsEmpty( Collections.<IndexedTypeIdentifier>emptyList().stream().collect( IndexedTypeSets.streamCollector() ) );
}

@Test
public void nullVararg() {
assertIsEmpty( IndexedTypesSets.fromClasses( null ) );
assertIsEmpty( IndexedTypeSets.fromClasses( null ) );
}

@Test
public void emptyArray() {
assertIsEmpty( IndexedTypesSets.fromIdentifiers( new IndexedTypeIdentifier[0] ) );
assertIsEmpty( IndexedTypeSets.fromIdentifiers( new IndexedTypeIdentifier[0] ) );
}

@Test
public void emptyIterable() {
assertIsEmpty( IndexedTypesSets.fromIdentifiers( Collections.<IndexedTypeIdentifier>emptyList() ) );
assertIsEmpty( IndexedTypeSets.fromIdentifiers( Collections.<IndexedTypeIdentifier>emptyList() ) );
}

@Test
public void singleElementClass() {
assertIsSingletonSet( IndexedTypesSets.fromClass( BasicTypeCollectionsTest.class ), BasicTypeCollectionsTest.class, true );
assertIsSingletonSet( IndexedTypeSets.fromClass( BasicTypeCollectionsTest.class ), BasicTypeCollectionsTest.class, true );
}

@Test
public void singleElementIterable() {
assertIsSingletonSet( IndexedTypesSets.fromIdentifiers( TYPE_A.asTypeSet() ), BasicTypeCollectionsTest.class, true );
assertIsSingletonSet( IndexedTypeSets.fromIdentifiers( TYPE_A.asTypeSet() ), BasicTypeCollectionsTest.class, true );
}

@Test
public void singleElementStream() {
assertIsSingletonSet(
Collections.<IndexedTypeIdentifier>singleton( TYPE_A ).stream().collect( IndexedTypesSets.streamCollector() ),
Collections.<IndexedTypeIdentifier>singleton( TYPE_A ).stream().collect( IndexedTypeSets.streamCollector() ),
BasicTypeCollectionsTest.class, true );
}

@Test
public void singleElementArray() {
assertIsSingletonSet(
IndexedTypesSets.fromIdentifiers( new IndexedTypeIdentifier[] { TYPE_A } ),
IndexedTypeSets.fromIdentifiers( new IndexedTypeIdentifier[] { TYPE_A } ),
BasicTypeCollectionsTest.class, true );
}

@Test
public void compositeEmpty() {
assertIsEmpty( IndexedTypesSets.composite( IndexedTypesSets.empty(), IndexedTypesSets.empty() ) );
assertIsEmpty( IndexedTypeSets.composite( IndexedTypeSets.empty(), IndexedTypeSets.empty() ) );
}

@Test
public void compositeSingle() {
assertIsSingletonSet( IndexedTypesSets.composite( TYPE_A.asTypeSet(), TYPE_A ), BasicTypeCollectionsTest.class, true );
assertIsSingletonSet( IndexedTypeSets.composite( TYPE_A.asTypeSet(), TYPE_A ), BasicTypeCollectionsTest.class, true );
}

@Test
public void compositeSingleAndEmpty() {
assertIsSingletonSet( IndexedTypesSets.composite( TYPE_A.asTypeSet(), IndexedTypesSets.empty() ), BasicTypeCollectionsTest.class, true );
assertIsSingletonSet( IndexedTypeSets.composite( TYPE_A.asTypeSet(), IndexedTypeSets.empty() ), BasicTypeCollectionsTest.class, true );
}

@Test
public void subtractionEmpty() {
assertIsEmpty( IndexedTypesSets.subtraction( IndexedTypesSets.empty(), IndexedTypesSets.empty() ) );
assertIsEmpty( IndexedTypeSets.subtraction( IndexedTypeSets.empty(), IndexedTypeSets.empty() ) );
}

@Test
public void subtractionOfSingletons() {
assertIsEmpty( IndexedTypesSets.subtraction( TYPE_A.asTypeSet(), TYPE_A.asTypeSet() ) );
assertIsEmpty( IndexedTypeSets.subtraction( TYPE_A.asTypeSet(), TYPE_A.asTypeSet() ) );
}

@Test
public void subtractionOfSingletonFromEmpty() {
assertIsEmpty( IndexedTypesSets.subtraction( IndexedTypesSets.empty(), TYPE_A.asTypeSet() ) );
assertIsEmpty( IndexedTypeSets.subtraction( IndexedTypeSets.empty(), TYPE_A.asTypeSet() ) );
}

@Test
public void subtractionOfEmptyFromSingleton() {
assertIsSingletonSet( IndexedTypesSets.subtraction( TYPE_A.asTypeSet(), IndexedTypesSets.empty() ), BasicTypeCollectionsTest.class, true );
assertIsSingletonSet( IndexedTypeSets.subtraction( TYPE_A.asTypeSet(), IndexedTypeSets.empty() ), BasicTypeCollectionsTest.class, true );
}

@Test
public void buildCoupleSet() {
assertIsDoubleSet( IndexedTypesSets.composite( TYPE_A.asTypeSet(), TYPE_B ) );
assertIsDoubleSet( IndexedTypeSets.composite( TYPE_A.asTypeSet(), TYPE_B ) );
}

@Test
public void subtractionOfOneFromCouple() {
assertIsSingletonSet( IndexedTypesSets.subtraction( IndexedTypesSets.composite( TYPE_A.asTypeSet(), TYPE_B ), TYPE_B.asTypeSet() ), TYPE_A.getPojoType(), true );
assertIsSingletonSet( IndexedTypesSets.subtraction( IndexedTypesSets.composite( TYPE_A.asTypeSet(), TYPE_B ), TYPE_A.asTypeSet() ), TYPE_B.getPojoType(), true );
assertIsSingletonSet( IndexedTypeSets.subtraction( IndexedTypeSets.composite( TYPE_A.asTypeSet(), TYPE_B ), TYPE_B.asTypeSet() ), TYPE_A.getPojoType(), true );
assertIsSingletonSet( IndexedTypeSets.subtraction( IndexedTypeSets.composite( TYPE_A.asTypeSet(), TYPE_B ), TYPE_A.asTypeSet() ), TYPE_B.getPojoType(), true );
}

private void assertIsDoubleSet(IndexedTypeSet typeSet) {
Assert.assertFalse( "Verify it's not a singleton", typeSet == IndexedTypesSets.empty() );
Assert.assertFalse( "Verify it's not a singleton", typeSet == IndexedTypeSets.empty() );
Assert.assertFalse( typeSet.isEmpty() );
Assert.assertEquals( 2, typeSet.size() );
Iterator<IndexedTypeIdentifier> iterator = typeSet.iterator();
Expand All @@ -129,15 +129,15 @@ private void assertIsDoubleSet(IndexedTypeSet typeSet) {
}

private void assertIsEmpty(IndexedTypeSet typeSet) {
Assert.assertTrue( "Verify the singleton optimisation applies", typeSet == IndexedTypesSets.empty() );
Assert.assertTrue( "Verify the singleton optimisation applies", typeSet == IndexedTypeSets.empty() );
Assert.assertTrue( typeSet.isEmpty() );
Assert.assertEquals( 0, typeSet.size() );
typeSet.iterator().forEachRemaining( l -> Assert.fail( "should never happen" ) );
Assert.assertEquals( 0, typeSet.toPojosSet().size() );
}

private void assertIsSingletonSet(IndexedTypeSet typeSet, Class<?> someType, boolean recursive) {
Assert.assertFalse( "Verify it's not a singleton", typeSet == IndexedTypesSets.empty() );
Assert.assertFalse( "Verify it's not a singleton", typeSet == IndexedTypeSets.empty() );
Assert.assertFalse( typeSet.isEmpty() );
Assert.assertEquals( 1, typeSet.size() );
Iterator<IndexedTypeIdentifier> iterator = typeSet.iterator();
Expand Down

0 comments on commit afb48fc

Please sign in to comment.