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

com.eventsourcing.index.AbstractIndexEngine 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.google.common.util.concurrent.AbstractService;
import com.googlecode.cqengine.index.Index;

import java.util.Arrays;
import java.util.List;

public abstract class AbstractIndexEngine extends AbstractService implements IndexEngine {


    protected abstract List getIndexMatrix();

    @Override @SuppressWarnings("unchecked")
    public  Index getIndexOnAttribute(Attribute attribute, IndexFeature... features)
            throws IndexNotSupported {
        for (IndexCapabilities capabilities : getIndexMatrix()) {
            if (Arrays.asList(capabilities.getFeatures()).containsAll(Arrays.asList(features))) {
                return ((IndexCapabilities) capabilities).getIndex().apply(attribute);
            }
        }
        throw new IndexNotSupported(new Attribute[]{attribute}, features, this);
    }

    @Override @SuppressWarnings("unchecked")
    public  Index getIndexOnAttributes(Attribute[] attributes, IndexFeature... features)
            throws IndexNotSupported {
        for (IndexCapabilities capabilities : getIndexMatrix()) {
            if (Arrays.asList(capabilities.getFeatures()).containsAll(Arrays.asList(features))) {
                return ((IndexCapabilities) capabilities).getIndex().apply(attributes);
            }
        }
        throw new IndexNotSupported(attributes, features, this);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy