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

ru.yandex.bolts.collection.impl.SingletonMap Maven / Gradle / Ivy

The newest version!
package ru.yandex.bolts.collection.impl;

import java.io.Serializable;

import ru.yandex.bolts.collection.Cf;
import ru.yandex.bolts.collection.SetF;
import ru.yandex.bolts.collection.Unmodifiable;


public class SingletonMap extends AbstractMapF implements Serializable, Unmodifiable {
    private static final long serialVersionUID = 1863420184567712379L;

    private final K key;
    private final V value;

    public SingletonMap(K key, V value) {
        this.key = key;
        this.value = value;
    }

    public SetF> entrySet() {
        return Cf.set(new SimpleEntry<>(key, value));
    }

    @Override
    public V get(Object key) {
        if (this.eq(key, this.key)) return value;
        else return null;
    }

    @Override
    public boolean containsValue(Object value) {
        return this.eq(this.value, value);
    }

    @Override
    public SetF keySet() {
        return Cf.set(key);
    }

    @Override
    public int size() {
        return 1;
    }

} //~




© 2015 - 2024 Weber Informatics LLC | Privacy Policy