?? immutablelist.java
字號:
package concurrency.time;
import java.util.*;
public class ImmutableList {
ImmutableList next;
Object item;
private ImmutableList(ImmutableList next, Object item) {
this.next = next; this.item=item;
}
public static ImmutableList add(ImmutableList list, Object item) {
return new ImmutableList(list, item);
}
public static ImmutableList remove(ImmutableList list, Object target) {
if (list == null) return null;
return list.remove(target);
}
private ImmutableList remove(Object target) {
if (item == target) {
return next;
} else {
ImmutableList new_next = remove(next,target);
if (new_next == next ) return this;
return new ImmutableList(new_next,item);
}
}
public static Enumeration elements(ImmutableList list) {
return new ImmutableListEnumerator(list);
}
}
final class ImmutableListEnumerator implements Enumeration {
private ImmutableList current;
ImmutableListEnumerator(ImmutableList l){current=l;};
public boolean hasMoreElements() {return current != null;}
public Object nextElement() {
if (current!=null) {
Object o = current.item;
current = current.next;
return o;
}
throw new NoSuchElementException("ImmutableListEnumerator");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -