
com.strobel.collections.ImmutableList Maven / Gradle / Ivy
/*
* ImmutableList.java
*
* Copyright (c) 2012 Mike Strobel
*
* This source code is subject to terms and conditions of the Apache License, Version 2.0.
* A copy of the license can be found in the License.html file at the root of this distribution.
* By using this source code in any fashion, you are agreeing to be bound by the terms of the
* Apache License, Version 2.0.
*
* You must not remove this notice, or any other, from this software.
*/
package com.strobel.collections;
import com.strobel.annotations.NotNull;
import com.strobel.core.StringUtilities;
import java.lang.reflect.Array;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.NoSuchElementException;
/**
* A class for generic linked lists. Links are supposed to be
* immutable, the only exception being the incremental construction of
* lists via ListBuffers. List is the main container class in
* GJC. Most data structures and algorithms in GJC use lists rather
* than arrays.
*
* Lists are always trailed by a sentinel element, whose head and tail
* are both null.
*
* This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.
*/
@SuppressWarnings("PublicField")
public class ImmutableList extends AbstractCollection implements java.util.List {
/**
* The first element of the list, supposed to be immutable.
*/
public A head;
/**
* The remainder of the list except for its first element, supposed
* to be immutable.
*/
//@Deprecated
public ImmutableList tail;
/**
* Construct a list given its head and tail.
*/
ImmutableList(final A head, final ImmutableList tail) {
this.tail = tail;
this.head = head;
}
/**
* Construct an empty list.
*/
@SuppressWarnings("unchecked")
public static ImmutableList empty() {
return (ImmutableList)EMPTY_LIST;
}
private static final ImmutableList> EMPTY_LIST = new ImmutableList