1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.utils.datastructures;
14 import java.util.Collection;
15 import java.util.Iterator;
16 import java.util.NoSuchElementException;
19 public class ImmutableSList<T> extends ImmutableCollection<T> {
22 final public ImmutableSList<T> tail; // null, if this is the last element
24 public ImmutableSList(T head, ImmutableSList<T> tail) {
29 public ImmutableSList(T head) {
34 public boolean contains(Object o) {
35 ImmutableSList<T> cur = this;
37 if(cur.head.equals(o))
44 public boolean containsAll(Collection<?> c) {
51 public boolean isEmpty() {
55 static private class Iter<T> implements Iterator<T> {
56 public ImmutableSList<T> cur;
58 public Iter(ImmutableSList<T> cur) {
63 public boolean hasNext() {
70 throw new NoSuchElementException();
77 public void remove() {
78 throw new UnsupportedOperationException();
84 public Iterator<T> iterator() {
85 return new Iter<T>(this);
89 ImmutableSList<T> cur = this;