Skip to content

Commit

Permalink
HSEARCH-3958 Make AggregationDescriptors singletons
Browse files Browse the repository at this point in the history
Like we did some time ago with field type descriptors.
  • Loading branch information
yrodiere committed Jul 1, 2020
1 parent e0c8791 commit 134cc8d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private boolean isSortSupported() {
}

private boolean isAggregationSupported() {
return new TermsAggregationDescriptor().getSingleFieldAggregationExpectations( fieldType ).isSupported();
return TermsAggregationDescriptor.INSTANCE.getSingleFieldAggregationExpectations( fieldType ).isSupported();
}

private class IndexBinding {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static Object[][] parameters() {
supportedFieldTypes = new LinkedHashSet<>();
dataSets = new ArrayList<>();
List<Object[]> parameters = new ArrayList<>();
AggregationDescriptor aggregationDescriptor = new RangeAggregationDescriptor();
AggregationDescriptor aggregationDescriptor = RangeAggregationDescriptor.INSTANCE;
for ( FieldTypeDescriptor<?> fieldType : FieldTypeDescriptor.getAll() ) {
if ( aggregationDescriptor.getSingleFieldAggregationExpectations( fieldType ).isSupported() ) {
supportedFieldTypes.add( fieldType );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static Object[][] parameters() {
supportedFieldTypes = new LinkedHashSet<>();
dataSets = new ArrayList<>();
List<Object[]> parameters = new ArrayList<>();
AggregationDescriptor aggregationDescriptor = new TermsAggregationDescriptor();
AggregationDescriptor aggregationDescriptor = TermsAggregationDescriptor.INSTANCE;
for ( FieldTypeDescriptor<?> fieldType : FieldTypeDescriptor.getAll() ) {
if ( aggregationDescriptor.getSingleFieldAggregationExpectations( fieldType ).isSupported() ) {
supportedFieldTypes.add( fieldType );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public abstract class AggregationDescriptor {
public static List<AggregationDescriptor> getAll() {
if ( all == null ) {
all = Collections.unmodifiableList( Arrays.asList(
new RangeAggregationDescriptor(),
new TermsAggregationDescriptor()
RangeAggregationDescriptor.INSTANCE,
TermsAggregationDescriptor.INSTANCE
) );
}
return all;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@

public class RangeAggregationDescriptor extends AggregationDescriptor {

public static RangeAggregationDescriptor INSTANCE = new RangeAggregationDescriptor();

private RangeAggregationDescriptor() {
}

@Override
public <F> ExpectationsAlternative<
SupportedSingleFieldAggregationExpectations<F>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@

public class TermsAggregationDescriptor extends AggregationDescriptor {

public static TermsAggregationDescriptor INSTANCE = new TermsAggregationDescriptor();

private TermsAggregationDescriptor() {
}

@Override
public <F> ExpectationsAlternative<
SupportedSingleFieldAggregationExpectations<F>,
Expand Down

0 comments on commit 134cc8d

Please sign in to comment.