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

com.landawn.abacus.util.ImmutableBiMap Maven / Gradle / Ivy

Go to download

A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.

There is a newer version: 5.2.4
Show newest version
/*
 * Copyright (C) 2017 HaiYang Li
 *
 * 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.landawn.abacus.util;

import java.util.Map;

/**
 *
 * @author Haiyang Li
 * @param  the key type
 * @param  the value type
 * @since 1.1.4
 */
@SuppressWarnings("java:S2160")
public final class ImmutableBiMap extends ImmutableMap {

    @SuppressWarnings({ "rawtypes", "unchecked" })
    private static final ImmutableBiMap EMPTY = new ImmutableBiMap(new BiMap<>());

    private final BiMap biMap;

    @SuppressWarnings("unchecked")
    ImmutableBiMap(final BiMap map) {
        super(map);
        this.biMap = (BiMap) map;
    }

    /**
     *
     * @param  the key type
     * @param  the value type
     * @return
     */
    @SuppressWarnings("unchecked")
    public static  ImmutableBiMap empty() {
        return EMPTY;
    }

    /**
     * 
     *
     * @param  the key type
     * @param  the value type
     * @param k1 
     * @param v1 
     * @return 
     */
    public static  ImmutableBiMap of(final K k1, final V v1) {
        final BiMap biMap = BiMap.of(k1, v1);
        return new ImmutableBiMap<>(biMap);
    }

    /**
     * 
     *
     * @param  the key type
     * @param  the value type
     * @param k1 
     * @param v1 
     * @param k2 
     * @param v2 
     * @return 
     */
    public static  ImmutableBiMap of(final K k1, final V v1, final K k2, final V v2) {
        final BiMap biMap = BiMap.of(k1, v1, k2, v2);
        return new ImmutableBiMap<>(biMap);
    }

    /**
     * 
     *
     * @param  the key type
     * @param  the value type
     * @param k1 
     * @param v1 
     * @param k2 
     * @param v2 
     * @param k3 
     * @param v3 
     * @return 
     */
    public static  ImmutableBiMap of(final K k1, final V v1, final K k2, final V v2, final K k3, final V v3) {
        final BiMap biMap = BiMap.of(k1, v1, k2, v2, k3, v3);
        return new ImmutableBiMap<>(biMap);
    }

    /**
     * 
     *
     * @param  the key type
     * @param  the value type
     * @param k1 
     * @param v1 
     * @param k2 
     * @param v2 
     * @param k3 
     * @param v3 
     * @param k4 
     * @param v4 
     * @return 
     */
    public static  ImmutableBiMap of(final K k1, final V v1, final K k2, final V v2, final K k3, final V v3, final K k4, final V v4) {
        final BiMap biMap = BiMap.of(k1, v1, k2, v2, k3, v3, k4, v4);
        return new ImmutableBiMap<>(biMap);
    }

    /**
     * 
     *
     * @param  the key type
     * @param  the value type
     * @param k1 
     * @param v1 
     * @param k2 
     * @param v2 
     * @param k3 
     * @param v3 
     * @param k4 
     * @param v4 
     * @param k5 
     * @param v5 
     * @return 
     */
    public static  ImmutableBiMap of(final K k1, final V v1, final K k2, final V v2, final K k3, final V v3, final K k4, final V v4, final K k5,
            final V v5) {
        final BiMap biMap = BiMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5);
        return new ImmutableBiMap<>(biMap);
    }

    /**
     * 
     *
     * @param  the key type
     * @param  the value type
     * @param k1 
     * @param v1 
     * @param k2 
     * @param v2 
     * @param k3 
     * @param v3 
     * @param k4 
     * @param v4 
     * @param k5 
     * @param v5 
     * @param k6 
     * @param v6 
     * @return 
     */
    public static  ImmutableBiMap of(final K k1, final V v1, final K k2, final V v2, final K k3, final V v3, final K k4, final V v4, final K k5,
            final V v5, final K k6, final V v6) {
        final BiMap biMap = BiMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6);
        return new ImmutableBiMap<>(biMap);
    }

    /**
     * 
     *
     * @param  the key type
     * @param  the value type
     * @param k1 
     * @param v1 
     * @param k2 
     * @param v2 
     * @param k3 
     * @param v3 
     * @param k4 
     * @param v4 
     * @param k5 
     * @param v5 
     * @param k6 
     * @param v6 
     * @param k7 
     * @param v7 
     * @return 
     */
    public static  ImmutableBiMap of(final K k1, final V v1, final K k2, final V v2, final K k3, final V v3, final K k4, final V v4, final K k5,
            final V v5, final K k6, final V v6, final K k7, final V v7) {
        final BiMap biMap = BiMap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7);
        return new ImmutableBiMap<>(biMap);
    }

    /**
     *
     * @param  the key type
     * @param  the value type
     * @param map
     * @return
     */
    public static  ImmutableBiMap copyOf(final BiMap map) {
        if (N.isNullOrEmpty(map)) {
            return empty();
        }

        return new ImmutableBiMap<>(map.copy());
    }

    /**
     * 
     *
     * @param  the key type
     * @param  the value type
     * @param map 
     * @return 
     * @throws UnsupportedOperationException 
     * @deprecated throws {@code UnsupportedOperationException}
     */
    @Deprecated
    public static  ImmutableMap copyOf(final Map map) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    /**
     *
     * @param  the key type
     * @param  the value type
     * @param map
     * @return an {@code ImmutableBiMap} backed by the specified {@code map}
     * @deprecated the ImmutableBiMap may be modified through the specified {@code map}
     */
    @Deprecated
    public static  ImmutableBiMap wrap(final BiMap map) {
        if (map == null) {
            return empty();
        }

        return new ImmutableBiMap<>(map);
    }

    /**
     * 
     *
     * @param  the key type
     * @param  the value type
     * @param map 
     * @return 
     * @throws UnsupportedOperationException 
     * @deprecated throws {@code UnsupportedOperationException}
     */
    @Deprecated
    public static  ImmutableMap wrap(final Map map) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    /**
     * Gets the by value.
     *
     * @param value
     * @return
     */
    public K getByValue(Object value) {
        return biMap.getByValue(value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy