com.eventsourcing.index.MultiValueIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eventsourcing-core Show documentation
Show all versions of eventsourcing-core Show documentation
Event capture and querying framework for Java
/**
* Copyright (c) 2016, All Contributors (see CONTRIBUTORS file)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.eventsourcing.index;
import com.eventsourcing.Entity;
import com.googlecode.cqengine.query.option.QueryOptions;
import java.util.function.BiFunction;
/**
* Designates a multiple values index using a functional interface
*
* Typically, a definition will look like this:
*
*
*
* public static MultiValueIndex<TestEvent, UUID> REFERENCE_ID = (object) -> ...;
*
*
*
* However, there are cases when accessing {@link QueryOptions} is necessary. This can be achieved
* using {@link MultiValueIndex#withQueryOptions(BiFunction)}:
*
*
*
* public static MultiValueIndex<TestEvent, UUID> REFERENCE_ID =
* MultiValueIndex.withQueryOptions((object, queryOptions) -> ...);
*
*
*
* @param entity type
* @param attribute type
*/
@FunctionalInterface
public interface MultiValueIndex extends EntityIndex {
default Iterable getValues(O object, QueryOptions queryOptions) {
return getValues(object);
}
Iterable getValues(O object);
/**
* Creates a MultiValueIndex with a function that can access {@link QueryOptions}
* @param function
* @param
* @param
* @return
*/
static MultiValueIndex
withQueryOptions(BiFunction> function) {
return new MultiValueIndex() {
@Override public Iterable getValues(O object, QueryOptions queryOptions) {
return function.apply(object, queryOptions);
}
@Override public Iterable getValues(O object) {
return function.apply(object, EntityQueryFactory.noQueryOptions());
}
};
}
default Attribute getAttribute() {
throw new IllegalStateException("Index " + this + " hasn't been initialized yet");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy