AbstractQueue抽象类
package java.util; //抽象类,队列的父类,实现了Queue接口,继承AbstractCollection类 public abstract class AbstractQueue<E> extends AbstractCollection<E> implements Queue<E> { protected AbstractQueue(){ } public boolean add(E e){ if(offer(e)) return true; else throw new IllegalStateException("Queue full"); } public E remove(){ E x = poll(); if(x != null) return x; else throw new NoSuchElementException(); } public E element(){ E x = peek(); if(x != null) return x; else throw new NoSuchElementException(); } public void clear(){ while (poll() != null) ; } public boolean addAll(Collection<? extends E> c){ if(c == null) throw new NullPointerException(); if(c == this) throw new IllegalArgumentException(); boolean modified = false; for(E e : c){ if(add(e)) modified = true; } return modified; } }
Java之uitil包源码阅读 文章被收录于专栏
源码阅读是程序员必不可少的,本专栏记录本人阅读java源码笔记,与阅读此专栏的同道共同进步。 本专栏以字典序对源码进行阅读注释,主要工作:1.去除源码中冗长的英语注释,用简短的注释代替;2.对关键语句和算法予以说明。3.概要性描述。