package org.eclipse.collections.impl.map.immutable.primitive;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.factory.map.primitive.ImmutableFloatObjectMapFactory;
import org.eclipse.collections.api.map.primitive.ImmutableFloatObjectMap;
import org.eclipse.collections.api.map.primitive.FloatObjectMap;
import org.eclipse.collections.impl.factory.primitive.FloatObjectMaps;
public enum ImmutableFloatObjectMapFactoryImpl implements ImmutableFloatObjectMapFactory
{
INSTANCE;
@Override
public <V> ImmutableFloatObjectMap<V> empty()
{
return (ImmutableFloatObjectMap<V>) ImmutableFloatObjectEmptyMap.INSTANCE;
}
@Override
public <V> ImmutableFloatObjectMap<V> of()
{
return this.empty();
}
@Override
public <V> ImmutableFloatObjectMap<V> with()
{
return this.empty();
}
@Override
public <V> ImmutableFloatObjectMap<V> of(float key, V value)
{
return this.with(key, value);
}
@Override
public <V> ImmutableFloatObjectMap<V> with(float key, V value)
{
return new ImmutableFloatObjectSingletonMap<>(key, value);
}
@Override
public <V> ImmutableFloatObjectMap<V> ofAll(FloatObjectMap<? extends V> map)
{
return this.withAll(map);
}
@Override
public <V> ImmutableFloatObjectMap<V> withAll(FloatObjectMap<? extends V> map)
{
if (map instanceof ImmutableFloatObjectMap)
{
return (ImmutableFloatObjectMap<V>) map;
}
if (map.isEmpty())
{
return this.with();
}
if (map.size() == 1)
{
final float[] array = new float[1];
map.forEachKey((float each) -> array[0] = each);
return new ImmutableFloatObjectSingletonMap<>(array[0], map.get(array[0]));
}
return new ImmutableFloatObjectHashMap<>(map);
}
@Override
public <T, V> ImmutableFloatObjectMap<V> from(Iterable<T> iterable, FloatFunction<? super T> keyFunction, Function<? super T, ? extends V> valueFunction)
{
FloatObjectMap<V> map = FloatObjectMaps.mutable.from(iterable, keyFunction, valueFunction);
return map.toImmutable();
}
}