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

org.javimmutable.collections.hash.EmptyHashSet Maven / Gradle / Ivy

package org.javimmutable.collections.hash;

import org.javimmutable.collections.JImmutableSet;
import org.javimmutable.collections.SplitableIterator;
import org.javimmutable.collections.common.AbstractJImmutableSet;
import org.javimmutable.collections.common.StreamConstants;
import org.javimmutable.collections.iterators.EmptyIterator;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class EmptyHashSet
    extends AbstractJImmutableSet
    implements Serializable
{
    @SuppressWarnings("rawtypes")
    private static final EmptyHashSet INSTANCE = new EmptyHashSet();

    @SuppressWarnings("unchecked")
    public static  EmptyHashSet instance()
    {
        return (EmptyHashSet)INSTANCE;
    }

    @Override
    protected Set emptyMutableSet()
    {
        return new HashSet<>();
    }

    @Nonnull
    @Override
    public JImmutableSet insert(@Nonnull T value)
    {
        return JImmutableHashSet.of(value);
    }

    @Override
    public boolean contains(@Nullable T value)
    {
        return false;
    }

    @Nonnull
    @Override
    public JImmutableSet delete(T value)
    {
        return this;
    }

    @Nonnull
    @Override
    public JImmutableSet deleteAll(@Nonnull Iterable other)
    {
        return this;
    }

    @Nonnull
    @Override
    public JImmutableSet deleteAll(@Nonnull Iterator other)
    {
        return this;
    }

    @Nonnull
    @Override
    public JImmutableSet union(@Nonnull Iterator values)
    {
        return new HashSetBuilder().add(values).build();
    }

    @Nonnull
    @Override
    public JImmutableSet intersection(@Nonnull Iterable other)
    {
        return this;
    }

    @Nonnull
    @Override
    public JImmutableSet intersection(@Nonnull JImmutableSet other)
    {
        return this;
    }

    @Nonnull
    @Override
    public JImmutableSet intersection(@Nonnull Iterator values)
    {
        return this;
    }

    @Nonnull
    @Override
    public JImmutableSet intersection(@Nonnull Set other)
    {
        return this;
    }

    @Override
    public int size()
    {
        return 0;
    }

    @Override
    public boolean isEmpty()
    {
        return true;
    }

    @Nonnull
    @Override
    public JImmutableSet deleteAll()
    {
        return this;
    }

    @Override
    public void checkInvariants()
    {
    }

    @Nonnull
    @Override
    public SplitableIterator iterator()
    {
        return EmptyIterator.of();
    }

    @Override
    public int getSpliteratorCharacteristics()
    {
        return StreamConstants.SPLITERATOR_UNORDERED;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy