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

dev.marksman.collectionviews.EmptySetBuilder Maven / Gradle / Ivy

There is a newer version: 1.2.3
Show newest version
package dev.marksman.collectionviews;

import com.jnape.palatable.lambda.adt.Maybe;
import dev.marksman.enhancediterables.FiniteIterable;
import dev.marksman.enhancediterables.NonEmptyFiniteIterable;

import java.util.Collection;
import java.util.Objects;

import static dev.marksman.collectionviews.ConcreteSetBuilder.concreteSetBuilder;

final class EmptySetBuilder implements SetBuilder {
    private final Maybe initialCapacity;

    private EmptySetBuilder(Maybe initialCapacity) {
        this.initialCapacity = initialCapacity;
    }

    @Override
    public NonEmptySetBuilder add(A element) {
        return concreteSetBuilder(initialCapacity, element);
    }

    @Override
    public SetBuilder addAll(Collection elements) {
        Objects.requireNonNull(elements);
        if (elements.isEmpty()) {
            return this;
        } else {
            return concreteSetBuilder(initialCapacity, elements);
        }
    }

    @Override
    public SetBuilder addAll(FiniteIterable elements) {
        Objects.requireNonNull(elements);
        if (elements.isEmpty()) {
            return this;
        } else {
            return concreteSetBuilder(initialCapacity, elements);
        }
    }

    @Override
    public NonEmptySetBuilder addAll(NonEmptyFiniteIterable elements) {
        Objects.requireNonNull(elements);
        return concreteSetBuilder(initialCapacity, elements);
    }

    @Override
    public ImmutableSet build() {
        return Set.empty();
    }

    static  EmptySetBuilder emptySetBuilder(Maybe initialCapacity) {
        return new EmptySetBuilder<>(initialCapacity.filter(n -> n >= 0));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy