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

com.github.protobufel.multikeymap.MultiKeyMaps Maven / Gradle / Ivy

Go to download

Java 8 implementation of the multi-key map. It behaves like a regular generic Map with the additional ability of getting its values by any combination of partial keys.

The newest version!
/*
 *    Copyright 2017 David Tesler
 *
 *    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.github.protobufel.multikeymap;

import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;

/**
 * Provides the factory methods of the generic MultiKeyMap implementations.
 *
 * @author David Tesler
 */
public final class MultiKeyMaps {
    private MultiKeyMaps() {
    }

    /**
     * Creates a new MultiKeyMap based on the provided map supplier.
     * The returned MultiKeyMap is Serializable if the provided map is Serializable.
     * 

NOTE: Use with caution. This is the advanced functionality. * * @param mapSupplier a supplier of {@code Map} this MultiKeyMap is based on * @param concurrent create a concurrent instance if true, un-synchronized, regular instance, otherwise * @param the type of a sub-key the key consist of * @param the type of a full key, which is an Iterable of its sub-keys, with usage as in a * regular Map * @param the type of a value which stored in the MultiKeyMap under the corresponding key * @return a new instance of the implementation of MultiKeyMap */ public static , V> MultiKeyMap newMultiKeyMap( final Supplier> mapSupplier, boolean concurrent) { return new BaseMultiKeyMap(Objects.requireNonNull(mapSupplier).get(), LiteSetMultimap.newInstance(concurrent)); } /** * Creates a new default, Serialiazable instance of MultiKeyMap. * * @param the type of a sub-key the key consist of * @param the type of a full key, which is an Iterable of its sub-keys, with usage as in a * regular Map * @param the type of a value which stored in the MultiKeyMap under the corresponding key * @return a new instance of the default implementation of MultiKeyMap */ public static , V> MultiKeyMap newMultiKeyMap() { return new BaseMultiKeyMap<>(); } /** * Creates a new default, Serialiazable instance of MultiKeyMap initialized off the data by the supplied Map. * * @param map a Map instance to copy data from; the data copied shallowly. * @param the type of a sub-key the key consist of * @param the type of a full key, which is an Iterable of its sub-keys, with usage as in a * regular Map * @param the type of a value which stored in the MultiKeyMap under the corresponding key * @return a new instance of the default implementation of MultiKeyMap initialized with the map's * data */ public static , V> MultiKeyMap of(final Map map) { return new BaseMultiKeyMap<>(Objects.requireNonNull(map)); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy