ru.yandex.bolts.collection.impl.SingletonMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bolts Show documentation
Show all versions of bolts Show documentation
Collections utilities used in various Yandex projects
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;
}
} //~