Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.gs.collections.impl.bag.immutable.ImmutableEmptyBag Maven / Gradle / Ivy
Go to download
GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map
implementations with a rich API and set of utility classes that work with any JDK compatible Collections,
Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework.
/*
* Copyright 2014 Goldman Sachs.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gs.collections.impl.bag.immutable;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.RichIterable;
import com.gs.collections.api.bag.Bag;
import com.gs.collections.api.bag.ImmutableBag;
import com.gs.collections.api.bag.MutableBag;
import com.gs.collections.api.bag.primitive.ImmutableBooleanBag;
import com.gs.collections.api.bag.primitive.ImmutableByteBag;
import com.gs.collections.api.bag.primitive.ImmutableCharBag;
import com.gs.collections.api.bag.primitive.ImmutableDoubleBag;
import com.gs.collections.api.bag.primitive.ImmutableFloatBag;
import com.gs.collections.api.bag.primitive.ImmutableIntBag;
import com.gs.collections.api.bag.primitive.ImmutableLongBag;
import com.gs.collections.api.bag.primitive.ImmutableShortBag;
import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function0;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.function.primitive.BooleanFunction;
import com.gs.collections.api.block.function.primitive.ByteFunction;
import com.gs.collections.api.block.function.primitive.CharFunction;
import com.gs.collections.api.block.function.primitive.DoubleFunction;
import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction;
import com.gs.collections.api.block.function.primitive.FloatFunction;
import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction;
import com.gs.collections.api.block.function.primitive.ShortFunction;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.predicate.primitive.IntPredicate;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure;
import com.gs.collections.api.collection.primitive.MutableBooleanCollection;
import com.gs.collections.api.collection.primitive.MutableByteCollection;
import com.gs.collections.api.collection.primitive.MutableCharCollection;
import com.gs.collections.api.collection.primitive.MutableDoubleCollection;
import com.gs.collections.api.collection.primitive.MutableFloatCollection;
import com.gs.collections.api.collection.primitive.MutableIntCollection;
import com.gs.collections.api.collection.primitive.MutableLongCollection;
import com.gs.collections.api.collection.primitive.MutableShortCollection;
import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.map.ImmutableMap;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.api.map.sorted.MutableSortedMap;
import com.gs.collections.api.multimap.MutableMultimap;
import com.gs.collections.api.multimap.bag.ImmutableBagMultimap;
import com.gs.collections.api.partition.bag.PartitionImmutableBag;
import com.gs.collections.api.set.ImmutableSet;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.set.sorted.MutableSortedSet;
import com.gs.collections.api.stack.MutableStack;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.impl.EmptyIterator;
import com.gs.collections.impl.bag.mutable.HashBag;
import com.gs.collections.impl.block.factory.Comparators;
import com.gs.collections.impl.factory.Bags;
import com.gs.collections.impl.factory.Lists;
import com.gs.collections.impl.factory.Maps;
import com.gs.collections.impl.factory.Sets;
import com.gs.collections.impl.factory.Stacks;
import com.gs.collections.impl.factory.primitive.BooleanBags;
import com.gs.collections.impl.factory.primitive.ByteBags;
import com.gs.collections.impl.factory.primitive.CharBags;
import com.gs.collections.impl.factory.primitive.DoubleBags;
import com.gs.collections.impl.factory.primitive.FloatBags;
import com.gs.collections.impl.factory.primitive.IntBags;
import com.gs.collections.impl.factory.primitive.LongBags;
import com.gs.collections.impl.factory.primitive.ShortBags;
import com.gs.collections.impl.map.mutable.UnifiedMap;
import com.gs.collections.impl.map.sorted.mutable.TreeSortedMap;
import com.gs.collections.impl.multimap.bag.HashBagMultimap;
import com.gs.collections.impl.partition.bag.PartitionHashBag;
import com.gs.collections.impl.set.mutable.UnifiedSet;
import com.gs.collections.impl.set.sorted.mutable.TreeSortedSet;
import com.gs.collections.impl.utility.ArrayIterate;
import com.gs.collections.impl.utility.Iterate;
import com.gs.collections.impl.utility.LazyIterate;
import net.jcip.annotations.Immutable;
/**
* This is a zero element {@link ImmutableBag} which is created by calling the Bags.immutable.of().
*
* @since 1.0
*/
@Immutable
final class ImmutableEmptyBag
implements ImmutableBag, Serializable
{
static final ImmutableBag> INSTANCE = new ImmutableEmptyBag();
private static final long serialVersionUID = 1L;
private static final LazyIterable> LAZY_ITERABLE = LazyIterate.adapt(INSTANCE);
private static final Object[] TO_ARRAY = new Object[0];
private static final PartitionImmutableBag IMMUTABLE_EMPTY_PARTITION = new PartitionHashBag().toImmutable();
@Override
public boolean equals(Object obj)
{
if (obj == this)
{
return true;
}
return obj instanceof Bag && ((Bag>) obj).isEmpty();
}
public int sizeDistinct()
{
return 0;
}
public String toStringOfItemToCount()
{
return "";
}
public int occurrencesOf(Object item)
{
return 0;
}
public void forEachWithOccurrences(ObjectIntProcedure super T> objectIntProcedure)
{
}
public MutableMap toMapOfItemToCount()
{
return Maps.mutable.of();
}
public ImmutableBag toImmutable()
{
return this;
}
@Override
public int hashCode()
{
return 0;
}
public int size()
{
return 0;
}
public boolean isEmpty()
{
return true;
}
public boolean notEmpty()
{
return false;
}
public boolean contains(Object object)
{
return false;
}
public boolean containsAll(Collection> source)
{
return this.containsAllIterable(source);
}
public boolean containsAllIterable(Iterable> source)
{
return Iterate.isEmpty(source);
}
public boolean containsAllArguments(Object... elements)
{
return ArrayIterate.isEmpty(elements);
}
public void forEach(Procedure super T> procedure)
{
}
public void forEachWithIndex(ObjectIntProcedure super T> objectIntProcedure)
{
}
public void forEachWith(Procedure2 super T, ? super P> procedure, P parameter)
{
}
public T getFirst()
{
return null;
}
public T getLast()
{
return null;
}
public Iterator iterator()
{
return EmptyIterator.getInstance();
}
public ImmutableBag newWith(T element)
{
return Bags.immutable.of(element);
}
public ImmutableBag newWithout(T element)
{
return this;
}
public ImmutableBag newWithAll(Iterable extends T> elements)
{
return HashBag.newBag(elements).toImmutable();
}
public ImmutableBag newWithoutAll(Iterable extends T> elements)
{
return this;
}
public ImmutableBag selectByOccurrences(IntPredicate predicate)
{
return this;
}
public ImmutableBag select(Predicate super T> predicate)
{
return this;
}
public > R select(Predicate super T> predicate, R target)
{
return target;
}
public ImmutableBag selectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this;
}
public > R selectWith(
Predicate2 super T, ? super P> predicate, P parameter, R targetCollection)
{
return targetCollection;
}
public ImmutableBag reject(Predicate super T> predicate)
{
return this;
}
public > R reject(Predicate super T> predicate, R target)
{
return target;
}
public ImmutableBag rejectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return this;
}
public > R rejectWith(
Predicate2 super T, ? super P> predicate, P parameter, R targetCollection)
{
return targetCollection;
}
public PartitionImmutableBag partition(Predicate super T> predicate)
{
return (PartitionImmutableBag) IMMUTABLE_EMPTY_PARTITION;
}
public PartitionImmutableBag partitionWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return (PartitionImmutableBag) IMMUTABLE_EMPTY_PARTITION;
}
public ImmutableBag selectInstancesOf(Class clazz)
{
return (ImmutableBag) INSTANCE;
}
public ImmutableBag collect(Function super T, ? extends V> function)
{
return (ImmutableBag) INSTANCE;
}
public ImmutableBooleanBag collectBoolean(BooleanFunction super T> booleanFunction)
{
return BooleanBags.immutable.of();
}
public R collectBoolean(BooleanFunction super T> booleanFunction, R target)
{
return target;
}
public ImmutableByteBag collectByte(ByteFunction super T> byteFunction)
{
return ByteBags.immutable.of();
}
public R collectByte(ByteFunction super T> byteFunction, R target)
{
return target;
}
public ImmutableCharBag collectChar(CharFunction super T> charFunction)
{
return CharBags.immutable.of();
}
public R collectChar(CharFunction super T> charFunction, R target)
{
return target;
}
public ImmutableDoubleBag collectDouble(DoubleFunction super T> doubleFunction)
{
return DoubleBags.immutable.of();
}
public R collectDouble(DoubleFunction super T> doubleFunction, R target)
{
return target;
}
public ImmutableFloatBag collectFloat(FloatFunction super T> floatFunction)
{
return FloatBags.immutable.of();
}
public R collectFloat(FloatFunction super T> floatFunction, R target)
{
return target;
}
public ImmutableIntBag collectInt(IntFunction super T> intFunction)
{
return IntBags.immutable.of();
}
public R collectInt(IntFunction super T> intFunction, R target)
{
return target;
}
public ImmutableLongBag collectLong(LongFunction super T> longFunction)
{
return LongBags.immutable.of();
}
public R collectLong(LongFunction super T> longFunction, R target)
{
return target;
}
public ImmutableShortBag collectShort(ShortFunction super T> shortFunction)
{
return ShortBags.immutable.of();
}
public R collectShort(ShortFunction super T> shortFunction, R target)
{
return target;
}
public > R collect(Function super T, ? extends V> function, R target)
{
return target;
}
public ImmutableBag collectWith(Function2 super T, ? super P, ? extends V> function, P parameter)
{
return (ImmutableBag) INSTANCE;
}
public > R collectWith(
Function2 super T, ? super P, ? extends V> function, P parameter, R targetCollection)
{
return targetCollection;
}
public ImmutableBag collectIf(
Predicate super T> predicate,
Function super T, ? extends V> function)
{
return (ImmutableBag) INSTANCE;
}
public > R collectIf(
Predicate super T> predicate,
Function super T, ? extends V> function,
R target)
{
return target;
}
public ImmutableBag flatCollect(Function super T, ? extends Iterable> function)
{
return (ImmutableBag) INSTANCE;
}
public > R flatCollect(
Function super T, ? extends Iterable> function,
R target)
{
return target;
}
public ImmutableBagMultimap groupBy(Function super T, ? extends V> function)
{
// TODO: Create a Singleton ImmutableEmptyBagMultimap for efficiency
return HashBagMultimap.newMultimap().toImmutable();
}
public ImmutableBagMultimap groupByEach(Function super T, ? extends Iterable> function)
{
// TODO: Create a Singleton ImmutableEmptyBagMultimap for efficiency
return HashBagMultimap.newMultimap().toImmutable();
}
public > R groupBy(
Function super T, ? extends V> function, R target)
{
return target;
}
public > R groupByEach(
Function super T, ? extends Iterable> function, R target)
{
return target;
}
public ImmutableMap groupByUniqueKey(Function super T, ? extends V> function)
{
throw new UnsupportedOperationException(this.getClass().getSimpleName() + ".groupByUniqueKey() not implemented yet");
}
public T detect(Predicate super T> predicate)
{
return null;
}
public T detectWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return null;
}
public T detectIfNone(Predicate super T> predicate, Function0 extends T> function)
{
return function.value();
}
public
T detectWithIfNone(Predicate2 super T, ? super P> predicate, P parameter, Function0 extends T> function)
{
return function.value();
}
public int count(Predicate super T> predicate)
{
return 0;
}
public
int countWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return 0;
}
public boolean anySatisfy(Predicate super T> predicate)
{
return false;
}
public boolean allSatisfy(Predicate super T> predicate)
{
return true;
}
public boolean noneSatisfy(Predicate super T> predicate)
{
return true;
}
public
boolean anySatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return false;
}
public
boolean allSatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return true;
}
public
boolean noneSatisfyWith(Predicate2 super T, ? super P> predicate, P parameter)
{
return true;
}
public IV injectInto(IV injectedValue, Function2 super IV, ? super T, ? extends IV> function)
{
return injectedValue;
}
public int injectInto(int injectedValue, IntObjectToIntFunction super T> function)
{
return injectedValue;
}
public long injectInto(long injectedValue, LongObjectToLongFunction super T> function)
{
return injectedValue;
}
public double injectInto(double injectedValue, DoubleObjectToDoubleFunction super T> function)
{
return injectedValue;
}
public float injectInto(float injectedValue, FloatObjectToFloatFunction super T> function)
{
return injectedValue;
}
public long sumOfInt(IntFunction super T> function)
{
return 0;
}
public double sumOfFloat(FloatFunction super T> function)
{
return 0.0F;
}
public long sumOfLong(LongFunction super T> function)
{
return 0L;
}
public double sumOfDouble(DoubleFunction super T> function)
{
return 0.0d;
}
public MutableList toList()
{
return Lists.mutable.of();
}
public MutableList toSortedList()
{
return Lists.mutable.of();
}
public MutableList toSortedList(Comparator super T> comparator)
{
return Lists.mutable.of();
}
public > MutableList toSortedListBy(Function super T, ? extends V> function)
{
return Lists.mutable.of();
}
public MutableSortedSet toSortedSet()
{
return TreeSortedSet.newSet();
}
public MutableSortedSet toSortedSet(Comparator super T> comparator)
{
return TreeSortedSet.newSet(comparator);
}
public > MutableSortedSet toSortedSetBy(Function super T, ? extends V> function)
{
return TreeSortedSet.newSet(Comparators.byFunction(function));
}
public MutableSet toSet()
{
return UnifiedSet.newSet();
}
public MutableBag toBag()
{
return Bags.mutable.of();
}
public MutableStack toStack()
{
return Stacks.mutable.of();
}
public MutableMap toMap(
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
return UnifiedMap.newMap();
}
public MutableSortedMap toSortedMap(
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
return TreeSortedMap.newMap();
}
public MutableSortedMap toSortedMap(Comparator super NK> comparator,
Function super T, ? extends NK> keyFunction,
Function super T, ? extends NV> valueFunction)
{
return TreeSortedMap.newMap(comparator);
}
public LazyIterable asLazy()
{
return (LazyIterable) LAZY_ITERABLE;
}
public Object[] toArray()
{
return TO_ARRAY;
}
public T[] toArray(T[] a)
{
if (a.length > 0)
{
a[0] = null;
}
return a;
}
public T min(Comparator super T> comparator)
{
throw new NoSuchElementException();
}
public T max(Comparator super T> comparator)
{
throw new NoSuchElementException();
}
public T min()
{
throw new NoSuchElementException();
}
public T max()
{
throw new NoSuchElementException();
}
public > T minBy(Function super T, ? extends V> function)
{
throw new NoSuchElementException();
}
public > T maxBy(Function super T, ? extends V> function)
{
throw new NoSuchElementException();
}
@Override
public String toString()
{
return "[]";
}
public String makeString()
{
return "";
}
public String makeString(String separator)
{
return "";
}
public String makeString(String start, String separator, String end)
{
return start + end;
}
public void appendString(Appendable appendable)
{
}
public void appendString(Appendable appendable, String separator)
{
}
public void appendString(Appendable appendable, String start, String separator, String end)
{
try
{
appendable.append(start);
appendable.append(end);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
public ImmutableBag> zip(Iterable that)
{
return Bags.immutable.of();
}
public >> R zip(Iterable that, R target)
{
return target;
}
public ImmutableSet> zipWithIndex()
{
return Sets.immutable.of();
}
public >> R zipWithIndex(R target)
{
return target;
}
public RichIterable> chunk(int size)
{
if (size <= 0)
{
throw new IllegalArgumentException("Size for groups must be positive but was: " + size);
}
return Bags.immutable.of();
}
private Object writeReplace()
{
return new ImmutableBagSerializationProxy(this);
}
public ImmutableMap aggregateInPlaceBy(
Function super T, ? extends K> groupBy,
Function0 extends V> zeroValueFactory,
Procedure2 super V, ? super T> mutatingAggregator)
{
return Maps.immutable.of();
}
public ImmutableMap aggregateBy(
Function super T, ? extends K> groupBy,
Function0 extends V> zeroValueFactory,
Function2 super V, ? super T, ? extends V> nonMutatingAggregator)
{
return Maps.immutable.of();
}
}