io.polyglotted.pgmodel.search.query.Bucket Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pg-model Show documentation
Show all versions of pg-model Show documentation
Standard set of models for geo coding, access control and elastic search abstraction
The newest version!
package io.polyglotted.pgmodel.search.query;
import com.google.common.collect.ImmutableList;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static com.google.common.collect.Iterables.transform;
import static io.polyglotted.pgmodel.util.ModelUtil.jsonEquals;
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@ToString(includeFieldNames = false, doNotUseGetters = true, of = {"key", "count", "aggregations"})
public final class Bucket {
public final String key;
public final Object value;
public final long count;
public final long errors;
public final ImmutableList aggregations;
@Override
public boolean equals(Object o) {
return jsonEquals(this, o);
}
@Override
public int hashCode() {
return Objects.hash(key, value, count, errors, aggregations);
}
@SuppressWarnings("unchecked")
public T keyValue() {
return (T) value;
}
public boolean hasAggregations() {
return aggregations.size() > 0;
}
public static Builder bucketBuilder() {
return new Builder();
}
@Setter
@Accessors(fluent = true)
public static class Builder {
private String key;
private Object keyValue;
private long docCount;
private long docCountError;
private final List builders = new ArrayList<>();
public Builder aggregation(Aggregation.Builder builder) {
this.builders.add(builder);
return this;
}
public Bucket build() {
Iterable aggregations = transform(builders, Aggregation.Builder::build);
return new Bucket(key, keyValue, docCount, docCountError, ImmutableList.copyOf(aggregations));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy