Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3056 Avoid instantiating lambdas when calling chained Contain…
…erExtractors Signed-off-by: Yoann Rodière <yoann@hibernate.org>
- Loading branch information
Showing
9 changed files
with
180 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
...main/java/org/hibernate/search/mapper/pojo/extractor/impl/ChainingContainerExtractor.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
...ava/org/hibernate/search/mapper/pojo/extractor/impl/ChainingContainerExtractorHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.mapper.pojo.extractor.impl; | ||
|
||
import org.hibernate.search.engine.environment.bean.BeanHolder; | ||
import org.hibernate.search.mapper.pojo.extractor.ContainerExtractor; | ||
import org.hibernate.search.mapper.pojo.extractor.ValueProcessor; | ||
import org.hibernate.search.util.common.impl.Closer; | ||
|
||
final class ChainingContainerExtractorHolder<C, U, V> implements ContainerExtractorHolder<C, V> { | ||
private final ContainerExtractorHolder<C, U> base; | ||
private final BeanHolder<? extends ContainerExtractor<? super U, V>> chained; | ||
|
||
public ChainingContainerExtractorHolder(ContainerExtractorHolder<C, U> base, | ||
BeanHolder<? extends ContainerExtractor<? super U, V>> chained) { | ||
this.base = base; | ||
this.chained = chained; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder builder = new StringBuilder( "[" ); | ||
appendToString( builder ); | ||
builder.append( "]" ); | ||
return builder.toString(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
try ( Closer<RuntimeException> closer = new Closer<>() ) { | ||
closer.push( ContainerExtractorHolder::close, base ); | ||
closer.push( BeanHolder::close, chained ); | ||
} | ||
} | ||
|
||
@Override | ||
public <T, C2> ValueProcessor<T, C, C2> wrap(ValueProcessor<T, ? super V, C2> perValueProcessor) { | ||
return base.wrap( new ContainerExtractingProcessor<>( chained.get(), perValueProcessor ) ); | ||
} | ||
|
||
@Override | ||
public boolean multiValued() { | ||
return base.multiValued() || chained.get().multiValued(); | ||
} | ||
|
||
@Override | ||
public void appendToString(StringBuilder builder) { | ||
base.appendToString( builder ); | ||
builder.append( ", " ); | ||
builder.append( chained ); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...in/java/org/hibernate/search/mapper/pojo/extractor/impl/ContainerExtractingProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.mapper.pojo.extractor.impl; | ||
|
||
import org.hibernate.search.mapper.pojo.extractor.ContainerExtractor; | ||
import org.hibernate.search.mapper.pojo.extractor.ValueProcessor; | ||
|
||
public final class ContainerExtractingProcessor<T, C, V, C2> implements ValueProcessor<T, C, C2> { | ||
private final ContainerExtractor<? super C, V> extractor; | ||
private final ValueProcessor<T, ? super V, C2> perValueProcessor; | ||
|
||
public ContainerExtractingProcessor(ContainerExtractor<? super C, V> extractor, | ||
ValueProcessor<T, ? super V, C2> perValueProcessor) { | ||
this.extractor = extractor; | ||
this.perValueProcessor = perValueProcessor; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ContainerExtractingProcessor[" | ||
+ "extractor=" + extractor | ||
+ ", perValueProcessor=" + perValueProcessor | ||
+ "]"; | ||
} | ||
|
||
@Override | ||
public void process(T target, C container, C2 context) { | ||
extractor.extract( container, perValueProcessor, target, context ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../java/org/hibernate/search/mapper/pojo/extractor/impl/SingleContainerExtractorHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.mapper.pojo.extractor.impl; | ||
|
||
|
||
import org.hibernate.search.engine.environment.bean.BeanHolder; | ||
import org.hibernate.search.mapper.pojo.extractor.ContainerExtractor; | ||
import org.hibernate.search.mapper.pojo.extractor.ValueProcessor; | ||
|
||
final class SingleContainerExtractorHolder<C, V> implements ContainerExtractorHolder<C, V> { | ||
|
||
private final BeanHolder<? extends ContainerExtractor<? super C, V>> extractorBeanHolder; | ||
|
||
SingleContainerExtractorHolder(BeanHolder<? extends ContainerExtractor<? super C, V>> extractorBeanHolder) { | ||
this.extractorBeanHolder = extractorBeanHolder; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder builder = new StringBuilder(); | ||
appendToString( builder ); | ||
return builder.toString(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
extractorBeanHolder.close(); | ||
} | ||
|
||
@Override | ||
public <T, C2> ValueProcessor<T, C, C2> wrap(ValueProcessor<T, ? super V, C2> perValueProcessor) { | ||
return new ContainerExtractingProcessor<>( extractorBeanHolder.get(), perValueProcessor ); | ||
} | ||
|
||
@Override | ||
public boolean multiValued() { | ||
return extractorBeanHolder.get().multiValued(); | ||
} | ||
|
||
@Override | ||
public void appendToString(StringBuilder builder) { | ||
builder.append( extractorBeanHolder.get() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters