From 5256da2b8b7bad2cd70bfb9339f619b3b0350308 Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Thu, 22 Aug 2019 21:19:03 +0200 Subject: [PATCH] Use lambda or member reference Converts anonymous inner classes to lambda expressions or member references --- ...earchAnalysisConfigurationContextImpl.java | 14 ++-- .../impl/ElasticsearchClientFactoryImpl.java | 15 ++-- .../searchdsl/sort/SortDslIT.java | 15 ++-- .../ElasticsearchExtensionIT.java | 37 ++++------ ...sticsearchSchemaAttributeValidationIT.java | 14 +--- .../ElasticsearchSchemaCreateStrategyIT.java | 14 +--- .../ElasticsearchSchemaCreationIT.java | 14 +--- .../ElasticsearchSchemaMigrationIT.java | 14 +--- .../ElasticsearchSchemaValidationIT.java | 14 +--- .../backend/lucene/LuceneExtensionIT.java | 9 +-- .../definition/PropertyBridgeBaseIT.java | 70 +++++++----------- .../mapping/definition/TypeBridgeBaseIT.java | 74 +++++++------------ .../search/util/common/impl/CloserTest.java | 21 ++---- .../common/impl/SuppressingCloserTest.java | 21 ++---- .../StubSearchProjectionBuilderFactory.java | 14 +--- 15 files changed, 116 insertions(+), 244 deletions(-) diff --git a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/analysis/model/dsl/impl/ElasticsearchAnalysisConfigurationContextImpl.java b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/analysis/model/dsl/impl/ElasticsearchAnalysisConfigurationContextImpl.java index 51885419336..e7560f3ccd5 100644 --- a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/analysis/model/dsl/impl/ElasticsearchAnalysisConfigurationContextImpl.java +++ b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/analysis/model/dsl/impl/ElasticsearchAnalysisConfigurationContextImpl.java @@ -13,7 +13,6 @@ import org.hibernate.search.backend.elasticsearch.analysis.model.dsl.ElasticsearchAnalyzerTypeStep; import org.hibernate.search.backend.elasticsearch.analysis.model.dsl.ElasticsearchAnalyzerTokenizerStep; import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurationContext; -import org.hibernate.search.backend.elasticsearch.analysis.model.dsl.ElasticsearchNormalizerOptionalComponentsStep; import org.hibernate.search.backend.elasticsearch.analysis.model.dsl.ElasticsearchNormalizerTypeStep; import org.hibernate.search.backend.elasticsearch.analysis.model.dsl.ElasticsearchAnalysisComponentParametersStep; import org.hibernate.search.backend.elasticsearch.analysis.model.impl.ElasticsearchAnalysisDefinitionCollector; @@ -49,14 +48,11 @@ public ElasticsearchAnalysisComponentParametersStep type(String type) { @Override public ElasticsearchNormalizerTypeStep normalizer(String name) { - return new ElasticsearchNormalizerTypeStep() { - @Override - public ElasticsearchNormalizerOptionalComponentsStep custom() { - ElasticsearchNormalizerComponentsStep context = - new ElasticsearchNormalizerComponentsStep( name ); - children.add( context ); - return context; - } + return () -> { + ElasticsearchNormalizerComponentsStep context = + new ElasticsearchNormalizerComponentsStep( name ); + children.add( context ); + return context; }; } diff --git a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/client/impl/ElasticsearchClientFactoryImpl.java b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/client/impl/ElasticsearchClientFactoryImpl.java index 069cf4ff781..1dbda029ad7 100644 --- a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/client/impl/ElasticsearchClientFactoryImpl.java +++ b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/client/impl/ElasticsearchClientFactoryImpl.java @@ -40,15 +40,12 @@ */ public class ElasticsearchClientFactoryImpl implements ElasticsearchClientFactory { - public static final BeanReference REFERENCE = new BeanReference() { - @Override - public BeanHolder resolve(BeanResolver beanResolver) { - BeanHolder> httpClientConfigurerHolders = - beanResolver.resolveRole( ElasticsearchHttpClientConfigurer.class ); - ElasticsearchClientFactoryImpl factory = new ElasticsearchClientFactoryImpl( httpClientConfigurerHolders.get() ); - return BeanHolder.of( factory ) - .withDependencyAutoClosing( httpClientConfigurerHolders ); - } + public static final BeanReference REFERENCE = (BeanResolver beanResolver) -> { + BeanHolder> httpClientConfigurerHolders = + beanResolver.resolveRole( ElasticsearchHttpClientConfigurer.class ); + ElasticsearchClientFactoryImpl factory = new ElasticsearchClientFactoryImpl( httpClientConfigurerHolders.get() ); + return BeanHolder.of( factory ) + .withDependencyAutoClosing( httpClientConfigurerHolders ); }; private static final ConfigurationProperty> HOST = diff --git a/documentation/src/test/java/org/hibernate/search/documentation/searchdsl/sort/SortDslIT.java b/documentation/src/test/java/org/hibernate/search/documentation/searchdsl/sort/SortDslIT.java index 70878415a1e..df19107157c 100644 --- a/documentation/src/test/java/org/hibernate/search/documentation/searchdsl/sort/SortDslIT.java +++ b/documentation/src/test/java/org/hibernate/search/documentation/searchdsl/sort/SortDslIT.java @@ -333,16 +333,11 @@ public void elasticsearch() { } private MySearchParameters getSearchParameters() { - return new MySearchParameters() { - @Override - public List getSorts() { - return Arrays.asList( - new MySort( MySortType.GENRE, SortOrder.ASC ), - new MySort( MySortType.TITLE, SortOrder.DESC ), - new MySort( MySortType.PAGE_COUNT, SortOrder.DESC ) - ); - } - }; + return () -> Arrays.asList( + new MySort( MySortType.GENRE, SortOrder.ASC ), + new MySort( MySortType.TITLE, SortOrder.DESC ), + new MySort( MySortType.PAGE_COUNT, SortOrder.DESC ) + ); } private void withinSearchSession(Consumer action) { diff --git a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/ElasticsearchExtensionIT.java b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/ElasticsearchExtensionIT.java index 1d2b31e281f..416bd638272 100644 --- a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/ElasticsearchExtensionIT.java +++ b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/ElasticsearchExtensionIT.java @@ -13,13 +13,19 @@ import java.util.Optional; import java.util.stream.Collectors; +import org.apache.http.nio.client.HttpAsyncClient; +import org.assertj.core.api.Assertions; +import org.assertj.core.api.HamcrestCondition; +import org.elasticsearch.client.Request; +import org.elasticsearch.client.Response; +import org.elasticsearch.client.RestClient; import org.hibernate.search.backend.elasticsearch.ElasticsearchBackend; import org.hibernate.search.backend.elasticsearch.ElasticsearchExtension; import org.hibernate.search.backend.elasticsearch.impl.ElasticsearchIndexNameNormalizer; import org.hibernate.search.backend.elasticsearch.index.ElasticsearchIndexManager; +import org.hibernate.search.backend.elasticsearch.search.dsl.query.ElasticsearchSearchQueryHitTypeStep; import org.hibernate.search.backend.elasticsearch.search.dsl.query.ElasticsearchSearchQueryOptionsStep; import org.hibernate.search.backend.elasticsearch.search.dsl.query.ElasticsearchSearchQueryPredicateStep; -import org.hibernate.search.backend.elasticsearch.search.dsl.query.ElasticsearchSearchQueryHitTypeStep; import org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchQuery; import org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchResult; import org.hibernate.search.engine.backend.Backend; @@ -27,34 +33,25 @@ import org.hibernate.search.engine.backend.document.IndexFieldReference; import org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement; import org.hibernate.search.engine.backend.index.IndexManager; -import org.hibernate.search.engine.search.SearchProjection; -import org.hibernate.search.engine.search.loading.context.spi.LoadingContext; -import org.hibernate.search.engine.search.query.SearchQueryExtension; -import org.hibernate.search.util.impl.integrationtest.common.stub.mapper.StubMappingScope; import org.hibernate.search.engine.backend.work.execution.spi.IndexWorkPlan; import org.hibernate.search.engine.common.spi.SearchIntegration; -import org.hibernate.search.util.impl.integrationtest.common.stub.mapper.StubMappingIndexManager; import org.hibernate.search.engine.search.DocumentReference; import org.hibernate.search.engine.search.SearchPredicate; -import org.hibernate.search.engine.search.query.SearchQuery; +import org.hibernate.search.engine.search.SearchProjection; import org.hibernate.search.engine.search.SearchSort; +import org.hibernate.search.engine.search.loading.context.spi.LoadingContext; +import org.hibernate.search.engine.search.query.SearchQuery; import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper; import org.hibernate.search.util.common.SearchException; +import org.hibernate.search.util.impl.integrationtest.common.stub.mapper.StubMappingIndexManager; +import org.hibernate.search.util.impl.integrationtest.common.stub.mapper.StubMappingScope; import org.hibernate.search.util.impl.test.ExceptionMatcherBuilder; import org.hibernate.search.util.impl.test.SubTest; - +import org.json.JSONException; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - -import org.apache.http.nio.client.HttpAsyncClient; -import org.assertj.core.api.Assertions; -import org.assertj.core.api.HamcrestCondition; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; -import org.json.JSONException; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -164,13 +161,7 @@ public void query() { // Unsupported extension SubTest.expectException( - () -> query.extension( new SearchQueryExtension() { - @Override - public Optional extendOptional(SearchQuery original, - LoadingContext loadingContext) { - return Optional.empty(); - } - } ) + () -> query.extension( (SearchQuery original, LoadingContext loadingContext) -> Optional.empty() ) ) .assertThrown() .isInstanceOf( SearchException.class ); diff --git a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaAttributeValidationIT.java b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaAttributeValidationIT.java index 8fe92ce7b0b..b83d0e32181 100644 --- a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaAttributeValidationIT.java +++ b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaAttributeValidationIT.java @@ -1158,17 +1158,11 @@ private SearchSetupHelper.SetupContext validateSchemaConfig() { ElasticsearchIndexSettings.LIFECYCLE_STRATEGY, IndexLifecycleStrategyName.VALIDATE.getExternalRepresentation() ) - .withBackendProperty( - BACKEND_NAME, + .withBackendProperty( BACKEND_NAME, // Don't contribute any analysis definitions, migration of those is tested in another test class - ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, - new ElasticsearchAnalysisConfigurer() { - @Override - public void configure(ElasticsearchAnalysisConfigurationContext context) { - // No-op - } - } - ); + ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, (ElasticsearchAnalysisConfigurer) (ElasticsearchAnalysisConfigurationContext context) -> { + // No-op + } ); } @Test diff --git a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaCreateStrategyIT.java b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaCreateStrategyIT.java index ac3324bdf6d..f5394b2c03a 100644 --- a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaCreateStrategyIT.java +++ b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaCreateStrategyIT.java @@ -89,17 +89,11 @@ private void setup() { ElasticsearchIndexSettings.LIFECYCLE_STRATEGY, IndexLifecycleStrategyName.CREATE.getExternalRepresentation() ) - .withBackendProperty( - BACKEND_NAME, + .withBackendProperty( BACKEND_NAME, // Don't contribute any analysis definitions, migration of those is tested in another test class - ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, - new ElasticsearchAnalysisConfigurer() { - @Override - public void configure(ElasticsearchAnalysisConfigurationContext context) { - // No-op - } - } - ) + ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, (ElasticsearchAnalysisConfigurer) (ElasticsearchAnalysisConfigurationContext context) -> { + // No-op + } ) .setup(); } diff --git a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaCreationIT.java b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaCreationIT.java index 87778b3c7ed..89298e04d83 100644 --- a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaCreationIT.java +++ b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaCreationIT.java @@ -207,17 +207,11 @@ private void setup(Consumer mappingContributor) { ElasticsearchIndexSettings.LIFECYCLE_STRATEGY, strategy.getExternalRepresentation() ) - .withBackendProperty( - BACKEND_NAME, + .withBackendProperty( BACKEND_NAME, // Don't contribute any analysis definitions, migration of those is tested in another test class - ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, - new ElasticsearchAnalysisConfigurer() { - @Override - public void configure(ElasticsearchAnalysisConfigurationContext context) { - // No-op - } - } - ) + ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, (ElasticsearchAnalysisConfigurer) (ElasticsearchAnalysisConfigurationContext context) -> { + // No-op + } ) .setup(); } diff --git a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaMigrationIT.java b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaMigrationIT.java index d421e9157aa..34d1258044d 100644 --- a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaMigrationIT.java +++ b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaMigrationIT.java @@ -467,17 +467,11 @@ private SearchSetupHelper.SetupContext withManagementStrategyConfiguration() { ElasticsearchIndexSettings.LIFECYCLE_STRATEGY, IndexLifecycleStrategyName.UPDATE.getExternalRepresentation() ) - .withBackendProperty( - BACKEND_NAME, + .withBackendProperty( BACKEND_NAME, // Don't contribute any analysis definitions, migration of those is tested in another test class - ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, - new ElasticsearchAnalysisConfigurer() { - @Override - public void configure(ElasticsearchAnalysisConfigurationContext context) { - // No-op - } - } - ); + ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, (ElasticsearchAnalysisConfigurer) (ElasticsearchAnalysisConfigurationContext context) -> { + // No-op + } ); } private String generateAnalysisSettings() { diff --git a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaValidationIT.java b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaValidationIT.java index 1ea168ec0fd..e23d9dbdf33 100644 --- a/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaValidationIT.java +++ b/integrationtest/backend/elasticsearch/src/test/java/org/hibernate/search/integrationtest/backend/elasticsearch/management/ElasticsearchSchemaValidationIT.java @@ -548,16 +548,10 @@ private SearchSetupHelper.SetupContext validateSchemaConfig() { ElasticsearchIndexSettings.LIFECYCLE_STRATEGY, IndexLifecycleStrategyName.VALIDATE.getExternalRepresentation() ) - .withBackendProperty( - BACKEND_NAME, + .withBackendProperty( BACKEND_NAME, // Don't contribute any analysis definitions, migration of those is tested in another test class - ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, - new ElasticsearchAnalysisConfigurer() { - @Override - public void configure(ElasticsearchAnalysisConfigurationContext context) { - // No-op - } - } - ); + ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, (ElasticsearchAnalysisConfigurer) (ElasticsearchAnalysisConfigurationContext context) -> { + // No-op + } ); } } diff --git a/integrationtest/backend/lucene/src/test/java/org/hibernate/search/integrationtest/backend/lucene/LuceneExtensionIT.java b/integrationtest/backend/lucene/src/test/java/org/hibernate/search/integrationtest/backend/lucene/LuceneExtensionIT.java index b900b58616d..bffa71ffb94 100644 --- a/integrationtest/backend/lucene/src/test/java/org/hibernate/search/integrationtest/backend/lucene/LuceneExtensionIT.java +++ b/integrationtest/backend/lucene/src/test/java/org/hibernate/search/integrationtest/backend/lucene/LuceneExtensionIT.java @@ -50,7 +50,6 @@ import org.hibernate.search.engine.common.spi.SearchIntegration; import org.hibernate.search.engine.search.SearchProjection; import org.hibernate.search.engine.search.loading.context.spi.LoadingContext; -import org.hibernate.search.engine.search.query.SearchQueryExtension; import org.hibernate.search.util.impl.integrationtest.common.stub.mapper.StubMappingIndexManager; import org.hibernate.search.util.impl.integrationtest.common.stub.mapper.StubMappingScope; import org.hibernate.search.backend.lucene.LuceneExtension; @@ -174,13 +173,7 @@ public void query() { // Unsupported extension SubTest.expectException( - () -> query.extension( new SearchQueryExtension() { - @Override - public Optional extendOptional(SearchQuery original, - LoadingContext loadingContext) { - return Optional.empty(); - } - } ) + () -> query.extension( (SearchQuery original, LoadingContext loadingContext) -> Optional.empty() ) ) .assertThrown() .isInstanceOf( SearchException.class ); diff --git a/integrationtest/mapper/pojo/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/mapping/definition/PropertyBridgeBaseIT.java b/integrationtest/mapper/pojo/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/mapping/definition/PropertyBridgeBaseIT.java index 8b344bf5bee..f8278f3ae74 100644 --- a/integrationtest/mapper/pojo/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/mapping/definition/PropertyBridgeBaseIT.java +++ b/integrationtest/mapper/pojo/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/mapping/definition/PropertyBridgeBaseIT.java @@ -100,17 +100,11 @@ public String getStringProperty() { f -> f.asString().analyzer( "myAnalyzer" ) ) .toReference(); - context.setBridge( - new PropertyBridge() { - @Override - public void write(DocumentElement target, Object bridgedElement, - PropertyBridgeWriteContext context) { - target.addValue( - indexFieldReference, pojoPropertyAccessor.read( bridgedElement ) - ); - } - } - ); + context.setBridge( (DocumentElement target, Object bridgedElement, PropertyBridgeWriteContext context1) -> { + target.addValue( + indexFieldReference, pojoPropertyAccessor.read( bridgedElement ) + ); + } ); } ) ) .setup( IndexedEntity.class ); @@ -184,18 +178,12 @@ public Contained getContained() { f -> f.asString().analyzer( "myAnalyzer" ) ) .toReference(); - context.setBridge( - new PropertyBridge() { - @Override - public void write(DocumentElement target, Object bridgedElement, - PropertyBridgeWriteContext context) { - Contained castedBridgedElement = (Contained) bridgedElement; - target.addValue( - indexFieldReference, castedBridgedElement.getStringProperty() - ); - } - } - ); + context.setBridge( (DocumentElement target, Object bridgedElement, PropertyBridgeWriteContext context1) -> { + Contained castedBridgedElement = (Contained) bridgedElement; + target.addValue( + indexFieldReference, castedBridgedElement.getStringProperty() + ); + } ); } ) ) .setup( IndexedEntity.class ); @@ -352,20 +340,16 @@ public void explicitReindexing() { f -> f.asString().analyzer( "myAnalyzer" ) ) .toReference(); - context.setBridge( new PropertyBridge() { - @Override - public void write(DocumentElement target, Object bridgedElement, - PropertyBridgeWriteContext context) { - PropertyBridgeExplicitIndexingClasses.ContainedLevel1Entity castedBridgedElement = - (PropertyBridgeExplicitIndexingClasses.ContainedLevel1Entity) bridgedElement; - /* - * In a real application this would run a query, - * but we don't have the necessary infrastructure here - * so we'll cut short and just index a constant. - * We just need to know the bridge is executed anyway. - */ - target.addValue( indexFieldReference, "constant" ); - } + context.setBridge( (DocumentElement target, Object bridgedElement, PropertyBridgeWriteContext context1) -> { + PropertyBridgeExplicitIndexingClasses.ContainedLevel1Entity castedBridgedElement = + (PropertyBridgeExplicitIndexingClasses.ContainedLevel1Entity) bridgedElement; + /* + * In a real application this would run a query, + * but we don't have the necessary infrastructure here + * so we'll cut short and just index a constant. + * We just need to know the bridge is executed anyway. + */ + target.addValue( indexFieldReference, "constant" ); } ); } ) ) @@ -800,14 +784,10 @@ public List getStringProperty() { f -> f.asString().analyzer( "myAnalyzer" ) ) .toReference(); - context.setBridge( new PropertyBridge() { - @Override - public void write(DocumentElement target, Object bridgedElement, - PropertyBridgeWriteContext context) { - List castedBridgedElement = (List) bridgedElement; - for ( String string : castedBridgedElement ) { - target.addValue( indexFieldReference, string ); - } + context.setBridge( (DocumentElement target, Object bridgedElement, PropertyBridgeWriteContext context1) -> { + List castedBridgedElement = (List) bridgedElement; + for ( String string : castedBridgedElement ) { + target.addValue( indexFieldReference, string ); } } ); } ) diff --git a/integrationtest/mapper/pojo/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/mapping/definition/TypeBridgeBaseIT.java b/integrationtest/mapper/pojo/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/mapping/definition/TypeBridgeBaseIT.java index 43e1b3ab18e..dce026fc34f 100644 --- a/integrationtest/mapper/pojo/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/mapping/definition/TypeBridgeBaseIT.java +++ b/integrationtest/mapper/pojo/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/mapping/definition/TypeBridgeBaseIT.java @@ -94,17 +94,11 @@ public String getStringProperty() { f -> f.asString().analyzer( "myAnalyzer" ) ) .toReference(); - context.setBridge( - new TypeBridge() { - @Override - public void write(DocumentElement target, Object bridgedElement, - TypeBridgeWriteContext context) { - target.addValue( - indexFieldReference, pojoPropertyAccessor.read( bridgedElement ) - ); - } - } - ); + context.setBridge( (DocumentElement target, Object bridgedElement, TypeBridgeWriteContext context1) -> { + target.addValue( + indexFieldReference, pojoPropertyAccessor.read( bridgedElement ) + ); + } ); } ) ) .setup( IndexedEntity.class ); @@ -172,18 +166,12 @@ public String getStringProperty() { f -> f.asString().analyzer( "myAnalyzer" ) ) .toReference(); - context.setBridge( - new TypeBridge() { - @Override - public void write(DocumentElement target, Object bridgedElement, - TypeBridgeWriteContext context) { - IndexedEntity castedBridgedElement = (IndexedEntity) bridgedElement; - target.addValue( - indexFieldReference, castedBridgedElement.getStringProperty() - ); - } - } - ); + context.setBridge( (DocumentElement target, Object bridgedElement, TypeBridgeWriteContext context1) -> { + IndexedEntity castedBridgedElement = (IndexedEntity) bridgedElement; + target.addValue( + indexFieldReference, castedBridgedElement.getStringProperty() + ); + } ); } ) ) .setup( IndexedEntity.class ); @@ -296,22 +284,16 @@ public String getStringProperty() { f -> f.asString().analyzer( "myAnalyzer" ) ) .toReference(); - context.setBridge( - new TypeBridge() { - @Override - public void write(DocumentElement target, Object bridgedElement, - TypeBridgeWriteContext context) { - IndexedEntity castedBridgedElement = (IndexedEntity) bridgedElement; - /* - * In a real application this would run a query, - * but we don't have the necessary infrastructure here - * so we'll cut short and just index a constant. - * We just need to know the bridge is executed anyway. - */ - target.addValue( indexFieldReference, "constant" ); - } - } - ); + context.setBridge( (DocumentElement target, Object bridgedElement, TypeBridgeWriteContext context1) -> { + IndexedEntity castedBridgedElement = (IndexedEntity) bridgedElement; + /* + * In a real application this would run a query, + * but we don't have the necessary infrastructure here + * so we'll cut short and just index a constant. + * We just need to know the bridge is executed anyway. + */ + target.addValue( indexFieldReference, "constant" ); + } ); } ) ) .setup( IndexedEntity.class, ContainedEntity.class ); @@ -699,15 +681,11 @@ public CustomEnum getEnumProperty() { f -> f.asString() ) .toReference(); - context.setBridge( new TypeBridge() { - @Override - public void write(DocumentElement target, Object bridgedElement, - TypeBridgeWriteContext context) { - CustomEnum castedBridgedElement = (CustomEnum) bridgedElement; - // This is a strange way to use bridges, - // but then again a type bridges that only uses the root *is* strange - target.addValue( indexFieldReference, castedBridgedElement.stringProperty ); - } + context.setBridge( (DocumentElement target, Object bridgedElement, TypeBridgeWriteContext context1) -> { + CustomEnum castedBridgedElement = (CustomEnum) bridgedElement; + // This is a strange way to use bridges, + // but then again a type bridges that only uses the root *is* strange + target.addValue( indexFieldReference, castedBridgedElement.stringProperty ); } ); } ) ) diff --git a/util/common/src/test/java/org/hibernate/search/util/common/impl/CloserTest.java b/util/common/src/test/java/org/hibernate/search/util/common/impl/CloserTest.java index 17d2258b417..78d4976ef2d 100644 --- a/util/common/src/test/java/org/hibernate/search/util/common/impl/CloserTest.java +++ b/util/common/src/test/java/org/hibernate/search/util/common/impl/CloserTest.java @@ -36,11 +36,8 @@ public void javaIOCloseable() throws IOException { IOException exception1 = new IOException(); RuntimeException exception2 = new IllegalStateException(); @SuppressWarnings("resource") - Closeable closeable = new Closeable() { - @Override - public void close() throws IOException { - throw exception1; - } + Closeable closeable = () -> { + throw exception1; }; thrown.expect( @@ -60,11 +57,8 @@ public void autoCloseable() throws Exception { Exception exception1 = new Exception(); RuntimeException exception2 = new IllegalStateException(); @SuppressWarnings("resource") - AutoCloseable closeable = new AutoCloseable() { - @Override - public void close() throws Exception { - throw exception1; - } + AutoCloseable closeable = () -> { + throw exception1; }; thrown.expect( @@ -127,11 +121,8 @@ public void customCloseable() throws MyException1 { MyException1 exception1 = new MyException1(); RuntimeException exception2 = new IllegalStateException(); @SuppressWarnings("resource") - MyException1Closeable closeable = new MyException1Closeable() { - @Override - public void close() throws MyException1 { - throw exception1; - } + MyException1Closeable closeable = () -> { + throw exception1; }; thrown.expect( diff --git a/util/common/src/test/java/org/hibernate/search/util/common/impl/SuppressingCloserTest.java b/util/common/src/test/java/org/hibernate/search/util/common/impl/SuppressingCloserTest.java index 225e039083d..bf9a19b8351 100644 --- a/util/common/src/test/java/org/hibernate/search/util/common/impl/SuppressingCloserTest.java +++ b/util/common/src/test/java/org/hibernate/search/util/common/impl/SuppressingCloserTest.java @@ -37,11 +37,8 @@ public void javaIOCloseable() { IOException exception1 = new IOException(); RuntimeException exception2 = new IllegalStateException(); @SuppressWarnings("resource") - Closeable closeable = new Closeable() { - @Override - public void close() throws IOException { - throw exception1; - } + Closeable closeable = () -> { + throw exception1; }; new SuppressingCloser( mainException ) @@ -59,11 +56,8 @@ public void autoCloseable() { Exception exception1 = new Exception(); RuntimeException exception2 = new IllegalStateException(); @SuppressWarnings("resource") - AutoCloseable closeable = new AutoCloseable() { - @Override - public void close() throws Exception { - throw exception1; - } + AutoCloseable closeable = () -> { + throw exception1; }; new SuppressingCloser( mainException ) @@ -133,11 +127,8 @@ public void customCloseable() { MyException1 exception1 = new MyException1(); RuntimeException exception2 = new IllegalStateException(); @SuppressWarnings("resource") - MyException1Closeable closeable = new MyException1Closeable() { - @Override - public void close() throws MyException1 { - throw exception1; - } + MyException1Closeable closeable = () -> { + throw exception1; }; new SuppressingCloser( mainException ) diff --git a/util/internal/integrationtest/common/src/main/java/org/hibernate/search/util/impl/integrationtest/common/stub/backend/search/projection/impl/StubSearchProjectionBuilderFactory.java b/util/internal/integrationtest/common/src/main/java/org/hibernate/search/util/impl/integrationtest/common/stub/backend/search/projection/impl/StubSearchProjectionBuilderFactory.java index 4a61f463255..9a913056a97 100644 --- a/util/internal/integrationtest/common/src/main/java/org/hibernate/search/util/impl/integrationtest/common/stub/backend/search/projection/impl/StubSearchProjectionBuilderFactory.java +++ b/util/internal/integrationtest/common/src/main/java/org/hibernate/search/util/impl/integrationtest/common/stub/backend/search/projection/impl/StubSearchProjectionBuilderFactory.java @@ -61,22 +61,12 @@ public SearchProjection build() { @Override public EntityProjectionBuilder entity() { - return new EntityProjectionBuilder() { - @Override - public SearchProjection build() { - return StubEntitySearchProjection.get(); - } - }; + return StubEntitySearchProjection::get; } @Override public EntityReferenceProjectionBuilder entityReference() { - return new EntityReferenceProjectionBuilder() { - @Override - public SearchProjection build() { - return StubReferenceSearchProjection.get(); - } - }; + return StubReferenceSearchProjection::get; } @Override