AbstractSequentialList说明
来源:互联网 发布:人工智能综述 编辑:程序博客网 时间:2024/06/05 03:28
AbstractSequentialList也是一个抽象类,它的声明如下:
public abstract class AbstractSequentialList extends AbstractList
有关AbstractList:http://blog.csdn.net/treeroot/archive/2004/09/14/104743.aspx
这个类的代码比较简单
public Object get(int index) {
ListIterator e = listIterator(index);
try {
return(e.next());
} catch(NoSuchElementException exc) {
throw(new IndexOutOfBoundsException("Index: "+index));
}
}
public Object set(int index, Object element) {
ListIterator e = listIterator(index);
try {
Object oldVal = e.next();
e.set(element);
return oldVal;
} catch(NoSuchElementException exc) {
throw(new IndexOutOfBoundsException("Index: "+index));
}
}
public void add(int index, Object element) {
ListIterator e = listIterator(index);
e.add(element);
}
public Object remove(int index) {
ListIterator e = listIterator(index);
Object outCast;
try {
outCast = e.next();
} catch(NoSuchElementException exc) {
throw(new IndexOutOfBoundsException("Index: "+index));
}
e.remove();
return(outCast);
}
public boolean addAll(int index, Collection c) {
boolean modified = false;
ListIterator e1 = listIterator(index);
Iterator e2 = c.iterator();
while (e2.hasNext()) {
e1.add(e2.next());
modified = true;
}
return modified;
}
public Iterator iterator() {
return listIterator();
}
public abstract ListIterator listIterator(int index);
注意到所有的方法都使用迭代器,明显设计的不好,没有做到fast-fail,应该是先简单是否越界
不过子类都会重写这些方法。由于这些代码都比较简单,前面的一些类中也有类似的情况,这里只是
提供一个通用的实现,这里列出来只是为了方便分析LinkedList,因为LinkedList是它的子类。
- AbstractSequentialList说明
- AbstractSequentialList
- AbstractSequentialList
- AbstractSequentialList源码分析
- 源码分析-java-AbstractSequentialList
- Java集合之AbstractSequentialList
- java.util.AbstractSequentialList<E>
- AbstractSequentialList抽象类源码解析
- 5-3、java.util.AbstractSequentialList
- java.util.AbstractSequentialList学习笔记
- java集合分析(8):AbstractSequentialList
- 解析java.util集合类源码(AbstractSequentialList)
- JDK源码阅读之List和AbstractSequentialList
- 共同学习Java源代码--数据结构--AbstractSequentialList类
- Java 集合深入理解(8):AbstractSequentialList
- Java 集合深入理解(8):AbstractSequentialList
- Java 集合深入理解(8):AbstractSequentialList
- Java常见集合框架(四):List之AbstractSequentialList、LinkedList
- excel打开就报错,说windows 即将关闭
- 网址收藏
- Eclipse 平台入门
- C++ 中的 Singleton 实现(转)
- Model View Controller (MVC) Using C#, Delegates and Events in .NET
- AbstractSequentialList说明
- Delphi异常处理的基本原则和方法
- 轻松实现类VC IDE界面
- 开学典礼致辞
- Toolbar within splitter windows
- Windows自带的小巧的调试利器--Dr.Watson
- Bitmap Basics - A GDI tutorial
- 常用文件的恐怖用法
- 决定开始翻译Dive Into Python