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

org.eclipse.collections.api.bimap.ImmutableBiMap Maven / Gradle / Ivy

There is a newer version: 12.0.0.M3
Show newest version
/*
 * Copyright (c) 2021 Goldman Sachs and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 */

package org.eclipse.collections.api.bimap;

import java.util.Map;

import org.eclipse.collections.api.bag.ImmutableBagIterable;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.factory.BiMaps;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.ImmutableMapIterable;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.multimap.set.ImmutableSetMultimap;
import org.eclipse.collections.api.ordered.OrderedIterable;
import org.eclipse.collections.api.partition.set.PartitionImmutableSet;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.tuple.Pair;

/**
 * A {@link BiMap} whose contents cannot be altered after initialization.
 *
 * @since 4.2
 */
public interface ImmutableBiMap extends BiMap, ImmutableMapIterable
{
    @Override
    ImmutableBiMap newWithKeyValue(K key, V value);

    @Override
    ImmutableBiMap newWithAllKeyValues(Iterable> keyValues);

    @Override
    ImmutableBiMap newWithMap(Map map);

    @Override
    ImmutableBiMap newWithMapIterable(MapIterable mapIterable);

    @Override
    ImmutableBiMap newWithAllKeyValueArguments(Pair... keyValuePairs);

    @Override
    ImmutableBiMap newWithoutKey(K key);

    @Override
    ImmutableBiMap newWithoutAllKeys(Iterable keys);

    @Override
    ImmutableBiMap inverse();

    @Override
    ImmutableSetMultimap flip();

    @Override
    ImmutableBiMap flipUniqueValues();

    @Override
    ImmutableBiMap tap(Procedure procedure);

    @Override
    ImmutableBiMap select(Predicate2 predicate);

    @Override
    ImmutableBiMap reject(Predicate2 predicate);

    @Override
     ImmutableBiMap collect(Function2> function);

    @Override
     ImmutableBiMap collectValues(Function2 function);

    @Override
    ImmutableSet select(Predicate predicate);

    @Override
    

ImmutableSet selectWith(Predicate2 predicate, P parameter); @Override ImmutableSet reject(Predicate predicate); @Override

ImmutableSet rejectWith(Predicate2 predicate, P parameter); @Override PartitionImmutableSet partition(Predicate predicate); @Override

PartitionImmutableSet partitionWith(Predicate2 predicate, P parameter); @Override ImmutableSet selectInstancesOf(Class clazz); @Override ImmutableBagIterable collect(Function function); @Override ImmutableBagIterable collectWith(Function2 function, P parameter); @Override ImmutableBagIterable collectIf(Predicate predicate, Function function); @Override ImmutableBagIterable flatCollect(Function> function); /** * @since 9.2 */ @Override default ImmutableBagIterable flatCollectWith(Function2> function, P parameter) { return this.flatCollect(each -> function.apply(each, parameter)); } @Override ImmutableSetMultimap groupBy(Function function); @Override ImmutableSetMultimap groupByEach(Function> function); @Override default ImmutableBiMap groupByUniqueKey(Function function) { MutableBiMap target = BiMaps.mutable.empty(); return this.groupByUniqueKey(function, target).toImmutable(); } /** * @since 11.0 */ @Override default ImmutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { MutableMap map = Maps.mutable.empty(); this.forEach(each -> { KK key = groupBy.valueOf(each); VV value = map.getIfAbsentPut(key, zeroValueFactory); mutatingAggregator.value(value, each); }); return map.toImmutable(); } /** * @since 11.0 */ @Override default ImmutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = this.aggregateBy( groupBy, zeroValueFactory, nonMutatingAggregator, Maps.mutable.empty()); return map.toImmutable(); } /** * @since 11.0 */ @Override default ImmutableMap aggregateBy( Function keyFunction, Function valueFunction, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { MutableMap map = Maps.mutable.empty(); this.forEachKeyValue((key, value) -> map.updateValueWith( keyFunction.valueOf(key), zeroValueFactory, nonMutatingAggregator, valueFunction.valueOf(value))); return map.toImmutable(); } /** * @deprecated in 8.0. Use {@link OrderedIterable#zip(Iterable)} instead. */ @Override @Deprecated ImmutableSet> zip(Iterable that); /** * @deprecated in 8.0. Use {@link OrderedIterable#zipWithIndex()} instead. */ @Override @Deprecated ImmutableSet> zipWithIndex(); }