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

org.eclipse.collections.impl.bag.immutable.ImmutableHashBag Maven / Gradle / Ivy

Go to download

Builds the commons-text. Requires eclipse-collections-api be built first and be excluded from any other poms requiring it.

There is a newer version: 11.1.0-r13
Show newest version
/*
 * Copyright (c) 2022 Goldman Sachs and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 */

package org.eclipse.collections.impl.bag.immutable;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;

import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.bag.ImmutableBag;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.bag.sorted.MutableSortedBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.primitive.DoubleObjectToDoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatObjectToFloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntObjectToIntFunction;
import org.eclipse.collections.api.block.function.primitive.LongObjectToLongFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.predicate.primitive.IntPredicate;
import org.eclipse.collections.api.block.predicate.primitive.ObjectIntPredicate;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.sorted.MutableSortedMap;
import org.eclipse.collections.api.multimap.MutableMultimap;
import org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.ordered.OrderedIterable;
import org.eclipse.collections.api.partition.bag.PartitionImmutableBag;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.set.sorted.MutableSortedSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.UnmodifiableIteratorAdapter;
import org.eclipse.collections.impl.bag.mutable.HashBag;
import org.eclipse.collections.impl.utility.Iterate;

/**
 * @since 1.0
 */
public class ImmutableHashBag
        extends AbstractImmutableBag
        implements Serializable
{
    private static final long serialVersionUID = 1L;

    private final MutableBag delegate;

    public ImmutableHashBag()
    {
        this.delegate = Bags.mutable.empty();
    }

    public ImmutableHashBag(Iterable source)
    {
        this.delegate = Bags.mutable.withAll(source);
    }

    public ImmutableHashBag(Bag source)
    {
        this.delegate = Bags.mutable.withAll(source);
    }

    public static  ImmutableHashBag newBag()
    {
        return new ImmutableHashBag<>();
    }

    public static  ImmutableHashBag newBag(Iterable source)
    {
        return new ImmutableHashBag<>(source);
    }

    public static  ImmutableHashBag newBagWith(T... elements)
    {
        return ImmutableHashBag.newBag(Arrays.asList(elements));
    }

    public static  ImmutableHashBag newBagWith(Bag bag)
    {
        return new ImmutableHashBag<>(bag);
    }

    @Override
    public ImmutableBag newWith(T element)
    {
        return Bags.mutable.withAll(this.delegate).with(element).toImmutable();
    }

    @Override
    public ImmutableBag newWithout(T element)
    {
        HashBag hashBag = HashBag.newBag(this.delegate);
        hashBag.remove(element);
        return hashBag.toImmutable();
    }

    @Override
    public ImmutableBag newWithAll(Iterable elements)
    {
        return Iterate.addAllTo(elements, Bags.mutable.withAll(this.delegate)).toImmutable();
    }

    @Override
    public int size()
    {
        return this.delegate.size();
    }

    @Override
    public  ImmutableBagMultimap groupBy(Function function)
    {
        MutableBagMultimap bagMultimap = this.delegate.groupBy(function);
        return bagMultimap.toImmutable();
    }

    @Override
    public > R groupBy(
            Function function,
            R target)
    {
        return this.delegate.groupBy(function, target);
    }

    @Override
    public  ImmutableBagMultimap groupByEach(Function> function)
    {
        return this.delegate.groupByEach(function).toImmutable();
    }

    @Override
    public > R groupByEach(
            Function> function,
            R target)
    {
        return this.delegate.groupByEach(function, target);
    }

    @Override
    public  ImmutableMap groupByUniqueKey(Function function)
    {
        MutableMap map = this.delegate.groupByUniqueKey(function);
        return map.toImmutable();
    }

    @Override
    public boolean isEmpty()
    {
        return this.delegate.isEmpty();
    }

    @Override
    public boolean notEmpty()
    {
        return this.delegate.notEmpty();
    }

    @Override
    public T getFirst()
    {
        return this.delegate.getFirst();
    }

    @Override
    public T getLast()
    {
        return this.delegate.getLast();
    }

    @Override
    public T getOnly()
    {
        return this.delegate.getOnly();
    }

    @Override
    public T min(Comparator comparator)
    {
        return this.delegate.min(comparator);
    }

    @Override
    public T max(Comparator comparator)
    {
        return this.delegate.max(comparator);
    }

    @Override
    public T min()
    {
        return this.delegate.min();
    }

    @Override
    public T max()
    {
        return this.delegate.max();
    }

    @Override
    public > T minBy(Function function)
    {
        return this.delegate.minBy(function);
    }

    @Override
    public > T maxBy(Function function)
    {
        return this.delegate.maxBy(function);
    }

    @Override
    public boolean contains(Object object)
    {
        return this.delegate.contains(object);
    }

    @Override
    public boolean containsAllIterable(Iterable source)
    {
        return this.delegate.containsAllIterable(source);
    }

    @Override
    public boolean containsAllArguments(Object... elements)
    {
        return this.delegate.containsAllArguments(elements);
    }

    @Override
    public  MutableMap toMap(
            Function keyFunction,
            Function valueFunction)
    {
        return this.delegate.toMap(keyFunction, valueFunction);
    }

    @Override
    public > R toMap(
            Function keyFunction,
            Function valueFunction,
            R target)
    {
        return this.delegate.toMap(keyFunction, valueFunction, target);
    }

    @Override
    public void each(Procedure procedure)
    {
        this.delegate.forEach(procedure);
    }

    @Override
    public void forEachWithIndex(ObjectIntProcedure objectIntProcedure)
    {
        this.delegate.forEachWithIndex(objectIntProcedure);
    }

    @Override
    public  ImmutableBag selectInstancesOf(Class clazz)
    {
        return this.delegate.selectInstancesOf(clazz).toImmutable();
    }

    @Override
    public ImmutableBag selectByOccurrences(IntPredicate predicate)
    {
        return this.delegate.selectByOccurrences(predicate).toImmutable();
    }

    @Override
    public boolean anySatisfyWithOccurrences(ObjectIntPredicate predicate)
    {
        return this.delegate.anySatisfyWithOccurrences(predicate);
    }

    @Override
    public boolean allSatisfyWithOccurrences(ObjectIntPredicate predicate)
    {
        return this.delegate.allSatisfyWithOccurrences(predicate);
    }

    @Override
    public boolean noneSatisfyWithOccurrences(ObjectIntPredicate predicate)
    {
        return this.delegate.noneSatisfyWithOccurrences(predicate);
    }

    @Override
    public T detectWithOccurrences(ObjectIntPredicate predicate)
    {
        return this.delegate.detectWithOccurrences(predicate);
    }

    @Override
    public void forEachWithOccurrences(ObjectIntProcedure objectIntProcedure)
    {
        this.delegate.forEachWithOccurrences(objectIntProcedure);
    }

    @Override
    public int sizeDistinct()
    {
        return this.delegate.sizeDistinct();
    }

    @Override
    public int occurrencesOf(Object item)
    {
        return this.delegate.occurrencesOf(item);
    }

    @Override
    public MutableList toList()
    {
        return this.delegate.toList();
    }

    @Override
    public MutableList toSortedList()
    {
        return this.delegate.toSortedList();
    }

    @Override
    public MutableList toSortedList(Comparator comparator)
    {
        return this.delegate.toSortedList(comparator);
    }

    @Override
    public MutableSortedSet toSortedSet()
    {
        return this.delegate.toSortedSet();
    }

    @Override
    public MutableSortedSet toSortedSet(Comparator comparator)
    {
        return this.delegate.toSortedSet(comparator);
    }

    @Override
    public  MutableSortedMap toSortedMap(Function keyFunction, Function valueFunction)
    {
        return this.delegate.toSortedMap(keyFunction, valueFunction);
    }

    @Override
    public  MutableSortedMap toSortedMap(Comparator comparator, Function keyFunction, Function valueFunction)
    {
        return this.delegate.toSortedMap(comparator, keyFunction, valueFunction);
    }

    @Override
    public ImmutableBag select(Predicate predicate)
    {
        return this.delegate.select(predicate).toImmutable();
    }

    @Override
    public > R select(Predicate predicate, R target)
    {
        return this.delegate.select(predicate, target);
    }

    @Override
    public ImmutableBag reject(Predicate predicate)
    {
        return this.delegate.reject(predicate).toImmutable();
    }

    @Override
    public > R reject(Predicate predicate, R target)
    {
        return this.delegate.reject(predicate, target);
    }

    @Override
    public PartitionImmutableBag partition(Predicate predicate)
    {
        return this.delegate.partition(predicate).toImmutable();
    }

    @Override
    public  ImmutableBag collect(Function function)
    {
        MutableBag bag = this.delegate.collect(function);
        return bag.toImmutable();
    }

    @Override
    public > R collect(Function function, R target)
    {
        return this.delegate.collect(function, target);
    }

    @Override
    public  ImmutableBag collectIf(
            Predicate predicate,
            Function function)
    {
        MutableBag bag = this.delegate.collectIf(predicate, function);
        return bag.toImmutable();
    }

    @Override
    public > R collectIf(
            Predicate predicate,
            Function function,
            R target)
    {
        return this.delegate.collectIf(predicate, function, target);
    }

    @Override
    public  ImmutableBag flatCollect(Function> function)
    {
        return this.delegate.flatCollect(function).toImmutable();
    }

    @Override
    public > R flatCollect(Function> function, R target)
    {
        return this.delegate.flatCollect(function, target);
    }

    @Override
    public T detect(Predicate predicate)
    {
        return this.delegate.detect(predicate);
    }

    @Override
    public 

T detectWith(Predicate2 predicate, P parameter) { return this.delegate.detectWith(predicate, parameter); } @Override public Optional detectOptional(Predicate predicate) { return this.delegate.detectOptional(predicate); } @Override public

Optional detectWithOptional(Predicate2 predicate, P parameter) { return this.delegate.detectWithOptional(predicate, parameter); } @Override public T detectIfNone(Predicate predicate, Function0 function) { return this.delegate.detectIfNone(predicate, function); } @Override public int count(Predicate predicate) { return this.delegate.count(predicate); } @Override public boolean anySatisfy(Predicate predicate) { return this.delegate.anySatisfy(predicate); } @Override public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return this.delegate.anySatisfyWith(predicate, parameter); } @Override public boolean allSatisfy(Predicate predicate) { return this.delegate.allSatisfy(predicate); } @Override public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return this.delegate.allSatisfyWith(predicate, parameter); } @Override public boolean noneSatisfy(Predicate predicate) { return this.delegate.noneSatisfy(predicate); } @Override public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.delegate.noneSatisfyWith(predicate, parameter); } @Override public IV injectInto(IV injectedValue, Function2 function) { return this.delegate.injectInto(injectedValue, function); } @Override public int injectInto(int injectedValue, IntObjectToIntFunction function) { return this.delegate.injectInto(injectedValue, function); } @Override public long injectInto(long injectedValue, LongObjectToLongFunction function) { return this.delegate.injectInto(injectedValue, function); } @Override public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return this.delegate.injectInto(injectedValue, function); } @Override public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return this.delegate.injectInto(injectedValue, function); } @Override public boolean equals(Object obj) { return this.delegate.equals(obj); } @Override public int hashCode() { return this.delegate.hashCode(); } @Override public MutableMap toMapOfItemToCount() { return this.delegate.toMapOfItemToCount(); } @Override public MutableSet toSet() { return this.delegate.toSet(); } @Override public MutableBag toBag() { return this.delegate.toBag(); } @Override public MutableSortedBag toSortedBag() { return this.delegate.toSortedBag(); } @Override public MutableSortedBag toSortedBag(Comparator comparator) { return this.delegate.toSortedBag(comparator); } @Override public LazyIterable asLazy() { return this.delegate.asLazy(); } @Override public Object[] toArray() { return this.delegate.toArray(); } @Override public T[] toArray(T[] a) { return this.delegate.toArray(a); } @Override public String toString() { return this.makeString("[", ", ", "]"); } @Override public String makeString() { return this.delegate.makeString(); } @Override public String makeString(String separator) { return this.delegate.makeString(separator); } @Override public String makeString(String start, String separator, String end) { return this.delegate.makeString(start, separator, end); } @Override public void appendString(Appendable appendable) { this.delegate.appendString(appendable); } @Override public void appendString(Appendable appendable, String separator) { this.delegate.appendString(appendable, separator); } @Override public void appendString(Appendable appendable, String start, String separator, String end) { this.delegate.appendString(appendable, start, separator, end); } /** * @deprecated in 6.0. Use {@link OrderedIterable#zip(Iterable)} instead. */ @Override @Deprecated public ImmutableBag> zip(Iterable that) { return this.delegate.zip(that).toImmutable(); } @Override public >> R zip(Iterable that, R target) { return this.delegate.zip(that, target); } /** * @deprecated in 6.0. Use {@link OrderedIterable#zipWithIndex()} instead. */ @Override @Deprecated public ImmutableSet> zipWithIndex() { return this.delegate.zipWithIndex().toImmutable(); } @Override public >> R zipWithIndex(R target) { return this.delegate.zipWithIndex(target); } @Override public Iterator iterator() { return new UnmodifiableIteratorAdapter<>(this.delegate.iterator()); } protected Object writeReplace() { return new ImmutableBagSerializationProxy<>(this); } @Override public RichIterable distinctView() { return this.delegate.distinctView(); } }