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

📄 collectionsequence30.java

📁 JAVA编程思想第四版英文原版习题答案. pdf原版的
💻 JAVA
字号:
// holding/CollectionSequence30.java
import typeinfo.pets.*;
import java.util.*;

public class CollectionSequence30 implements Collection<Pet> {
	private Pet[] pets = Pets.createArray(8);
	public int size() { return pets.length; }
	public Iterator<Pet> iterator() {
		return new Iterator<Pet>() {
			private int index = 0;
			public boolean hasNext() {
				return index < pets.length; 
			}
			public Pet next() { return pets[index++]; }
			public void remove() { // not implemented
				throw new UnsupportedOperationException();
			}
		};
	}
	public void clear() { 
		if(this.size() != 0)
		for(Pet p : pets)
			p = null;
	}
	public boolean retainAll(Collection<?> c) { 
		throw new UnsupportedOperationException();
	}
	public boolean removeAll(Collection<?> c) { 
		throw new UnsupportedOperationException();
	}
	public boolean addAll(Collection<? extends Pet> c) { 
		throw new UnsupportedOperationException();
	}
	public boolean contains(Object o) {	
		throw new UnsupportedOperationException();
	}
	public boolean isEmpty() {	
		return (this.size() == 0) ? true : false;
	}
	public boolean containsAll(Collection<?> c) { 
		throw new UnsupportedOperationException();
	}
	public boolean remove(Object o) { 
		throw new UnsupportedOperationException();
	}
	public boolean add(Pet p) { 
		throw new UnsupportedOperationException();
	}
	public Object[] toArray() {
		return pets;
	}
	public <T> T[] toArray(T[] a) {
            throw new UnsupportedOperationException();
       }
	public static void main(String[] args) {
		CollectionSequence30 c = new CollectionSequence30();
		InterfaceVsIterator.display(c);
		InterfaceVsIterator.display(c.iterator());
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -