package org.eclipse.collections.impl.map.immutable.primitive;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.primitive.ByteFunction;
import org.eclipse.collections.api.factory.map.primitive.ImmutableObjectByteMapFactory;
import org.eclipse.collections.api.map.primitive.ImmutableObjectByteMap;
import org.eclipse.collections.api.map.primitive.MutableObjectByteMap;
import org.eclipse.collections.api.map.primitive.ObjectByteMap;
import org.eclipse.collections.impl.factory.primitive.ObjectByteMaps;
public enum ImmutableObjectByteMapFactoryImpl implements ImmutableObjectByteMapFactory
{
INSTANCE;
@Override
public <K> ImmutableObjectByteMap<K> empty()
{
return (ImmutableObjectByteMap<K>) ImmutableObjectByteEmptyMap.INSTANCE;
}
@Override
public <K> ImmutableObjectByteMap<K> of()
{
return this.empty();
}
@Override
public <K> ImmutableObjectByteMap<K> with()
{
return this.empty();
}
@Override
public <K> ImmutableObjectByteMap<K> of(K key, byte value)
{
return this.with(key, value);
}
@Override
public <K> ImmutableObjectByteMap<K> with(K key, byte value)
{
return new ImmutableObjectByteSingletonMap<>(key, value);
}
@Override
public <K> ImmutableObjectByteMap<K> ofAll(ObjectByteMap<? extends K> map)
{
return this.withAll(map);
}
@Override
public <K> ImmutableObjectByteMap<K> withAll(ObjectByteMap<? extends K> map)
{
if (map instanceof ImmutableObjectByteMap)
{
return (ImmutableObjectByteMap<K>) map;
}
if (map.isEmpty())
{
return this.with();
}
if (map.size() == 1)
{
final Object[] array = new Object[1];
map.forEachKey((K each) -> array[0] = each);
return new ImmutableObjectByteSingletonMap<>((K) array[0], map.get(array[0]));
}
return new ImmutableObjectByteHashMap<>(map);
}
@Override
public <T, K> ImmutableObjectByteMap<K> from(Iterable<T> iterable, Function<? super T, ? extends K> keyFunction, ByteFunction<? super T> valueFunction)
{
MutableObjectByteMap<K> map = ObjectByteMaps.mutable.from(iterable, keyFunction, valueFunction);
return map.toImmutable();
}
}