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

com.ocadotechnology.indexedcache.OneToManyIndex Maven / Gradle / Ivy

There is a newer version: 16.6.21
Show newest version
/*
 * Copyright © 2017-2023 Ocado (Ocava)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ocadotechnology.indexedcache;

import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;

import javax.annotation.CheckForNull;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.ocadotechnology.id.Identified;
import com.ocadotechnology.indexedcache.OneToOneIndex.WrappedIndexingFunction;

public final class OneToManyIndex> extends AbstractIndex {

    private final OptionalOneToManyIndex optionalOneToManyIndex;

    /**
     * @deprecated use OptionalOneToManyIndex or pass in a non-optional function
     */
    @Deprecated
    public OneToManyIndex(Function> function) {
        super(null);
        optionalOneToManyIndex = new OptionalOneToManyIndex<>(function);
    }

    private OneToManyIndex(@CheckForNull String name, Function function) {
        super(name);
        optionalOneToManyIndex = new OptionalOneToManyIndex<>(name, new WrappedIndexingFunction<>(function, formattedName));
    }

    public static > OneToManyIndex create(Function function) {
        return create(null, function);
    }

    public static > OneToManyIndex create(@CheckForNull String name, Function function) {
        return new OneToManyIndex<>(name, function);
    }

    public ImmutableList getCopy(R r) {
        return optionalOneToManyIndex.getCopy(r);
    }

    public ImmutableSet getCopyAsSet(R r) {
        return optionalOneToManyIndex.getCopyAsSet(r);
    }

    public boolean isEmpty(R r) {
        return optionalOneToManyIndex.isEmpty(r);
    }

    public int count(R r) {
        return optionalOneToManyIndex.count(r);
    }

    public Stream stream(R r) {
        return optionalOneToManyIndex.stream(r);
    }

    @Override
    protected void add(C object) {
        optionalOneToManyIndex.add(object);
    }

    @Override
    protected void remove(C object) {
        optionalOneToManyIndex.remove(object);
    }

    public Stream streamKeys() {
        return optionalOneToManyIndex.streamKeys();
    }

    public ImmutableMultimap snapshot() {
        return optionalOneToManyIndex.snapshot();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy