Skip to content

Commit 229da0d

Browse files
committed
apply spotless formatting
1 parent ad912cd commit 229da0d

15 files changed

+535
-385
lines changed

build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,26 @@ buildscript {
99
}
1010
}
1111

12+
// the spotless plugin is dedicated to format the code
13+
plugins {
14+
id("com.diffplug.spotless") version "7.0.4"
15+
}
16+
1217
repositories {
1318
mavenLocal()
1419
mavenCentral()
1520
}
1621

22+
// add -Xlint:deprecation to check the Elasticsearch deprecation warning at compile-time
23+
allprojects {
24+
gradle.projectsEvaluated {
25+
tasks.withType(JavaCompile) {
26+
options.compilerArgs << "-Xlint:deprecation"
27+
options.compilerArgs << "-Xlint:unchecked"
28+
}
29+
}
30+
}
31+
1732
group = 'org.elasticsearch.plugin'
1833
version = "${plugin_version}"
1934

@@ -24,6 +39,17 @@ apply plugin: 'idea'
2439
apply plugin: 'elasticsearch.esplugin'
2540
apply plugin: 'elasticsearch.yaml-rest-test'
2641

42+
// automatic formatting configuration (the same configuration as elasticsearch)
43+
spotless {
44+
java {
45+
importOrderFile('config/elastic.importorder') // import order file as exported from elastic
46+
eclipse().configFile('config/formatterConfig.xml')
47+
trimTrailingWhitespace()
48+
target 'src/**/*.java'
49+
}
50+
}
51+
52+
check.dependsOn spotlessCheck
2753

2854
esplugin {
2955
name 'pathhierarchy-aggregation'

src/main/java/org/opendatasoft/elasticsearch/plugin/PathHierarchyAggregation.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@ public class PathHierarchyAggregation extends Plugin implements SearchPlugin {
1414
public ArrayList<SearchPlugin.AggregationSpec> getAggregations() {
1515
ArrayList<SearchPlugin.AggregationSpec> r = new ArrayList<>();
1616
r.add(
17-
new AggregationSpec(
18-
PathHierarchyAggregationBuilder.NAME,
19-
PathHierarchyAggregationBuilder::new,
20-
PathHierarchyAggregationBuilder.PARSER)
21-
.addResultReader(InternalPathHierarchy::new)
22-
.setAggregatorRegistrar(PathHierarchyAggregationBuilder::registerAggregators)
17+
new AggregationSpec(
18+
PathHierarchyAggregationBuilder.NAME,
19+
PathHierarchyAggregationBuilder::new,
20+
PathHierarchyAggregationBuilder.PARSER
21+
).addResultReader(InternalPathHierarchy::new).setAggregatorRegistrar(PathHierarchyAggregationBuilder::registerAggregators)
2322
);
2423
r.add(
25-
new AggregationSpec(
26-
DateHierarchyAggregationBuilder.NAME,
27-
DateHierarchyAggregationBuilder::new,
28-
DateHierarchyAggregationBuilder.PARSER)
29-
.addResultReader(InternalDateHierarchy::new)
30-
.setAggregatorRegistrar(DateHierarchyAggregationBuilder::registerAggregators)
24+
new AggregationSpec(
25+
DateHierarchyAggregationBuilder.NAME,
26+
DateHierarchyAggregationBuilder::new,
27+
DateHierarchyAggregationBuilder.PARSER
28+
).addResultReader(InternalDateHierarchy::new).setAggregatorRegistrar(DateHierarchyAggregationBuilder::registerAggregators)
3129
);
3230
return r;
3331
}

src/main/java/org/opendatasoft/elasticsearch/search/aggregations/bucket/DateHierarchyAggregationBuilder.java

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
package org.opendatasoft.elasticsearch.search.aggregations.bucket;
22

33
import org.elasticsearch.Version;
4-
import org.elasticsearch.xcontent.ParseField;
54
import org.elasticsearch.common.Rounding;
65
import org.elasticsearch.common.io.stream.StreamInput;
76
import org.elasticsearch.common.io.stream.StreamOutput;
87
import org.elasticsearch.common.io.stream.Writeable;
98
import org.elasticsearch.common.time.DateFormatter;
10-
import org.elasticsearch.xcontent.ObjectParser;
11-
import org.elasticsearch.xcontent.XContentBuilder;
12-
import org.elasticsearch.xcontent.XContentParser;
139
import org.elasticsearch.index.mapper.DateFieldMapper;
14-
import org.elasticsearch.search.aggregations.support.AggregationContext;
1510
import org.elasticsearch.search.DocValueFormat;
1611
import org.elasticsearch.search.aggregations.AggregationBuilder;
1712
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
1813
import org.elasticsearch.search.aggregations.AggregatorFactory;
1914
import org.elasticsearch.search.aggregations.BucketOrder;
2015
import org.elasticsearch.search.aggregations.InternalOrder;
16+
import org.elasticsearch.search.aggregations.support.AggregationContext;
2117
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
2218
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
2319
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
2420
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
2521
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
2622
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
23+
import org.elasticsearch.xcontent.ObjectParser;
24+
import org.elasticsearch.xcontent.ParseField;
25+
import org.elasticsearch.xcontent.XContentBuilder;
26+
import org.elasticsearch.xcontent.XContentParser;
2727

2828
import java.io.IOException;
2929
import java.time.ZoneId;
@@ -36,23 +36,20 @@
3636

3737
import static java.util.Collections.unmodifiableMap;
3838

39-
4039
/**
4140
* The builder of the aggregatorFactory. Also implements the parsing of the request.
4241
*/
4342
public class DateHierarchyAggregationBuilder extends ValuesSourceAggregationBuilder<DateHierarchyAggregationBuilder> {
4443
public static final String NAME = "date_hierarchy";
4544
public static final ValuesSourceRegistry.RegistryKey<DateHierarchyAggregationSupplier> REGISTRY_KEY =
46-
new ValuesSourceRegistry.RegistryKey<>(NAME, DateHierarchyAggregationSupplier.class);
47-
45+
new ValuesSourceRegistry.RegistryKey<>(NAME, DateHierarchyAggregationSupplier.class);
4846

4947
public static final ParseField INTERVAL_FIELD = new ParseField("interval");
5048
public static final ParseField ORDER_FIELD = new ParseField("order");
5149
public static final ParseField SIZE_FIELD = new ParseField("size");
5250
public static final ParseField SHARD_SIZE_FIELD = new ParseField("shard_size");
5351
public static final ParseField MIN_DOC_COUNT_FIELD = new ParseField("min_doc_count");
5452

55-
5653
public static final Map<String, IntervalConfig> INTERVAL_CONFIG;
5754
static {
5855
Map<String, IntervalConfig> dateFieldUnits = new LinkedHashMap<>();
@@ -88,13 +85,19 @@ public PreparedRounding(RoundingInfo roundingInfo, Rounding.Prepared prepared) {
8885
public List<PreparedRounding> buildRoundings() {
8986
List<PreparedRounding> roundings = new ArrayList<>();
9087

91-
ZoneId timeZone = timeZone() == null ? ZoneOffset.UTC: timeZone();
88+
ZoneId timeZone = timeZone() == null ? ZoneOffset.UTC : timeZone();
9289

9390
long now = System.currentTimeMillis();
9491
for (String interval : INTERVAL_CONFIG.keySet()) {
95-
RoundingInfo ri = new RoundingInfo(interval, createRounding(INTERVAL_CONFIG.get(interval).dateTimeUnit),
96-
new DocValueFormat.DateTime(DateFormatter.forPattern(INTERVAL_CONFIG.get(interval).format), timeZone,
97-
DateFieldMapper.Resolution.MILLISECONDS));
92+
RoundingInfo ri = new RoundingInfo(
93+
interval,
94+
createRounding(INTERVAL_CONFIG.get(interval).dateTimeUnit),
95+
new DocValueFormat.DateTime(
96+
DateFormatter.forPattern(INTERVAL_CONFIG.get(interval).format),
97+
timeZone,
98+
DateFieldMapper.Resolution.MILLISECONDS
99+
)
100+
);
98101
roundings.add(new PreparedRounding(ri, ri.rounding.prepareForUnknown()));
99102

100103
if (interval.equals(interval())) {
@@ -112,7 +115,7 @@ public static class RoundingInfo implements Writeable {
112115

113116
public RoundingInfo(String interval, Rounding rounding, DocValueFormat docValueFormat) {
114117
this.interval = interval;
115-
this.rounding = rounding;
118+
this.rounding = rounding;
116119
this.format = docValueFormat;
117120
}
118121

@@ -130,10 +133,12 @@ public void writeTo(StreamOutput out) throws IOException {
130133
}
131134
}
132135

133-
public static final DateHierarchyAggregator.BucketCountThresholds DEFAULT_BUCKET_COUNT_THRESHOLDS = new
134-
DateHierarchyAggregator.BucketCountThresholds(10, -1);
135-
public static final ObjectParser<DateHierarchyAggregationBuilder, String> PARSER =
136-
ObjectParser.fromBuilder(NAME, DateHierarchyAggregationBuilder::new);
136+
public static final DateHierarchyAggregator.BucketCountThresholds DEFAULT_BUCKET_COUNT_THRESHOLDS =
137+
new DateHierarchyAggregator.BucketCountThresholds(10, -1);
138+
public static final ObjectParser<DateHierarchyAggregationBuilder, String> PARSER = ObjectParser.fromBuilder(
139+
NAME,
140+
DateHierarchyAggregationBuilder::new
141+
);
137142
static {
138143

139144
ValuesSourceAggregationBuilder.declareFields(PARSER, true, true, true);
@@ -151,8 +156,7 @@ public void writeTo(StreamOutput out) throws IOException {
151156
PARSER.declareInt(DateHierarchyAggregationBuilder::size, SIZE_FIELD);
152157
PARSER.declareLong(DateHierarchyAggregationBuilder::minDocCount, MIN_DOC_COUNT_FIELD);
153158
PARSER.declareInt(DateHierarchyAggregationBuilder::shardSize, SHARD_SIZE_FIELD);
154-
PARSER.declareObjectArray(DateHierarchyAggregationBuilder::order, (p, c) -> InternalOrder.Parser.parseOrderParam(p),
155-
ORDER_FIELD);
159+
PARSER.declareObjectArray(DateHierarchyAggregationBuilder::order, (p, c) -> InternalOrder.Parser.parseOrderParam(p), ORDER_FIELD);
156160
}
157161

158162
public static AggregationBuilder parse(String aggregationName, XContentParser parser) throws IOException {
@@ -168,8 +172,8 @@ public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
168172
private String interval = "years";
169173
private BucketOrder order = BucketOrder.compound(BucketOrder.count(false)); // automatically adds tie-breaker key asc order
170174
private DateHierarchyAggregator.BucketCountThresholds bucketCountThresholds = new DateHierarchyAggregator.BucketCountThresholds(
171-
DEFAULT_BUCKET_COUNT_THRESHOLDS);
172-
175+
DEFAULT_BUCKET_COUNT_THRESHOLDS
176+
);
173177

174178
private DateHierarchyAggregationBuilder(String name) {
175179
super(name);
@@ -193,8 +197,7 @@ public DateHierarchyAggregationBuilder(StreamInput in) throws IOException {
193197
timeZone = in.readOptionalZoneId();
194198
}
195199

196-
private DateHierarchyAggregationBuilder(DateHierarchyAggregationBuilder clone, Builder factoriesBuilder,
197-
Map<String, Object> metaData) {
200+
private DateHierarchyAggregationBuilder(DateHierarchyAggregationBuilder clone, Builder factoriesBuilder, Map<String, Object> metaData) {
198201
super(clone, factoriesBuilder, metaData);
199202
order = clone.order;
200203
minDocCount = clone.minDocCount;
@@ -275,7 +278,7 @@ private DateHierarchyAggregationBuilder order(BucketOrder order) {
275278
if (order == null) {
276279
throw new IllegalArgumentException("[order] must not be null: [" + name + "]");
277280
}
278-
if(order instanceof InternalOrder.CompoundOrder || InternalOrder.isKeyOrder(order)) {
281+
if (order instanceof InternalOrder.CompoundOrder || InternalOrder.isKeyOrder(order)) {
279282
this.order = order; // if order already contains a tie-breaker we are good to go
280283
} else { // otherwise add a tie-breaker by using a compound order
281284
this.order = BucketOrder.compound(order);
@@ -292,7 +295,6 @@ private DateHierarchyAggregationBuilder order(List<BucketOrder> orders) {
292295
return this;
293296
}
294297

295-
296298
/**
297299
* Sets the size - indicating how many term buckets should be returned
298300
* (defaults to 10)
@@ -310,7 +312,8 @@ public DateHierarchyAggregationBuilder size(int size) {
310312
public DateHierarchyAggregationBuilder minDocCount(long minDocCount) {
311313
if (minDocCount < 0) {
312314
throw new IllegalArgumentException(
313-
"[minDocCount] must be greater than or equal to 0. Found [" + minDocCount + "] in [" + name + "]");
315+
"[minDocCount] must be greater than or equal to 0. Found [" + minDocCount + "] in [" + name + "]"
316+
);
314317
}
315318
this.minDocCount = minDocCount;
316319
return this;
@@ -336,8 +339,7 @@ public BucketCardinality bucketCardinality() {
336339
*/
337340
public DateHierarchyAggregationBuilder shardSize(int shardSize) {
338341
if (shardSize <= 0) {
339-
throw new IllegalArgumentException(
340-
"[shardSize] must be greater than 0. Found [" + shardSize + "] in [" + name + "]");
342+
throw new IllegalArgumentException("[shardSize] must be greater than 0. Found [" + shardSize + "] in [" + name + "]");
341343
}
342344
bucketCountThresholds.setShardSize(shardSize);
343345
return this;
@@ -351,25 +353,27 @@ public int shardSize() {
351353
}
352354

353355
@Override
354-
protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context,
355-
ValuesSourceConfig config,
356-
AggregatorFactory parent,
357-
Builder subFactoriesBuilder) throws IOException {
358-
356+
protected ValuesSourceAggregatorFactory innerBuild(
357+
AggregationContext context,
358+
ValuesSourceConfig config,
359+
AggregatorFactory parent,
360+
Builder subFactoriesBuilder
361+
) throws IOException {
359362

360363
final List<PreparedRounding> preparedRoundings = buildRoundings();
361364

362365
return new DateHierarchyAggregatorFactory(
363-
name,
364-
config,
365-
order,
366-
preparedRoundings,
367-
minDocCount,
368-
bucketCountThresholds,
369-
context,
370-
parent,
371-
subFactoriesBuilder,
372-
metadata);
366+
name,
367+
config,
368+
order,
369+
preparedRoundings,
370+
minDocCount,
371+
bucketCountThresholds,
372+
context,
373+
parent,
374+
subFactoriesBuilder,
375+
metadata
376+
);
373377
}
374378

375379
@Override
@@ -398,10 +402,10 @@ public boolean equals(Object obj) {
398402
if (!super.equals(obj)) return false;
399403
DateHierarchyAggregationBuilder other = (DateHierarchyAggregationBuilder) obj;
400404
return Objects.equals(interval, other.interval)
401-
&& Objects.equals(order, other.order)
402-
&& Objects.equals(minDocCount, other.minDocCount)
403-
&& Objects.equals(bucketCountThresholds, other.bucketCountThresholds)
404-
&& Objects.equals(timeZone, other.timeZone);
405+
&& Objects.equals(order, other.order)
406+
&& Objects.equals(minDocCount, other.minDocCount)
407+
&& Objects.equals(bucketCountThresholds, other.bucketCountThresholds)
408+
&& Objects.equals(timeZone, other.timeZone);
405409
}
406410

407411
@Override
@@ -410,6 +414,7 @@ public String getType() {
410414
}
411415

412416
@Override
413-
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() { return REGISTRY_KEY; }
417+
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
418+
return REGISTRY_KEY;
419+
}
414420
}
415-

src/main/java/org/opendatasoft/elasticsearch/search/aggregations/bucket/DateHierarchyAggregationSupplier.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313

1414
@FunctionalInterface
1515
public interface DateHierarchyAggregationSupplier {
16-
Aggregator build(String name,
17-
AggregatorFactories factories,
18-
BucketOrder order,
19-
List<DateHierarchyAggregationBuilder.RoundingInfo> roundingsInfo,
20-
long minDocCount,
21-
DateHierarchyAggregator.BucketCountThresholds bucketCountThresholds,
22-
ValuesSourceConfig valuesSourceConfig,
23-
SearchContext aggregationContext,
24-
Aggregator parent,
25-
CardinalityUpperBound cardinality,
26-
Map<String, Object> metadata) throws IOException;
16+
Aggregator build(
17+
String name,
18+
AggregatorFactories factories,
19+
BucketOrder order,
20+
List<DateHierarchyAggregationBuilder.RoundingInfo> roundingsInfo,
21+
long minDocCount,
22+
DateHierarchyAggregator.BucketCountThresholds bucketCountThresholds,
23+
ValuesSourceConfig valuesSourceConfig,
24+
SearchContext aggregationContext,
25+
Aggregator parent,
26+
CardinalityUpperBound cardinality,
27+
Map<String, Object> metadata
28+
) throws IOException;
2729
}

0 commit comments

Comments
 (0)