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

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

There is a newer version: 1.10.1
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;

/**
 * 
 * @since 1.1.4
 * 
 * @author Haiyang Li
 */
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;
    }

    @SuppressWarnings("unchecked")
    public static  ImmutableBiMap empty() {
        return EMPTY;
    }

    public static  ImmutableBiMap of(final k k1, final v v1) {
        final BiMap biMap = BiMap.of(k1, v1);
        return new ImmutableBiMap(biMap);
    }

    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);
    }

    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);
    }

    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);
    }

    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);
    }

    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);
    }

    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 map the elements in this map are shared by the returned ImmutableBiMap.
     * @return
     */
    public static  ImmutableBiMap of(final BiMap map) {
        if (map == null) {
            return empty();
        }

        return new ImmutableBiMap<>(map);
    }

    public static  ImmutableBiMap copyOf(final BiMap map) {
        if (N.isNullOrEmpty(map)) {
            return empty();
        }

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

    @Deprecated
    public static  ImmutableMap of(final Map map) {
        throw new UnsupportedOperationException();
    }

    @Deprecated
    public static  ImmutableMap copyOf(final Map map) {
        throw new UnsupportedOperationException();
    }

    public K getByValue(Object value) {
        return biMap.getByValue(value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy