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

com.gs.collections.impl.list.immutable.ImmutableEmptyList 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.

There is a newer version: 7.0.3
Show newest version
/*
 * Copyright 2015 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.list.immutable;

import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.RandomAccess;

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.DoubleObjectToDoubleFunction;
import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction;
import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
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.list.ImmutableList;
import com.gs.collections.api.partition.list.PartitionImmutableList;
import com.gs.collections.api.stack.MutableStack;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.impl.factory.Lists;
import com.gs.collections.impl.factory.Stacks;
import com.gs.collections.impl.partition.list.PartitionFastList;
import net.jcip.annotations.Immutable;

/**
 * This is a zero element {@link ImmutableList} which is created by calling the Lists.immutable.empty() method.
 */
@Immutable
final class ImmutableEmptyList
        extends AbstractImmutableList
        implements Serializable, RandomAccess
{
    static final ImmutableList INSTANCE = new ImmutableEmptyList();
    private static final PartitionImmutableList EMPTY = new PartitionFastList().toImmutable();

    private static final long serialVersionUID = 1L;

    private Object readResolve()
    {
        return INSTANCE;
    }

    @Override
    public ImmutableList newWithout(T element)
    {
        return this;
    }

    @Override
    public ImmutableList newWithoutAll(Iterable elements)
    {
        return this;
    }

    public int size()
    {
        return 0;
    }

    @Override
    public boolean contains(Object obj)
    {
        return false;
    }

    public T get(int index)
    {
        throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size());
    }

    @Override
    public ImmutableList tap(Procedure procedure)
    {
        return this;
    }

    public void each(Procedure procedure)
    {
    }

    @Override
    public void reverseForEach(Procedure procedure)
    {
    }

    @Override
    public void forEachWithIndex(ObjectIntProcedure objectIntProcedure)
    {
    }

    @Override
    public 

void forEachWith(Procedure2 procedure, P parameter) { } public ImmutableList newWith(T newItem) { return Lists.immutable.with(newItem); } @Override public T min(Comparator comparator) { throw new NoSuchElementException(); } @Override public T max(Comparator comparator) { throw new NoSuchElementException(); } @Override public T min() { throw new NoSuchElementException(); } @Override public T max() { throw new NoSuchElementException(); } @Override public > T minBy(Function function) { throw new NoSuchElementException(); } @Override public > T maxBy(Function function) { throw new NoSuchElementException(); } @Override public ImmutableList> zip(Iterable that) { return Lists.immutable.empty(); } @Override public >> R zip(Iterable that, R target) { return target; } @Override public ImmutableList> zipWithIndex() { return Lists.immutable.empty(); } @Override public MutableStack toStack() { return Stacks.mutable.empty(); } @Override public >> R zipWithIndex(R target) { return target; } @Override public ImmutableList select(Predicate predicate) { return this; } @Override public > R selectWith(Predicate2 predicate, P parameter, R target) { return target; } @Override public ImmutableList reject(Predicate predicate) { return this; } @Override public > R rejectWith(Predicate2 predicate, P parameter, R target) { return target; } @Override public PartitionImmutableList partition(Predicate predicate) { return (PartitionImmutableList) EMPTY; } @Override public ImmutableList collect(Function function) { return Lists.immutable.empty(); } @Override public ImmutableList collectIf(Predicate predicate, Function function) { return Lists.immutable.empty(); } @Override public > R collectWith(Function2 function, P parameter, R target) { return target; } @Override public ImmutableList flatCollect(Function> function) { return Lists.immutable.empty(); } @Override public > R flatCollect(Function> function, R targetCollection) { return targetCollection; } @Override public T detect(Predicate predicate) { return null; } @Override public int count(Predicate predicate) { return 0; } @Override public

int countWith(Predicate2 predicate, P parameter) { return 0; } @Override public boolean anySatisfy(Predicate predicate) { return false; } @Override public boolean allSatisfy(Predicate predicate) { return true; } @Override public boolean noneSatisfy(Predicate predicate) { return true; } @Override public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return false; } @Override public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return true; } @Override public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return true; } @Override public IV injectInto(IV injectedValue, Function2 function) { return injectedValue; } @Override public int injectInto(int injectedValue, IntObjectToIntFunction intObjectToIntFunction) { return injectedValue; } @Override public long injectInto(long injectedValue, LongObjectToLongFunction longObjectToLongFunction) { return injectedValue; } @Override public double injectInto(double injectedValue, DoubleObjectToDoubleFunction doubleObjectToDoubleFunction) { return injectedValue; } @Override public T getFirst() { return null; } @Override public T getLast() { return null; } @Override public int indexOf(Object object) { return -1; } @Override public boolean equals(Object otherList) { if (otherList == this) { return true; } if (!(otherList instanceof List)) { return false; } List list = (List) otherList; return list.isEmpty(); } @Override public int hashCode() { return 1; } @Override public boolean isEmpty() { return true; } @Override public boolean notEmpty() { return false; } @Override public > R select(Predicate predicate, R target) { return target; } @Override public > R reject(Predicate predicate, R target) { return target; } @Override public > R collect(Function function, R target) { return target; } @Override public > R collectIf(Predicate predicate, Function function, R target) { return target; } @Override public T detectIfNone(Predicate predicate, Function0 function) { return function.value(); } @Override public String toString() { return "[]"; } @Override public String makeString() { return ""; } @Override public String makeString(String separator) { return ""; } @Override public String makeString(String start, String separator, String end) { return start + end; } @Override public void appendString(Appendable appendable) { } @Override public void appendString(Appendable appendable, String separator) { } @Override 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); } } @Override public ImmutableList take(int count) { if (count < 0) { throw new IllegalArgumentException("Count must be greater than zero, but was: " + count); } return this; } @Override public ImmutableList takeWhile(Predicate predicate) { return this; } @Override public ImmutableList drop(int count) { if (count < 0) { throw new IllegalArgumentException("Count must be greater than zero, but was: " + count); } return this; } @Override public ImmutableList dropWhile(Predicate predicate) { return this; } @Override public PartitionImmutableList partitionWhile(Predicate predicate) { return (PartitionImmutableList) EMPTY; } }