Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.google.common.collect;
import static com.google.common.collect.CollectPreconditions.checkEntryNotNull;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collector;
/**
* GWT emulation of {@link com.google.common.collect.ImmutableBiMap}.
*
* @author Hayward Chan
*/
public abstract class ImmutableBiMap extends ForwardingImmutableMap
implements BiMap {
public static Collector> toImmutableBiMap(
Function keyFunction,
Function valueFunction) {
return CollectCollectors.toImmutableBiMap(keyFunction, valueFunction);
}
// Casting to any type is safe because the set will never hold any elements.
@SuppressWarnings("unchecked")
public static ImmutableBiMap of() {
return (ImmutableBiMap) RegularImmutableBiMap.EMPTY;
}
public static ImmutableBiMap of(K k1, V v1) {
checkEntryNotNull(k1, v1);
return new SingletonImmutableBiMap(k1, v1);
}
public static ImmutableBiMap of(K k1, V v1, K k2, V v2) {
return new RegularImmutableBiMap(ImmutableMap.of(k1, v1, k2, v2));
}
public static ImmutableBiMap of(K k1, V v1, K k2, V v2, K k3, V v3) {
return new RegularImmutableBiMap(ImmutableMap.of(k1, v1, k2, v2, k3, v3));
}
public static ImmutableBiMap of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
return new RegularImmutableBiMap(ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4));
}
public static ImmutableBiMap of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
return new RegularImmutableBiMap(ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5));
}
public static ImmutableBiMap of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) {
return new RegularImmutableBiMap(
ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6));
}
public static ImmutableBiMap of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) {
return new RegularImmutableBiMap(
ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7));
}
public static ImmutableBiMap of(
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8) {
return new RegularImmutableBiMap(
ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8));
}
public static ImmutableBiMap of(
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9) {
return new RegularImmutableBiMap(
ImmutableMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9));
}
public static ImmutableBiMap of(
K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9,
K k10,
V v10) {
return new RegularImmutableBiMap(
ImmutableMap.of(
k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10));
}
@SafeVarargs
public static ImmutableBiMap ofEntries(Entry... entries) {
return new RegularImmutableBiMap(ImmutableMap.ofEntries(entries));
}
public static Builder builder() {
return new Builder();
}
public static final class Builder extends ImmutableMap.Builder {
public Builder() {}
Builder(int initCapacity) {
super(initCapacity);
}
@Override
public Builder put(K key, V value) {
super.put(key, value);
return this;
}
@Override
public Builder put(Entry entry) {
super.put(entry);
return this;
}
@Override
public Builder putAll(Map map) {
super.putAll(map);
return this;
}
@Override
public Builder putAll(Iterable> entries) {
super.putAll(entries);
return this;
}
public Builder orderEntriesByValue(Comparator valueComparator) {
super.orderEntriesByValue(valueComparator);
return this;
}
Builder combine(Builder other) {
super.combine(other);
return this;
}
@Override
public ImmutableBiMap build() {
return buildOrThrow();
}
@Override
public ImmutableBiMap buildOrThrow() {
ImmutableMap map = super.buildOrThrow();
if (map.isEmpty()) {
return of();
}
return new RegularImmutableBiMap(super.buildOrThrow());
}
@Override
ImmutableBiMap buildJdkBacked() {
return build();
}
}
public static ImmutableBiMap copyOf(Map map) {
if (map instanceof ImmutableBiMap) {
@SuppressWarnings("unchecked") // safe since map is not writable
ImmutableBiMap bimap = (ImmutableBiMap) map;
return bimap;
}
if (map.isEmpty()) {
return of();
}
ImmutableMap immutableMap = ImmutableMap.copyOf(map);
return new RegularImmutableBiMap(immutableMap);
}
public static ImmutableBiMap copyOf(
Iterable> entries) {
return new Builder().putAll(entries).build();
}
ImmutableBiMap(Map delegate) {
super(delegate);
}
public abstract ImmutableBiMap inverse();
@Override
public ImmutableSet values() {
return inverse().keySet();
}
public final V forcePut(K key, V value) {
throw new UnsupportedOperationException();
}
}