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

com.eventsourcing.index.MultiValueIndex Maven / Gradle / Ivy

There is a newer version: 0.4.6
Show newest version
/**
 * 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