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

VCollections.src.org.violetlib.collections.impl.Impl Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2023 Alan Snyder.
 * All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the license agreement. For details see
 * accompanying license terms.
 */

package org.violetlib.collections.impl;

import java.util.Comparator;
import java.util.Map;

import org.violetlib.collections.*;

import org.jetbrains.annotations.*;
import org.violetlib.annotations.NoInstances;

/**

*/

public final @NoInstances class Impl
{
    private Impl()
    {
        throw new AssertionError("Impl may not be instantiated");
    }

    public static  @NotNull IList getEmptyList()
    {
        return EmptyListImpl.empty();
    }

    public static  @NotNull IList getIndexableEmptyList()
    {
        return SimpleList.EMPTY;
    }

    public static  @NotNull ICollection concatenate(@NotNull IList> sources)
    {
        return ICollectionSequence.create(sources);
    }

    public static  @NotNull ISet getEmptySet()
    {
        return SimpleSet.empty();
    }

    public static  @NotNull ISet createSet(@NotNull Iterable values)
      throws IllegalArgumentException
    {
        return SimpleSet.collect(values);
    }

    public static  @NotNull IIterator concatenateIterators(@NotNull IList> sources)
    {
        return SimpleCompositeIterator.create(IList.cast(sources));
    }

    @SafeVarargs
    public static  @NotNull ISet setOf(@NotNull V... elements)
      throws IllegalArgumentException
    {
        return SimpleSet.create(elements);
    }

    public static  @NotNull SetBuilder getSetBuilder()
    {
        return SetBuilderImpl.create();
    }

    public static  @NotNull SetBuilder getOrderedSetBuilder()
    {
        return OrderedSetBuilderImpl.create();
    }

    public static @NotNull Comparator getUniversalComparator()
    {
        return UniversalComparator.get();
    }

    public static  @NotNull IMap createSingletonMap(@NotNull K key, @NotNull V value)
    {
        return SingletonMap.create(key, value);
    }

    public static  @NotNull IMap createMap(@NotNull Map map)
    {
        if (map.isEmpty()) {
            return EmptyMap.get();
        }

        int count = map.size();
        if (count < 8) {
            return ArrayMapImpl.create(map);
        }

        return HashMapImpl.create(map);
    }

    public static  @NotNull IMap createWeakMap(@NotNull Map map)
    {
        return WeakMap.from(map);
    }

    public static  @NotNull MapBuilder getMapBuilder()
    {
        return MapBuilderImpl.create();
    }

    public static  @NotNull MapBuilder getOrderedMapBuilder()
    {
        return OrderedMapBuilder.create();
    }

    public static  @NotNull UnorderedMapListBuilder getMapListBuilder()
    {
        return MapListBuilderImpl.create();
    }

    public static  @NotNull MapListBuilder getOrderedMapListBuilder()
    {
        return OrderedMapListBuilderImpl.create();
    }

    public static  @NotNull MapSetBuilder getMapSetBuilder()
    {
        return MapSetBuilderImpl.create(false);
    }

    public static  @NotNull MapSetBuilder getMapOrderedSetBuilder()
    {
        return MapSetBuilderImpl.create(true);
    }
}