All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.datakernel.aggregation.ot.AggregationStructure Maven / Gradle / Ivy

package io.datakernel.aggregation.ot;

import io.datakernel.aggregation.fieldtype.FieldType;
import io.datakernel.aggregation.measure.Measure;
import io.datakernel.util.Initializable;

import java.util.*;

import static io.datakernel.util.CollectionUtils.intersection;
import static io.datakernel.util.Preconditions.checkArgument;

public final class AggregationStructure implements Initializable {

	private final Map keyTypes = new LinkedHashMap<>();
	private final Map measureTypes = new LinkedHashMap<>();
	private final List partitioningKey = new ArrayList<>();
	private final Map measures = new LinkedHashMap<>();

	public List getKeys() {
		return new ArrayList<>(keyTypes.keySet());
	}

	public List getMeasures() {
		return new ArrayList<>(measures.keySet());
	}

	public Map getKeyTypes() {
		return keyTypes;
	}

	public Map getMeasureTypes() {
		return measureTypes;
	}

	public Measure getMeasure(String field) {
		return measures.get(field);
	}

	public FieldType getKeyType(String key) {
		return keyTypes.get(key);
	}

	public FieldType getMeasureType(String field) {
		return measureTypes.get(field);
	}

	public List getPartitioningKey() {
		return partitioningKey;
	}

	public AggregationStructure withKey(String keyId, FieldType type) {
		checkArgument(!keyTypes.containsKey(keyId));
		keyTypes.put(keyId, type);
		return this;
	}

	public AggregationStructure withKeys(Map keyTypes) {
		this.keyTypes.putAll(keyTypes);
		return this;
	}

	public AggregationStructure withMeasure(String measureId, Measure aggregateFunction) {
		checkArgument(!measureTypes.containsKey(measureId));
		measureTypes.put(measureId, aggregateFunction.getFieldType());
		measures.put(measureId, aggregateFunction);
		return this;
	}

	public AggregationStructure withMeasures(Map measures) {
		for (String measureId : measures.keySet()) {
			withMeasure(measureId, measures.get(measureId));
		}
		return this;
	}

	public AggregationStructure withIgnoredMeasure(String measureId, FieldType measureType) {
		checkArgument(!measureTypes.containsKey(measureId));
		measureTypes.put(measureId, measureType);
		return this;
	}

	public AggregationStructure withIgnoredMeasures(Map measureTypes) {
		checkArgument(intersection(this.measureTypes.keySet(), measureTypes.keySet()).isEmpty());
		this.measureTypes.putAll(measureTypes);
		return this;
	}

	public AggregationStructure withPartitioningKey(List partitioningKey) {
		this.partitioningKey.addAll(partitioningKey);
		return this;
	}

	public AggregationStructure withPartitioningKey(String... partitioningKey) {
		this.partitioningKey.addAll(Arrays.asList(partitioningKey));
		return this;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy