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