zoukankan      html  css  js  c++  java
  • Java AbstractSequentialList 抽象类

    继承于 AbstractList ,提供了对数据元素的链式访问而不是随机访问。

    源码展示

    package java.util;
    
    public abstract class AbstractSequentialList<E> extends AbstractList<E> {
    	
        /**
         * 构造方法
         */
        protected AbstractSequentialList() {
        }
    
        /**
         * 获取指定位置的元素
         */
        public E get(int index) {
            try {
                return listIterator(index).next();
            } catch (NoSuchElementException exc) {
                throw new IndexOutOfBoundsException("Index: "+index);
            }
        }
    
        /**
         * 替换元素
         */
        public E set(int index, E element) {
            try {
                ListIterator<E> e = listIterator(index);
                E oldVal = e.next();
                e.set(element);
                return oldVal;
            } catch (NoSuchElementException exc) {
                throw new IndexOutOfBoundsException("Index: "+index);
            }
        }
    
        /**
         * 添加元素
         */
        public void add(int index, E element) {
            try {
                listIterator(index).add(element);
            } catch (NoSuchElementException exc) {
                throw new IndexOutOfBoundsException("Index: "+index);
            }
        }
    
        /**
         * 删除元素
         */
        public E remove(int index) {
            try {
                ListIterator<E> e = listIterator(index);
                E outCast = e.next();
                e.remove();
                return outCast;
            } catch (NoSuchElementException exc) {
                throw new IndexOutOfBoundsException("Index: "+index);
            }
        }
    
    
        /**
         * 批量添加
         */
        public boolean addAll(int index, Collection<? extends E> c) {
            try {
                boolean modified = false;
                ListIterator<E> e1 = listIterator(index);
                Iterator<? extends E> e2 = c.iterator();
                while (e2.hasNext()) {
                    e1.add(e2.next());
                    modified = true;
                }
                return modified;
            } catch (NoSuchElementException exc) {
                throw new IndexOutOfBoundsException("Index: "+index);
            }
        }
    
    
        /**
         * 返回迭代器
         */
        public Iterator<E> iterator() {
            return listIterator();
        }
    
        /**
         * 返回迭代器
         */
        public abstract ListIterator<E> listIterator(int index);
    }
    
  • 相关阅读:
    Linux crontab 命令
    tcpdump抓包工具
    tcpdump过滤某个端口
    ARM处理器基础Cortex-M4
    rtems floating poing switch
    ARM处理器的堆栈和函数调用,以及与Sparc的比较
    关于调用堆栈,任务堆栈
    如何测试嵌入式处理器的CPU使用率
    关于嵌入式实时操作系统的实时性
    RTEMS API
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/14987767.html
Copyright © 2011-2022 走看看