package org.eclipse.collections.impl.map.immutable.primitive;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.factory.map.primitive.ImmutableDoubleObjectMapFactory;
import org.eclipse.collections.api.map.primitive.ImmutableDoubleObjectMap;
import org.eclipse.collections.api.map.primitive.DoubleObjectMap;
import org.eclipse.collections.impl.factory.primitive.DoubleObjectMaps;
public enum ImmutableDoubleObjectMapFactoryImpl implements ImmutableDoubleObjectMapFactory
{
INSTANCE;
@Override
public <V> ImmutableDoubleObjectMap<V> empty()
{
return (ImmutableDoubleObjectMap<V>) ImmutableDoubleObjectEmptyMap.INSTANCE;
}
@Override
public <V> ImmutableDoubleObjectMap<V> of()
{
return this.empty();
}
@Override
public <V> ImmutableDoubleObjectMap<V> with()
{
return this.empty();
}
@Override
public <V> ImmutableDoubleObjectMap<V> of(double key, V value)
{
return this.with(key, value);
}
@Override
public <V> ImmutableDoubleObjectMap<V> with(double key, V value)
{
return new ImmutableDoubleObjectSingletonMap<>(key, value);
}
@Override
public <V> ImmutableDoubleObjectMap<V> ofAll(DoubleObjectMap<? extends V> map)
{
return this.withAll(map);
}
@Override
public <V> ImmutableDoubleObjectMap<V> withAll(DoubleObjectMap<? extends V> map)
{
if (map instanceof ImmutableDoubleObjectMap)
{
return (ImmutableDoubleObjectMap<V>) map;
}
if (map.isEmpty())
{
return this.with();
}
if (map.size() == 1)
{
final double[] array = new double[1];
map.forEachKey((double each) -> array[0] = each);
return new ImmutableDoubleObjectSingletonMap<>(array[0], map.get(array[0]));
}
return new ImmutableDoubleObjectHashMap<>(map);
}
@Override
public <T, V> ImmutableDoubleObjectMap<V> from(Iterable<T> iterable, DoubleFunction<? super T> keyFunction, Function<? super T, ? extends V> valueFunction)
{
DoubleObjectMap<V> map = DoubleObjectMaps.mutable.from(iterable, keyFunction, valueFunction);
return map.toImmutable();
}
}