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

com.gs.collections.api.bimap.BiMap Maven / Gradle / Ivy

/*
 * Copyright 2015 Goldman Sachs.
 *
 * 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.gs.collections.api.bimap;

import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.map.MapIterable;
import com.gs.collections.api.multimap.set.SetMultimap;
import com.gs.collections.api.partition.set.PartitionUnsortedSet;
import com.gs.collections.api.set.SetIterable;
import com.gs.collections.api.tuple.Pair;

/**
 * A map that allows users to look up key-value pairs from either direction. Uniqueness is enforced on both the keys and values.
 *
 * @since 4.2
 */
public interface BiMap extends MapIterable
{
    /**
     * Returns an inversed view of this BiMap, where the associations are in the direction of this bimap's values to keys.
     */
    BiMap inverse();

    SetMultimap flip();

    BiMap flipUniqueValues();

    /**
     * Converts the BiMap to an ImmutableBiMap.  If the bimap is immutable, it returns itself.
     */
    ImmutableBiMap toImmutable();

    BiMap tap(Procedure procedure);

    BiMap select(Predicate2 predicate);

    BiMap reject(Predicate2 predicate);

    /**
     * {@inheritDoc}
     *
     * Implementations are expected to delegate to {@link MutableBiMap#put(Object, Object)},
     * {@link ImmutableBiMap#newWithKeyValue(Object, Object)}, or equivalent, not {@link MutableBiMap#forcePut(Object, Object)}.
     *
     * @throws RuntimeException when {@code function} returns colliding keys or values.
     */
     BiMap collect(Function2> function);

    /**
     * {@inheritDoc}
     *
     * Implementations are expected to delegate to {@link MutableBiMap#put(Object, Object)},
     * {@link ImmutableBiMap#newWithKeyValue(Object, Object)}, or equivalent, not {@link MutableBiMap#forcePut(Object, Object)}.
     *
     * @throws RuntimeException when {@code function} returns colliding values.
     */
     BiMap collectValues(Function2 function);

    SetIterable select(Predicate predicate);

    

SetIterable selectWith(Predicate2 predicate, P parameter); SetIterable reject(Predicate predicate);

SetIterable rejectWith(Predicate2 predicate, P parameter); PartitionUnsortedSet partition(Predicate predicate);

PartitionUnsortedSet partitionWith(Predicate2 predicate, P parameter); SetIterable selectInstancesOf(Class clazz); SetIterable> zip(Iterable that); SetIterable> zipWithIndex(); SetMultimap groupBy(Function function); SetMultimap groupByEach(Function> function); BiMap groupByUniqueKey(Function function); }