⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 immutablelist.java

📁 演示win32的socket 通讯 八皇后的改进算法 并发Concurrency的JAVA实现 applet演示鼠标的点击时间和显示图象 手机J2ME的多线程演示
💻 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 + -