com.shapesecurity.functional.data.ImmutableList Maven / Gradle / Ivy
Show all versions of shape-functional-java Show documentation
/*
* Copyright 2014 Shape Security, Inc.
*
* 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.shapesecurity.functional.data;
import com.shapesecurity.functional.Effect;
import com.shapesecurity.functional.F;
import com.shapesecurity.functional.F2;
import com.shapesecurity.functional.Pair;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.function.Supplier;
import java.util.stream.Collector;
/**
* An immutable singly linked list implementation. None of the operations in {@link ImmutableList}
* changes the list itself. Therefore you can freely share the list in your system. This is a
* "classical" list implementation that the list is only allowed to prepend and to remove the first
* element efficiently. Therefore it is essentially equivalent to a stack.
It is either an empty
* list, or a record that contains the first element (called "head") and a list that follows(called
* "tail"). With the assumption that all the elements in the list are also immutable, the sharing of
* the tails is possible.
For a data structure that allows O(1) concatenation, try {@link
* ConcatList}. A BinaryTree can be converted into a List in O(n) time.
*
* @param The super type of all the elements.
*/
@CheckReturnValue
public abstract class ImmutableList implements Iterable {
@SuppressWarnings("StaticInitializerReferencesSubClass")
private static final ImmutableList