diff --git a/README.md b/README.md index add63ab3..f4fa5df9 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ 整理自《深入理解 Java 虚拟机》,包括内存模型、垃圾回收和类加载机制。 -> [Java 容器](https://github.com/CyC2018/InnterviewNotes/blob/master/notes/Java%20集合.mdd) +> [Java 容器](https://github.com/CyC2018/InnterviewNotes/blob/master/notes/Java%20容器.md) 容器的一些总结,包含容器源码的分析。 diff --git a/notes/Java 容器.md b/notes/Java 容器.md new file mode 100644 index 00000000..9721f2a6 --- /dev/null +++ b/notes/Java 容器.md @@ -0,0 +1,360 @@ +<!-- GFM-TOC --> +* [����](#����) + * [1. List](#1-list) + * [2. Set](#2-set) + * [3. Queue](#3-queue) + * [4. Map](#4-map) + * [5. Java 1.0/1.1 ����](#5-java-1011-����) +* [�����е����ģʽ](#�����е����ģʽ) + * [1. ������ģʽ](#1-������ģʽ) + * [2. ������ģʽ](#2-������ģʽ) +* [ɢ��](#ɢ��) +* [Դ�����](#Դ�����) + * [1. ArraList](#1-arralist) + * [2. Vector �� Stack](#2-vector-��-stack) + * [3. LinkedList](#3-linkedlist) + * [4. TreeMap](#4-treemap) + * [5. HashMap](#5-hashmap) + * [6. LinkedHashMap](#6-linkedhashmap) + * [7. ConcurrentHashMap](#7-concurrenthashmap) +* [�ο�����](#�ο�����) +<!-- GFM-TOC --> + +# ���� + + + +������Ҫ���� Collection �� Map ���֣�Collection �ְ����� List��Set �Լ� Queue�� + +## 1. List + +- ArrayList��ʹ�����鷽����֧��������ʣ� + +- LinkedList��ʹ������ʵ�֣�ֻ��˳����ʣ����ǿ��Կ��ٵ����м�����ɾ��Ԫ�ء�������ˣ�LinkedList ����������ջ�����к�˫�˶��С� + +## 2. Set + +- HashSet��ʹ�� Hash ʵ�֣�֧�ֿ��ٲ��ң�����ʧȥ�����ԣ� + +- TreeSet��ʹ����ʵ�֣����������Dz���Ч�ʲ��� HashSet�� + +- LinkedListHashSet������ HashSet �IJ���Ч�ʣ����ڲ�ʹ������ά��Ԫ�صIJ���˳����˾��������ԡ� + +## 3. Queue + +ֻ������ʵ�֣�LinkedList �� PriorityQueue������ LinkedList ֧��˫����С� + +## 4. Map + +- HashMap��ʹ�� Hash ʵ�� + +- LinkedHashMap����������˳��Ϊ����˳������������ʹ�ã�LRU��˳�� + +- TreeMap�����ں����ʵ�� + +- ConcurrentHashMap���̰߳�ȫ Map�����漰ͬ������ + +## 5. Java 1.0/1.1 ���� + +���ھɵ����������Ǿ���Ӧ��ʹ�����ǣ�ֻ��Ҫ�����ǽ����˽⡣ + +- Vector���� ArrayList ���ƣ��������̰߳�ȫ�� + +- HashTable���� HashMap ���ƣ��������̰߳�ȫ�� + +# �����е����ģʽ + +## 1. ������ģʽ + +�Ӹ���ͼ���Կ�����ÿ���������һ�� Iterator ������ͨ��������������������������е�Ԫ�ء� + +[Java �еĵ�����ģʽ ](https://github.com/CyC2018/InterviewNotes/blob/master/notes/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F.md#92-java-%E5%86%85%E7%BD%AE%E7%9A%84%E8%BF%AD%E4%BB%A3%E5%99%A8) + +## 2. ������ģʽ + +java.util.Arrays#asList() ������������ת��Ϊ List ���͡� + +```java + List list = Arrays.asList(1, 2, 3); + int[] arr = {1, 2, 3}; + list = Arrays.asList(arr); +``` + +# ɢ�� + +ʹ�� hasCode() ������ɢ��ֵ��ʹ�õ��Ƕ���ĵ�ַ�� + +�� equals() �������ж����������Ƿ���ȵģ���ȵ���������ɢ��ֵһ��Ҫ��ͬ������ɢ��ֵ��ͬ����������һ����ȡ� + +��ȱ�����������������ʣ� + +1. �Է��� +2. �Գ��� +3. ������ +4. һ���ԣ���ε��� x.equals(y)��������䣩 +5. ���κβ��� null �Ķ��� x ���� x.equals(nul) �����Ϊ false + +# Դ����� + +�������Ķ� [ �㷨 - ���� ](https://github.com/CyC2018/InterviewNotes/blob/master/notes/%E7%AE%97%E6%B3%95.md#%E7%AC%AC%E4%B8%89%E7%AB%A0-%E6%9F%A5%E6%89%BE) ���֣��Լ�����Դ��������кܴ������ + +Դ�����أ�[OpenJDK 1.7](http://download.java.net/openjdk/jdk7) + +## 1. ArraList + +[ArraList.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/ArrayList.java) + +ʵ���� RandomAccess �ӿڣ����֧��������ʣ�����������Ȼ�ģ���Ϊ ArrayList �ǻ�������ʵ�ֵġ� + +```java +public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable +``` + +��������ʵ�֣�����Ԫ�ص�����ʹ�� transient ���Σ�������Ϊ�����鲻һ������λ�ö�ռ��Ԫ�أ����Ҳ��û��Ҫȫ�����������л�����Ҫ��д writeObject() �� readObject()�� + +```java +private transient Object[] elementData; +``` + +�����Ĭ�ϴ�СΪ 10 + +```java +public ArrayList(int initialCapacity) { + super(); + if (initialCapacity < 0) + throw new IllegalArgumentException("Illegal Capacity: "+ initialCapacity); + this.elementData = new Object[initialCapacity]; +} + +public ArrayList() { + this(10); +} +``` + +ɾ��Ԫ��ʱ���� System.arraycopy() ��Ԫ�ؽ��и��ƣ����ɾ�������ɱ��ܸߡ� + +```java +public E remove(int index) { + rangeCheck(index); + + modCount++; + E oldValue = elementData(index); + + int numMoved = size - index - 1; + if (numMoved > 0) + System.arraycopy(elementData, index+1, elementData, index, numMoved); + elementData[--size] = null; // Let gc do its work + + return oldValue; +} +``` + +����Ԫ��ʱʹ�� ensureCapacity() ��������֤�����㹻���������ʱ����Ҫ�������ݣ�ʹ��������Ϊ�������� 1.5 ���� + +modCount ������¼ ArrayList �����仯�Ĵ�������Ϊÿ���ڽ��� add() �� addAll() ʱ����Ҫ���� ensureCapacity()�����ֱ���� ensureCapacity() �ж� modCount �����ġ� + +```java +public void ensureCapacity(int minCapacity) { + if (minCapacity > 0) + ensureCapacityInternal(minCapacity); +} + +private void ensureCapacityInternal(int minCapacity) { + modCount++; + // overflow-conscious code + if (minCapacity - elementData.length > 0) + grow(minCapacity); +} + +private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; + +private void grow(int minCapacity) { + // overflow-conscious code + int oldCapacity = elementData.length; + int newCapacity = oldCapacity + (oldCapacity >> 1); + if (newCapacity - minCapacity < 0) + newCapacity = minCapacity; + if (newCapacity - MAX_ARRAY_SIZE > 0) + newCapacity = hugeCapacity(minCapacity); + // minCapacity is usually close to size, so this is a win: + elementData = Arrays.copyOf(elementData, newCapacity); +} + +private static int hugeCapacity(int minCapacity) { + if (minCapacity < 0) // overflow + throw new OutOfMemoryError(); + return (minCapacity > MAX_ARRAY_SIZE) ? + Integer.MAX_VALUE : + MAX_ARRAY_SIZE; +} +``` + +�ڽ������л����ߵ����Ȳ���ʱ����Ҫ�Ƚϲ���ǰ�� modCount �Ƿ�ı䣬����ı�����Ҫ�׳� ConcurrentModificationException�� + +```java +private void writeObject(java.io.ObjectOutputStream s) + throws java.io.IOException{ + // Write out element count, and any hidden stuff + int expectedModCount = modCount; + s.defaultWriteObject(); + + // Write out array length + s.writeInt(elementData.length); + + // Write out all elements in the proper order. + for (int i=0; i<size; i++) + s.writeObject(elementData[i]); + + if (modCount != expectedModCount) { + throw new ConcurrentModificationException(); + } + +} +``` + +**�� Vector ������** + +1. Vector �� ArrayList ��������ȫ��ͬ�ģ�Ψһ���������� Vector ��ͬ���ģ���˿����ͱ� ArrayList Ҫ����Ҫ�������ʹ�� ArrayList ������ Vector����Ϊͬ����ȫ�����ɳ���Ա�Լ������ƣ� +2. Vector ÿ�������������С�� 2 ���ռ䣬�� ArrayList �� 1.5 ���� + +Ϊ��ʹ���̰߳�ȫ�� ArrayList������ʹ�� Collections.synchronizedList(new ArrayList<>()); ����һ���̰߳�ȫ�� ArrayList��Ҳ����ʹ�� concurrent �������µ� CopyOnWriteArrayList �ࣻ + +**�� LinkedList ������** + +1. ArrayList ���ڶ�̬����ʵ�֣�LinkedList ����˫��ѭ������ʵ�֣� +2. ArrayList ֧��������ʣ�LinkedList ��֧�֣� +3. LinkedList ������λ������ɾ��Ԫ�ظ��졣 + +## 2. Vector �� Stack + +[Vector.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/Vector.java) + +## 3. LinkedList + +[LinkedList.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/LinkedList.java) + +## 4. TreeMap + +[TreeMap.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/TreeMap.java) + +## 5. HashMap + +[HashMap.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/HashMap.java) + +ʹ���������������ͻ�� + +Ĭ������ capacity Ϊ 16����Ҫע������������뱣֤Ϊ 2 �Ĵη����������� Entry[] table ����ij��ȣ�size �������ʵ��ʹ������ + +threshold �涨��һ�� size ���ٽ�ֵ��size ����С�� threshold��������ڵ��ڣ��ͱ���������ݲ����� + +threshold = capacity * load_factor������ load_factor Ϊ table �����ܹ�ʹ�õı�����load_factor ����ᵼ�¾۴صij��֣��Ӷ�Ӱ���ѯ�Ͳ����Ч�ʣ�����㷨�ʼǡ� + +```java +static final int DEFAULT_INITIAL_CAPACITY = 16; + +static final int MAXIMUM_CAPACITY = 1 << 30; + +static final float DEFAULT_LOAD_FACTOR = 0.75f; + +transient Entry[] table; + +transient int size; + +int threshold; + +final float loadFactor; + +transient int modCount; +``` + +�����������Ԫ�ش����п��Կ���������Ҫ����ʱ���� capacity Ϊԭ���������� + +```java +void addEntry(int hash, K key, V value, int bucketIndex) { + Entry<K,V> e = table[bucketIndex]; + table[bucketIndex] = new Entry<>(hash, key, value, e); + if (size++ >= threshold) + resize(2 * table.length); +} +``` + +Entry ������ʾһ����ֵ��Ԫ�أ����е� next ָ�������л�ʱ��ʹ�á� + +```java +static class Entry<K,V> implements Map.Entry<K,V> { + final K key; + V value; + Entry<K,V> next; + final int hash; +} +``` + +get() ������Ҫ�ֳ����������key Ϊ null �� ��Ϊ null�����п��Կ��� HashMap �������� null ��Ϊ���� + +```java +public V get(Object key) { + if (key == null) + return getForNullKey(); + int hash = hash(key.hashCode()); + for (Entry<K,V> e = table[indexFor(hash, table.length)]; e != null; e = e.next) { + Object k; + if (e.hash == hash && ((k = e.key) == key || key.equals(k))) + return e.value; + } + return null; +} +``` + +put() ����Ҳ��Ҫ���� key �Ƿ�Ϊ null ����ͬ�Ĵ�������Ҫע������������û�� key Ϊ null �ļ�ֵ�ԣ��²���һ�� key Ϊ null �ļ�ֵ��ʱĬ���Ƿ�������� 0 λ�ã�������Ϊ null ���ܼ��� hash ֵ��Ҳ����֪��Ӧ�÷����ĸ������ϡ� + +```java +public V put(K key, V value) { + if (key == null) + return putForNullKey(value); + int hash = hash(key.hashCode()); + int i = indexFor(hash, table.length); + for (Entry<K,V> e = table[i]; e != null; e = e.next) { + Object k; + if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { + V oldValue = e.value; + e.value = value; + e.recordAccess(this); + return oldValue; + } + } + + modCount++; + addEntry(hash, key, value, i); + return null; +} +``` + +```java +private V putForNullKey(V value) { + for (Entry<K,V> e = table[0]; e != null; e = e.next) { + if (e.key == null) { + V oldValue = e.value; + e.value = value; + e.recordAccess(this); + return oldValue; + } + } + modCount++; + addEntry(0, null, value, 0); + return null; +} +``` + +## 6. LinkedHashMap + +[LinkedHashMap.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/HashMap.java) + +## 7. ConcurrentHashMap + +[ConcurrentHashMap.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/HashMap.java) + +[ ̽�� ConcurrentHashMap �߲����Ե�ʵ�ֻ��� ](https://www.ibm.com/developerworks/cn/java/java-lo-concurrenthashmap/) + +# �ο����� + +- Java ���˼�� diff --git a/notes/Java 集合.md b/notes/Java 集合.md deleted file mode 100644 index b6d0616b..00000000 --- a/notes/Java 集合.md +++ /dev/null @@ -1,152 +0,0 @@ -<!-- GFM-TOC --> -* [����](#����) - * [1. List](#1-list) - * [2. Set](#2-set) - * [3. Queue](#3-queue) - * [4. Map](#4-map) - * [5. Java 1.0/1.1 ����](#5-java-1011-����) -* [�����е����ģʽ](#�����е����ģʽ) - * [1. ������ģʽ](#1-������ģʽ) - * [2. ������ģʽ](#2-������ģʽ) -* [ɢ��](#ɢ��) -* [Դ�����](#Դ�����) - * [1. ArraList](#1-arralist) - * [2. LinkedList](#2-linkedlist) - * [3. Vector](#3-vector) - * [4. HashMap](#4-hashmap) - * [5. LinkedHashMap](#5-linkedhashmap) - * [6. ConcurrentHashMap](#6-concurrenthashmap) -* [�ο�����](#�ο�����) -<!-- GFM-TOC --> - -# ���� - - - -������Ҫ���� Collection �� Map ���֣�Collection �ְ����� List��Set �Լ� Queue�� - -## 1. List - -- ArrayList��ʹ�����鷽����֧��������ʣ� - -- LinkedList��ʹ������ʵ�֣�ֻ��˳����ʣ����ǿ��Կ��ٵ����м�����ɾ��Ԫ�ء�������ˣ�LinkedList ����������ջ�����к�˫�˶��С� - -## 2. Set - -- HashSet��ʹ�� Hash ʵ�֣�֧�ֿ��ٲ��ң�����ʧȥ�����ԣ� - -- TreeSet��ʹ����ʵ�֣����������Dz���Ч�ʲ��� HashSet�� - -- LinkedListHashSet������ HashSet �IJ���Ч�ʣ����ڲ�ʹ������ά��Ԫ�صIJ���˳����˾��������ԡ� - -## 3. Queue - -ֻ������ʵ�֣�LinkedList �� PriorityQueue������ LinkedList ֧��˫����С� - -## 4. Map - -- HashMap��ʹ�� Hash ʵ�� - -- LinkedHashMap����������˳��Ϊ����˳������������ʹ�ã�LRU��˳�� - -- TreeMap�����ں����ʵ�� - -- ConcurrentHashMap���̰߳�ȫ Map�����漰ͬ������ - -## 5. Java 1.0/1.1 ���� - -���ھɵ����������Ǿ���Ӧ��ʹ�����ǣ�ֻ��Ҫ�����ǽ����˽⡣ - -- Vector���� ArrayList ���ƣ��������̰߳�ȫ�� - -- HashTable���� HashMap ���ƣ��������̰߳�ȫ�� - -# �����е����ģʽ - -## 1. ������ģʽ - -�Ӹ���ͼ���Կ�����ÿ���������һ�� Iterator ������ͨ��������������������������е�Ԫ�ء� - -[Java �еĵ�����ģʽ](https://github.com/CyC2018/InterviewNotes/blob/master/notes/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F.md#92-java-%E5%86%85%E7%BD%AE%E7%9A%84%E8%BF%AD%E4%BB%A3%E5%99%A8) - -## 2. ������ģʽ - -java.util.Arrays#asList() ������������ת��Ϊ List ���͡� - -```java - List list = Arrays.asList(1, 2, 3); - int[] arr = {1, 2, 3}; - list = Arrays.asList(arr); -``` - -# ɢ�� - -ʹ�� hasCode() ������ɢ��ֵ��ʹ�õ��Ƕ���ĵ�ַ�� - -�� equals() �������ж����������Ƿ���ȵģ���ȵ���������ɢ��ֵһ��Ҫ��ͬ������ɢ��ֵ��ͬ����������һ����ȡ� - -��ȱ�����������������ʣ� - -1. �Է��� -2. �Գ��� -3. ������ -4. һ���ԣ���ε��� x.equals(y)��������䣩 -5. ���κβ��� null �Ķ��� x ���� x.equals(nul) �����Ϊ false - -# Դ����� - -�������Ķ� [�㷨-����](https://github.com/CyC2018/InterviewNotes/blob/master/notes/%E7%AE%97%E6%B3%95.md#%E7%AC%AC%E4%B8%89%E7%AB%A0-%E6%9F%A5%E6%89%BE) ���֣��Լ�����Դ��������кܴ������ - - -Դ�����أ�[OpenJDK 1.7](http://download.java.net/openjdk/jdk7) - -�����Ķ���[7u40-b43](http://grepcode.com/snapshot/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/) - -## 1. ArraList - -- ʹ������ʵ�� - -- ���ж�̬�������ԣ�Ĭ������Ϊ 10������������Ԫ��ʱʹ�� ensureCapacity() ��֤�����㹻���������������������Ϊԭʼ������ 1.5 times + 1. - -[ArraList.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/ArrayList.java) - - -## 2. LinkedList - -- LinkedList �ǻ���˫��ѭ������ʵ�֣�ͷ��㲻�������ݡ� - - - -- ����������������Ҫ����������LinkedList �� Entry entry(int index) ��������������������������һ���Ż��IJ������������ index ������ǰ�棬��ô�ʹ�ͷ�������������ں���ʹӺ���ǰ������ - -[LinkedList.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/LinkedList.java) - -## 3. Vector - -Vector �ĺܶ�ʵ�ַ�����������ͬ����䣬������̰߳�ȫ�ġ� - -[Vector.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/Vector.java) - -## 4. HashMap - -- ʹ���������������ͻ�� - -[Vector.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/HashMap.java) - - -## 5. LinkedHashMap - -- ʹ��˫���������������Ľڵ㣬�Ӷ�ά��һ������˳�� -- ע��Դ���е�accessOrder��־λ������falseʱ����ʾ˫�������е�Ԫ�ذ���Entry����LinkedHashMap���е��Ⱥ�˳������ÿ��put��LinkedHashMap�е�Entry������˫��������β������������˫������ʱ��Entry�����˳���Ͳ����˳��һ�£���Ҳ��Ĭ�ϵ�˫�������Ĵ洢˳����Ϊtrueʱ����ʾ˫�������е�Ԫ�ذ��շ��ʵ��Ⱥ�˳�����У����Կ�������ȻEntry����������˳����Ȼ�ǰ�����put��LinkedHashMap�е�˳��put��get�������е���recordAccess������put������key��ͬ������ԭ�е�Entry������µ���recordAccess���������÷����ж�accessOrder�Ƿ�Ϊtrue������ǣ���ǰ���ʵ�Entry��put������Entry��get������Entry���Ƶ�˫��������β����key����ͬʱ��put��Entryʱ�������addEntry���������creatEntry���÷���ͬ�����²����Ԫ�ط��뵽˫��������β�����ȷ��ϲ�����Ⱥ�˳���ַ��Ϸ��ʵ��Ⱥ�˳����Ϊ��ʱ��EntryҲ�������ˣ�������ʲôҲ���������˵˵LinkedHashMap�����ʵ��LRU�ġ����ȣ���accessOrderΪtrueʱ���ŻῪ��������˳�������ģʽ����������ʵ��LRU�㷨�����ǿ��Կ�����������put��������get���������ᵼ��Ŀ��Entry��Ϊ������ʵ�Entry����˱�Ѹ�Entry���뵽��˫��������ĩβ��get����ͨ������recordAccess������ʵ�֣�put�����ڸ�������key������£�Ҳ��ͨ������recordAccess������ʵ�֣��ڲ����µ�Entryʱ������ͨ��createEntry�е�addBefore������ʵ�֣�������������ʹ���˵�Entry���뵽��˫�������ĺ��棬��β�����˫������ǰ���Entry�������û��ʹ�õģ��������ڵ��������ʱ��ɾ������ǰ���Entry(head������Ǹ�Entry)�����������ʹ�õ�Entry�� - -[LinkedHashMap.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/HashMap.java) - -## 6. ConcurrentHashMap - -[̽�� ConcurrentHashMap �߲����Ե�ʵ�ֻ���](https://www.ibm.com/developerworks/cn/java/java-lo-concurrenthashmap/) - -[ConcurrentHashMap.java](https://github.com/CyC2018/InterviewNotes/blob/master/notes/src/HashMap.java) - -# �ο����� - -- Java ���˼�� diff --git a/notes/src/ConcurrentHashMap.java b/notes/src/ConcurrentHashMap.java index e8214806..338f7d65 100644 --- a/notes/src/ConcurrentHashMap.java +++ b/notes/src/ConcurrentHashMap.java @@ -1,37 +1,3 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * This file is available under and governed by the GNU General Public - * License version 2 only, as published by the Free Software Foundation. - * However, the following notice accompanied the original version of this - * file: - * - * Written by Doug Lea with assistance from members of JCP JSR-166 - * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/publicdomain/zero/1.0/ - */ package java.util.concurrent; import java.util.concurrent.locks.*; @@ -41,64 +7,6 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -/** - * A hash table supporting full concurrency of retrievals and - * adjustable expected concurrency for updates. This class obeys the - * same functional specification as {@link java.util.Hashtable}, and - * includes versions of methods corresponding to each method of - * <tt>Hashtable</tt>. However, even though all operations are - * thread-safe, retrieval operations do <em>not</em> entail locking, - * and there is <em>not</em> any support for locking the entire table - * in a way that prevents all access. This class is fully - * interoperable with <tt>Hashtable</tt> in programs that rely on its - * thread safety but not on its synchronization details. - * - * <p> Retrieval operations (including <tt>get</tt>) generally do not - * block, so may overlap with update operations (including - * <tt>put</tt> and <tt>remove</tt>). Retrievals reflect the results - * of the most recently <em>completed</em> update operations holding - * upon their onset. For aggregate operations such as <tt>putAll</tt> - * and <tt>clear</tt>, concurrent retrievals may reflect insertion or - * removal of only some entries. Similarly, Iterators and - * Enumerations return elements reflecting the state of the hash table - * at some point at or since the creation of the iterator/enumeration. - * They do <em>not</em> throw {@link ConcurrentModificationException}. - * However, iterators are designed to be used by only one thread at a time. - * - * <p> The allowed concurrency among update operations is guided by - * the optional <tt>concurrencyLevel</tt> constructor argument - * (default <tt>16</tt>), which is used as a hint for internal sizing. The - * table is internally partitioned to try to permit the indicated - * number of concurrent updates without contention. Because placement - * in hash tables is essentially random, the actual concurrency will - * vary. Ideally, you should choose a value to accommodate as many - * threads as will ever concurrently modify the table. Using a - * significantly higher value than you need can waste space and time, - * and a significantly lower value can lead to thread contention. But - * overestimates and underestimates within an order of magnitude do - * not usually have much noticeable impact. A value of one is - * appropriate when it is known that only one thread will modify and - * all others will only read. Also, resizing this or any other kind of - * hash table is a relatively slow operation, so, when possible, it is - * a good idea to provide estimates of expected table sizes in - * constructors. - * - * <p>This class and its views and iterators implement all of the - * <em>optional</em> methods of the {@link Map} and {@link Iterator} - * interfaces. - * - * <p> Like {@link Hashtable} but unlike {@link HashMap}, this class - * does <em>not</em> allow <tt>null</tt> to be used as a key or value. - * - * <p>This class is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @since 1.5 - * @author Doug Lea - * @param <K> the type of keys maintained by this map - * @param <V> the type of mapped values - */ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K, V>, Serializable { private static final long serialVersionUID = 7249069246763182397L; diff --git a/notes/src/HashMap.java b/notes/src/HashMap.java index 916d6951..5afaa09c 100644 --- a/notes/src/HashMap.java +++ b/notes/src/HashMap.java @@ -1,126 +1,6 @@ -/* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - package java.util; import java.io.*; -/** - * Hash table based implementation of the <tt>Map</tt> interface. This - * implementation provides all of the optional map operations, and permits - * <tt>null</tt> values and the <tt>null</tt> key. (The <tt>HashMap</tt> - * class is roughly equivalent to <tt>Hashtable</tt>, except that it is - * unsynchronized and permits nulls.) This class makes no guarantees as to - * the order of the map; in particular, it does not guarantee that the order - * will remain constant over time. - * - * <p>This implementation provides constant-time performance for the basic - * operations (<tt>get</tt> and <tt>put</tt>), assuming the hash function - * disperses the elements properly among the buckets. Iteration over - * collection views requires time proportional to the "capacity" of the - * <tt>HashMap</tt> instance (the number of buckets) plus its size (the number - * of key-value mappings). Thus, it's very important not to set the initial - * capacity too high (or the load factor too low) if iteration performance is - * important. - * - * <p>An instance of <tt>HashMap</tt> has two parameters that affect its - * performance: <i>initial capacity</i> and <i>load factor</i>. The - * <i>capacity</i> is the number of buckets in the hash table, and the initial - * capacity is simply the capacity at the time the hash table is created. The - * <i>load factor</i> is a measure of how full the hash table is allowed to - * get before its capacity is automatically increased. When the number of - * entries in the hash table exceeds the product of the load factor and the - * current capacity, the hash table is <i>rehashed</i> (that is, internal data - * structures are rebuilt) so that the hash table has approximately twice the - * number of buckets. - * - * <p>As a general rule, the default load factor (.75) offers a good tradeoff - * between time and space costs. Higher values decrease the space overhead - * but increase the lookup cost (reflected in most of the operations of the - * <tt>HashMap</tt> class, including <tt>get</tt> and <tt>put</tt>). The - * expected number of entries in the map and its load factor should be taken - * into account when setting its initial capacity, so as to minimize the - * number of rehash operations. If the initial capacity is greater - * than the maximum number of entries divided by the load factor, no - * rehash operations will ever occur. - * - * <p>If many mappings are to be stored in a <tt>HashMap</tt> instance, - * creating it with a sufficiently large capacity will allow the mappings to - * be stored more efficiently than letting it perform automatic rehashing as - * needed to grow the table. - * - * <p><strong>Note that this implementation is not synchronized.</strong> - * If multiple threads access a hash map concurrently, and at least one of - * the threads modifies the map structurally, it <i>must</i> be - * synchronized externally. (A structural modification is any operation - * that adds or deletes one or more mappings; merely changing the value - * associated with a key that an instance already contains is not a - * structural modification.) This is typically accomplished by - * synchronizing on some object that naturally encapsulates the map. - * - * If no such object exists, the map should be "wrapped" using the - * {@link Collections#synchronizedMap Collections.synchronizedMap} - * method. This is best done at creation time, to prevent accidental - * unsynchronized access to the map:<pre> - * Map m = Collections.synchronizedMap(new HashMap(...));</pre> - * - * <p>The iterators returned by all of this class's "collection view methods" - * are <i>fail-fast</i>: if the map is structurally modified at any time after - * the iterator is created, in any way except through the iterator's own - * <tt>remove</tt> method, the iterator will throw a - * {@link ConcurrentModificationException}. Thus, in the face of concurrent - * modification, the iterator fails quickly and cleanly, rather than risking - * arbitrary, non-deterministic behavior at an undetermined time in the - * future. - * - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed - * as it is, generally speaking, impossible to make any hard guarantees in the - * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw <tt>ConcurrentModificationException</tt> on a best-effort basis. - * Therefore, it would be wrong to write a program that depended on this - * exception for its correctness: <i>the fail-fast behavior of iterators - * should be used only to detect bugs.</i> - * - * <p>This class is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @param <K> the type of keys maintained by this map - * @param <V> the type of mapped values - * - * @author Doug Lea - * @author Josh Bloch - * @author Arthur van Hoff - * @author Neal Gafter - * @see Object#hashCode() - * @see Collection - * @see Map - * @see TreeMap - * @see Hashtable - * @since 1.2 - */ - public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable diff --git a/notes/src/HashSet.java b/notes/src/HashSet.java index 9e53917a..b2fca169 100644 --- a/notes/src/HashSet.java +++ b/notes/src/HashSet.java @@ -1,89 +1,5 @@ -/* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - package java.util; -/** - * This class implements the <tt>Set</tt> interface, backed by a hash table - * (actually a <tt>HashMap</tt> instance). It makes no guarantees as to the - * iteration order of the set; in particular, it does not guarantee that the - * order will remain constant over time. This class permits the <tt>null</tt> - * element. - * - * <p>This class offers constant time performance for the basic operations - * (<tt>add</tt>, <tt>remove</tt>, <tt>contains</tt> and <tt>size</tt>), - * assuming the hash function disperses the elements properly among the - * buckets. Iterating over this set requires time proportional to the sum of - * the <tt>HashSet</tt> instance's size (the number of elements) plus the - * "capacity" of the backing <tt>HashMap</tt> instance (the number of - * buckets). Thus, it's very important not to set the initial capacity too - * high (or the load factor too low) if iteration performance is important. - * - * <p><strong>Note that this implementation is not synchronized.</strong> - * If multiple threads access a hash set concurrently, and at least one of - * the threads modifies the set, it <i>must</i> be synchronized externally. - * This is typically accomplished by synchronizing on some object that - * naturally encapsulates the set. - * - * If no such object exists, the set should be "wrapped" using the - * {@link Collections#synchronizedSet Collections.synchronizedSet} - * method. This is best done at creation time, to prevent accidental - * unsynchronized access to the set:<pre> - * Set s = Collections.synchronizedSet(new HashSet(...));</pre> - * - * <p>The iterators returned by this class's <tt>iterator</tt> method are - * <i>fail-fast</i>: if the set is modified at any time after the iterator is - * created, in any way except through the iterator's own <tt>remove</tt> - * method, the Iterator throws a {@link ConcurrentModificationException}. - * Thus, in the face of concurrent modification, the iterator fails quickly - * and cleanly, rather than risking arbitrary, non-deterministic behavior at - * an undetermined time in the future. - * - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed - * as it is, generally speaking, impossible to make any hard guarantees in the - * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw <tt>ConcurrentModificationException</tt> on a best-effort basis. - * Therefore, it would be wrong to write a program that depended on this - * exception for its correctness: <i>the fail-fast behavior of iterators - * should be used only to detect bugs.</i> - * - * <p>This class is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @param <E> the type of elements maintained by this set - * - * @author Josh Bloch - * @author Neal Gafter - * @see Collection - * @see Set - * @see TreeSet - * @see HashMap - * @since 1.2 - */ - public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, java.io.Serializable diff --git a/notes/src/LinkedHashMap.java b/notes/src/LinkedHashMap.java index 4f80ec4f..946ac9a8 100644 --- a/notes/src/LinkedHashMap.java +++ b/notes/src/LinkedHashMap.java @@ -1,149 +1,7 @@ -/* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ package java.util; import java.io.*; -/** - * <p>Hash table and linked list implementation of the <tt>Map</tt> interface, - * with predictable iteration order. This implementation differs from - * <tt>HashMap</tt> in that it maintains a doubly-linked list running through - * all of its entries. This linked list defines the iteration ordering, - * which is normally the order in which keys were inserted into the map - * (<i>insertion-order</i>). Note that insertion order is not affected - * if a key is <i>re-inserted</i> into the map. (A key <tt>k</tt> is - * reinserted into a map <tt>m</tt> if <tt>m.put(k, v)</tt> is invoked when - * <tt>m.containsKey(k)</tt> would return <tt>true</tt> immediately prior to - * the invocation.) - * - * <p>This implementation spares its clients from the unspecified, generally - * chaotic ordering provided by {@link HashMap} (and {@link Hashtable}), - * without incurring the increased cost associated with {@link TreeMap}. It - * can be used to produce a copy of a map that has the same order as the - * original, regardless of the original map's implementation: - * <pre> - * void foo(Map m) { - * Map copy = new LinkedHashMap(m); - * ... - * } - * </pre> - * This technique is particularly useful if a module takes a map on input, - * copies it, and later returns results whose order is determined by that of - * the copy. (Clients generally appreciate having things returned in the same - * order they were presented.) - * - * <p>A special {@link #LinkedHashMap(int,float,boolean) constructor} is - * provided to create a linked hash map whose order of iteration is the order - * in which its entries were last accessed, from least-recently accessed to - * most-recently (<i>access-order</i>). This kind of map is well-suited to - * building LRU caches. Invoking the <tt>put</tt> or <tt>get</tt> method - * results in an access to the corresponding entry (assuming it exists after - * the invocation completes). The <tt>putAll</tt> method generates one entry - * access for each mapping in the specified map, in the order that key-value - * mappings are provided by the specified map's entry set iterator. <i>No - * other methods generate entry accesses.</i> In particular, operations on - * collection-views do <i>not</i> affect the order of iteration of the backing - * map. - * - * <p>The {@link #removeEldestEntry(Map.Entry)} method may be overridden to - * impose a policy for removing stale mappings automatically when new mappings - * are added to the map. - * - * <p>This class provides all of the optional <tt>Map</tt> operations, and - * permits null elements. Like <tt>HashMap</tt>, it provides constant-time - * performance for the basic operations (<tt>add</tt>, <tt>contains</tt> and - * <tt>remove</tt>), assuming the hash function disperses elements - * properly among the buckets. Performance is likely to be just slightly - * below that of <tt>HashMap</tt>, due to the added expense of maintaining the - * linked list, with one exception: Iteration over the collection-views - * of a <tt>LinkedHashMap</tt> requires time proportional to the <i>size</i> - * of the map, regardless of its capacity. Iteration over a <tt>HashMap</tt> - * is likely to be more expensive, requiring time proportional to its - * <i>capacity</i>. - * - * <p>A linked hash map has two parameters that affect its performance: - * <i>initial capacity</i> and <i>load factor</i>. They are defined precisely - * as for <tt>HashMap</tt>. Note, however, that the penalty for choosing an - * excessively high value for initial capacity is less severe for this class - * than for <tt>HashMap</tt>, as iteration times for this class are unaffected - * by capacity. - * - * <p><strong>Note that this implementation is not synchronized.</strong> - * If multiple threads access a linked hash map concurrently, and at least - * one of the threads modifies the map structurally, it <em>must</em> be - * synchronized externally. This is typically accomplished by - * synchronizing on some object that naturally encapsulates the map. - * - * If no such object exists, the map should be "wrapped" using the - * {@link Collections#synchronizedMap Collections.synchronizedMap} - * method. This is best done at creation time, to prevent accidental - * unsynchronized access to the map:<pre> - * Map m = Collections.synchronizedMap(new LinkedHashMap(...));</pre> - * - * A structural modification is any operation that adds or deletes one or more - * mappings or, in the case of access-ordered linked hash maps, affects - * iteration order. In insertion-ordered linked hash maps, merely changing - * the value associated with a key that is already contained in the map is not - * a structural modification. <strong>In access-ordered linked hash maps, - * merely querying the map with <tt>get</tt> is a structural - * modification.</strong>) - * - * <p>The iterators returned by the <tt>iterator</tt> method of the collections - * returned by all of this class's collection view methods are - * <em>fail-fast</em>: if the map is structurally modified at any time after - * the iterator is created, in any way except through the iterator's own - * <tt>remove</tt> method, the iterator will throw a {@link - * ConcurrentModificationException}. Thus, in the face of concurrent - * modification, the iterator fails quickly and cleanly, rather than risking - * arbitrary, non-deterministic behavior at an undetermined time in the future. - * - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed - * as it is, generally speaking, impossible to make any hard guarantees in the - * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw <tt>ConcurrentModificationException</tt> on a best-effort basis. - * Therefore, it would be wrong to write a program that depended on this - * exception for its correctness: <i>the fail-fast behavior of iterators - * should be used only to detect bugs.</i> - * - * <p>This class is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @param <K> the type of keys maintained by this map - * @param <V> the type of mapped values - * - * @author Josh Bloch - * @see Object#hashCode() - * @see Collection - * @see Map - * @see HashMap - * @see TreeMap - * @see Hashtable - * @since 1.4 - */ - public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V> diff --git a/notes/src/LinkedHashSet.java b/notes/src/LinkedHashSet.java index 399ba80f..9859c3cf 100644 --- a/notes/src/LinkedHashSet.java +++ b/notes/src/LinkedHashSet.java @@ -1,120 +1,6 @@ -/* - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ package java.util; -/** - * <p>Hash table and linked list implementation of the <tt>Set</tt> interface, - * with predictable iteration order. This implementation differs from - * <tt>HashSet</tt> in that it maintains a doubly-linked list running through - * all of its entries. This linked list defines the iteration ordering, - * which is the order in which elements were inserted into the set - * (<i>insertion-order</i>). Note that insertion order is <i>not</i> affected - * if an element is <i>re-inserted</i> into the set. (An element <tt>e</tt> - * is reinserted into a set <tt>s</tt> if <tt>s.add(e)</tt> is invoked when - * <tt>s.contains(e)</tt> would return <tt>true</tt> immediately prior to - * the invocation.) - * - * <p>This implementation spares its clients from the unspecified, generally - * chaotic ordering provided by {@link HashSet}, without incurring the - * increased cost associated with {@link TreeSet}. It can be used to - * produce a copy of a set that has the same order as the original, regardless - * of the original set's implementation: - * <pre> - * void foo(Set s) { - * Set copy = new LinkedHashSet(s); - * ... - * } - * </pre> - * This technique is particularly useful if a module takes a set on input, - * copies it, and later returns results whose order is determined by that of - * the copy. (Clients generally appreciate having things returned in the same - * order they were presented.) - * - * <p>This class provides all of the optional <tt>Set</tt> operations, and - * permits null elements. Like <tt>HashSet</tt>, it provides constant-time - * performance for the basic operations (<tt>add</tt>, <tt>contains</tt> and - * <tt>remove</tt>), assuming the hash function disperses elements - * properly among the buckets. Performance is likely to be just slightly - * below that of <tt>HashSet</tt>, due to the added expense of maintaining the - * linked list, with one exception: Iteration over a <tt>LinkedHashSet</tt> - * requires time proportional to the <i>size</i> of the set, regardless of - * its capacity. Iteration over a <tt>HashSet</tt> is likely to be more - * expensive, requiring time proportional to its <i>capacity</i>. - * - * <p>A linked hash set has two parameters that affect its performance: - * <i>initial capacity</i> and <i>load factor</i>. They are defined precisely - * as for <tt>HashSet</tt>. Note, however, that the penalty for choosing an - * excessively high value for initial capacity is less severe for this class - * than for <tt>HashSet</tt>, as iteration times for this class are unaffected - * by capacity. - * - * <p><strong>Note that this implementation is not synchronized.</strong> - * If multiple threads access a linked hash set concurrently, and at least - * one of the threads modifies the set, it <em>must</em> be synchronized - * externally. This is typically accomplished by synchronizing on some - * object that naturally encapsulates the set. - * - * If no such object exists, the set should be "wrapped" using the - * {@link Collections#synchronizedSet Collections.synchronizedSet} - * method. This is best done at creation time, to prevent accidental - * unsynchronized access to the set: <pre> - * Set s = Collections.synchronizedSet(new LinkedHashSet(...));</pre> - * - * <p>The iterators returned by this class's <tt>iterator</tt> method are - * <em>fail-fast</em>: if the set is modified at any time after the iterator - * is created, in any way except through the iterator's own <tt>remove</tt> - * method, the iterator will throw a {@link ConcurrentModificationException}. - * Thus, in the face of concurrent modification, the iterator fails quickly - * and cleanly, rather than risking arbitrary, non-deterministic behavior at - * an undetermined time in the future. - * - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed - * as it is, generally speaking, impossible to make any hard guarantees in the - * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw <tt>ConcurrentModificationException</tt> on a best-effort basis. - * Therefore, it would be wrong to write a program that depended on this - * exception for its correctness: <i>the fail-fast behavior of iterators - * should be used only to detect bugs.</i> - * - * <p>This class is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @param <E> the type of elements maintained by this set - * - * @author Josh Bloch - * @see Object#hashCode() - * @see Collection - * @see Set - * @see HashSet - * @see TreeSet - * @see Hashtable - * @since 1.4 - */ - public class LinkedHashSet<E> extends HashSet<E> implements Set<E>, Cloneable, java.io.Serializable { diff --git a/notes/src/LinkedList.java b/notes/src/LinkedList.java index 94508da5..10f800de 100644 --- a/notes/src/LinkedList.java +++ b/notes/src/LinkedList.java @@ -1,83 +1,6 @@ -/* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ package java.util; -/** - * Doubly-linked list implementation of the {@code List} and {@code Deque} - * interfaces. Implements all optional list operations, and permits all - * elements (including {@code null}). - * - * <p>All of the operations perform as could be expected for a doubly-linked - * list. Operations that index into the list will traverse the list from - * the beginning or the end, whichever is closer to the specified index. - * - * <p><strong>Note that this implementation is not synchronized.</strong> - * If multiple threads access a linked list concurrently, and at least - * one of the threads modifies the list structurally, it <i>must</i> be - * synchronized externally. (A structural modification is any operation - * that adds or deletes one or more elements; merely setting the value of - * an element is not a structural modification.) This is typically - * accomplished by synchronizing on some object that naturally - * encapsulates the list. - * - * If no such object exists, the list should be "wrapped" using the - * {@link Collections#synchronizedList Collections.synchronizedList} - * method. This is best done at creation time, to prevent accidental - * unsynchronized access to the list:<pre> - * List list = Collections.synchronizedList(new LinkedList(...));</pre> - * - * <p>The iterators returned by this class's {@code iterator} and - * {@code listIterator} methods are <i>fail-fast</i>: if the list is - * structurally modified at any time after the iterator is created, in - * any way except through the Iterator's own {@code remove} or - * {@code add} methods, the iterator will throw a {@link - * ConcurrentModificationException}. Thus, in the face of concurrent - * modification, the iterator fails quickly and cleanly, rather than - * risking arbitrary, non-deterministic behavior at an undetermined - * time in the future. - * - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed - * as it is, generally speaking, impossible to make any hard guarantees in the - * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw {@code ConcurrentModificationException} on a best-effort basis. - * Therefore, it would be wrong to write a program that depended on this - * exception for its correctness: <i>the fail-fast behavior of iterators - * should be used only to detect bugs.</i> - * - * <p>This class is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @author Josh Bloch - * @see List - * @see ArrayList - * @since 1.2 - * @param <E> the type of elements held in this collection - */ - public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, java.io.Serializable diff --git a/notes/src/PriorityQueue.java b/notes/src/PriorityQueue.java index b4416ab2..b76c1d96 100644 --- a/notes/src/PriorityQueue.java +++ b/notes/src/PriorityQueue.java @@ -1,82 +1,5 @@ -/* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - package java.util; -/** - * An unbounded priority {@linkplain Queue queue} based on a priority heap. - * The elements of the priority queue are ordered according to their - * {@linkplain Comparable natural ordering}, or by a {@link Comparator} - * provided at queue construction time, depending on which constructor is - * used. A priority queue does not permit {@code null} elements. - * A priority queue relying on natural ordering also does not permit - * insertion of non-comparable objects (doing so may result in - * {@code ClassCastException}). - * - * <p>The <em>head</em> of this queue is the <em>least</em> element - * with respect to the specified ordering. If multiple elements are - * tied for least value, the head is one of those elements -- ties are - * broken arbitrarily. The queue retrieval operations {@code poll}, - * {@code remove}, {@code peek}, and {@code element} access the - * element at the head of the queue. - * - * <p>A priority queue is unbounded, but has an internal - * <i>capacity</i> governing the size of an array used to store the - * elements on the queue. It is always at least as large as the queue - * size. As elements are added to a priority queue, its capacity - * grows automatically. The details of the growth policy are not - * specified. - * - * <p>This class and its iterator implement all of the - * <em>optional</em> methods of the {@link Collection} and {@link - * Iterator} interfaces. The Iterator provided in method {@link - * #iterator()} is <em>not</em> guaranteed to traverse the elements of - * the priority queue in any particular order. If you need ordered - * traversal, consider using {@code Arrays.sort(pq.toArray())}. - * - * <p> <strong>Note that this implementation is not synchronized.</strong> - * Multiple threads should not access a {@code PriorityQueue} - * instance concurrently if any of the threads modifies the queue. - * Instead, use the thread-safe {@link - * java.util.concurrent.PriorityBlockingQueue} class. - * - * <p>Implementation note: this implementation provides - * O(log(n)) time for the enqueing and dequeing methods - * ({@code offer}, {@code poll}, {@code remove()} and {@code add}); - * linear time for the {@code remove(Object)} and {@code contains(Object)} - * methods; and constant time for the retrieval methods - * ({@code peek}, {@code element}, and {@code size}). - * - * <p>This class is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @since 1.5 - * @author Josh Bloch, Doug Lea - * @param <E> the type of elements held in this collection - */ public class PriorityQueue<E> extends AbstractQueue<E> implements java.io.Serializable { diff --git a/notes/src/Queue.java b/notes/src/Queue.java index 124cc449..05088a39 100644 --- a/notes/src/Queue.java +++ b/notes/src/Queue.java @@ -1,146 +1,6 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * This file is available under and governed by the GNU General Public - * License version 2 only, as published by the Free Software Foundation. - * However, the following notice accompanied the original version of this - * file: - * - * Written by Doug Lea with assistance from members of JCP JSR-166 - * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/publicdomain/zero/1.0/ - */ package java.util; -/** - * A collection designed for holding elements prior to processing. - * Besides basic {@link java.util.Collection Collection} operations, - * queues provide additional insertion, extraction, and inspection - * operations. Each of these methods exists in two forms: one throws - * an exception if the operation fails, the other returns a special - * value (either <tt>null</tt> or <tt>false</tt>, depending on the - * operation). The latter form of the insert operation is designed - * specifically for use with capacity-restricted <tt>Queue</tt> - * implementations; in most implementations, insert operations cannot - * fail. - * - * <p> - * <table BORDER CELLPADDING=3 CELLSPACING=1> - * <tr> - * <td></td> - * <td ALIGN=CENTER><em>Throws exception</em></td> - * <td ALIGN=CENTER><em>Returns special value</em></td> - * </tr> - * <tr> - * <td><b>Insert</b></td> - * <td>{@link #add add(e)}</td> - * <td>{@link #offer offer(e)}</td> - * </tr> - * <tr> - * <td><b>Remove</b></td> - * <td>{@link #remove remove()}</td> - * <td>{@link #poll poll()}</td> - * </tr> - * <tr> - * <td><b>Examine</b></td> - * <td>{@link #element element()}</td> - * <td>{@link #peek peek()}</td> - * </tr> - * </table> - * - * <p>Queues typically, but do not necessarily, order elements in a - * FIFO (first-in-first-out) manner. Among the exceptions are - * priority queues, which order elements according to a supplied - * comparator, or the elements' natural ordering, and LIFO queues (or - * stacks) which order the elements LIFO (last-in-first-out). - * Whatever the ordering used, the <em>head</em> of the queue is that - * element which would be removed by a call to {@link #remove() } or - * {@link #poll()}. In a FIFO queue, all new elements are inserted at - * the <em> tail</em> of the queue. Other kinds of queues may use - * different placement rules. Every <tt>Queue</tt> implementation - * must specify its ordering properties. - * - * <p>The {@link #offer offer} method inserts an element if possible, - * otherwise returning <tt>false</tt>. This differs from the {@link - * java.util.Collection#add Collection.add} method, which can fail to - * add an element only by throwing an unchecked exception. The - * <tt>offer</tt> method is designed for use when failure is a normal, - * rather than exceptional occurrence, for example, in fixed-capacity - * (or "bounded") queues. - * - * <p>The {@link #remove()} and {@link #poll()} methods remove and - * return the head of the queue. - * Exactly which element is removed from the queue is a - * function of the queue's ordering policy, which differs from - * implementation to implementation. The <tt>remove()</tt> and - * <tt>poll()</tt> methods differ only in their behavior when the - * queue is empty: the <tt>remove()</tt> method throws an exception, - * while the <tt>poll()</tt> method returns <tt>null</tt>. - * - * <p>The {@link #element()} and {@link #peek()} methods return, but do - * not remove, the head of the queue. - * - * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue - * methods</i>, which are common in concurrent programming. These methods, - * which wait for elements to appear or for space to become available, are - * defined in the {@link java.util.concurrent.BlockingQueue} interface, which - * extends this interface. - * - * <p><tt>Queue</tt> implementations generally do not allow insertion - * of <tt>null</tt> elements, although some implementations, such as - * {@link LinkedList}, do not prohibit insertion of <tt>null</tt>. - * Even in the implementations that permit it, <tt>null</tt> should - * not be inserted into a <tt>Queue</tt>, as <tt>null</tt> is also - * used as a special return value by the <tt>poll</tt> method to - * indicate that the queue contains no elements. - * - * <p><tt>Queue</tt> implementations generally do not define - * element-based versions of methods <tt>equals</tt> and - * <tt>hashCode</tt> but instead inherit the identity based versions - * from class <tt>Object</tt>, because element-based equality is not - * always well-defined for queues with the same elements but different - * ordering properties. - * - * - * <p>This interface is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @see java.util.Collection - * @see LinkedList - * @see PriorityQueue - * @see java.util.concurrent.LinkedBlockingQueue - * @see java.util.concurrent.BlockingQueue - * @see java.util.concurrent.ArrayBlockingQueue - * @see java.util.concurrent.LinkedBlockingQueue - * @see java.util.concurrent.PriorityBlockingQueue - * @since 1.5 - * @author Doug Lea - * @param <E> the type of elements held in this collection - */ public interface Queue<E> extends Collection<E> { /** * Inserts the specified element into this queue if it is possible to do so diff --git a/notes/src/Stack.java b/notes/src/Stack.java index ebea11e5..96acf05b 100644 --- a/notes/src/Stack.java +++ b/notes/src/Stack.java @@ -1,50 +1,6 @@ -/* - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ package java.util; -/** - * The <code>Stack</code> class represents a last-in-first-out - * (LIFO) stack of objects. It extends class <tt>Vector</tt> with five - * operations that allow a vector to be treated as a stack. The usual - * <tt>push</tt> and <tt>pop</tt> operations are provided, as well as a - * method to <tt>peek</tt> at the top item on the stack, a method to test - * for whether the stack is <tt>empty</tt>, and a method to <tt>search</tt> - * the stack for an item and discover how far it is from the top. - * <p> - * When a stack is first created, it contains no items. - * - * <p>A more complete and consistent set of LIFO stack operations is - * provided by the {@link Deque} interface and its implementations, which - * should be used in preference to this class. For example: - * <pre> {@code - * Deque<Integer> stack = new ArrayDeque<Integer>();}</pre> - * - * @author Jonathan Payne - * @since JDK1.0 - */ public class Stack<E> extends Vector<E> { /** diff --git a/notes/src/TreeMap.java b/notes/src/TreeMap.java index 6e92b8d1..120b46cf 100644 --- a/notes/src/TreeMap.java +++ b/notes/src/TreeMap.java @@ -1,108 +1,6 @@ -/* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ package java.util; -/** - * A Red-Black tree based {@link NavigableMap} implementation. - * The map is sorted according to the {@linkplain Comparable natural - * ordering} of its keys, or by a {@link Comparator} provided at map - * creation time, depending on which constructor is used. - * - * <p>This implementation provides guaranteed log(n) time cost for the - * {@code containsKey}, {@code get}, {@code put} and {@code remove} - * operations. Algorithms are adaptations of those in Cormen, Leiserson, and - * Rivest's <em>Introduction to Algorithms</em>. - * - * <p>Note that the ordering maintained by a tree map, like any sorted map, and - * whether or not an explicit comparator is provided, must be <em>consistent - * with {@code equals}</em> if this sorted map is to correctly implement the - * {@code Map} interface. (See {@code Comparable} or {@code Comparator} for a - * precise definition of <em>consistent with equals</em>.) This is so because - * the {@code Map} interface is defined in terms of the {@code equals} - * operation, but a sorted map performs all key comparisons using its {@code - * compareTo} (or {@code compare}) method, so two keys that are deemed equal by - * this method are, from the standpoint of the sorted map, equal. The behavior - * of a sorted map <em>is</em> well-defined even if its ordering is - * inconsistent with {@code equals}; it just fails to obey the general contract - * of the {@code Map} interface. - * - * <p><strong>Note that this implementation is not synchronized.</strong> - * If multiple threads access a map concurrently, and at least one of the - * threads modifies the map structurally, it <em>must</em> be synchronized - * externally. (A structural modification is any operation that adds or - * deletes one or more mappings; merely changing the value associated - * with an existing key is not a structural modification.) This is - * typically accomplished by synchronizing on some object that naturally - * encapsulates the map. - * If no such object exists, the map should be "wrapped" using the - * {@link Collections#synchronizedSortedMap Collections.synchronizedSortedMap} - * method. This is best done at creation time, to prevent accidental - * unsynchronized access to the map: <pre> - * SortedMap m = Collections.synchronizedSortedMap(new TreeMap(...));</pre> - * - * <p>The iterators returned by the {@code iterator} method of the collections - * returned by all of this class's "collection view methods" are - * <em>fail-fast</em>: if the map is structurally modified at any time after - * the iterator is created, in any way except through the iterator's own - * {@code remove} method, the iterator will throw a {@link - * ConcurrentModificationException}. Thus, in the face of concurrent - * modification, the iterator fails quickly and cleanly, rather than risking - * arbitrary, non-deterministic behavior at an undetermined time in the future. - * - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed - * as it is, generally speaking, impossible to make any hard guarantees in the - * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw {@code ConcurrentModificationException} on a best-effort basis. - * Therefore, it would be wrong to write a program that depended on this - * exception for its correctness: <em>the fail-fast behavior of iterators - * should be used only to detect bugs.</em> - * - * <p>All {@code Map.Entry} pairs returned by methods in this class - * and its views represent snapshots of mappings at the time they were - * produced. They do <strong>not</strong> support the {@code Entry.setValue} - * method. (Note however that it is possible to change mappings in the - * associated map using {@code put}.) - * - * <p>This class is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @param <K> the type of keys maintained by this map - * @param <V> the type of mapped values - * - * @author Josh Bloch and Doug Lea - * @see Map - * @see HashMap - * @see Hashtable - * @see Comparable - * @see Comparator - * @see Collection - * @since 1.2 - */ - public class TreeMap<K,V> extends AbstractMap<K,V> implements NavigableMap<K,V>, Cloneable, java.io.Serializable diff --git a/notes/src/TreeSet.java b/notes/src/TreeSet.java index 3eee2a8e..1f0d9490 100644 --- a/notes/src/TreeSet.java +++ b/notes/src/TreeSet.java @@ -1,94 +1,6 @@ -/* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ package java.util; -/** - * A {@link NavigableSet} implementation based on a {@link TreeMap}. - * The elements are ordered using their {@linkplain Comparable natural - * ordering}, or by a {@link Comparator} provided at set creation - * time, depending on which constructor is used. - * - * <p>This implementation provides guaranteed log(n) time cost for the basic - * operations ({@code add}, {@code remove} and {@code contains}). - * - * <p>Note that the ordering maintained by a set (whether or not an explicit - * comparator is provided) must be <i>consistent with equals</i> if it is to - * correctly implement the {@code Set} interface. (See {@code Comparable} - * or {@code Comparator} for a precise definition of <i>consistent with - * equals</i>.) This is so because the {@code Set} interface is defined in - * terms of the {@code equals} operation, but a {@code TreeSet} instance - * performs all element comparisons using its {@code compareTo} (or - * {@code compare}) method, so two elements that are deemed equal by this method - * are, from the standpoint of the set, equal. The behavior of a set - * <i>is</i> well-defined even if its ordering is inconsistent with equals; it - * just fails to obey the general contract of the {@code Set} interface. - * - * <p><strong>Note that this implementation is not synchronized.</strong> - * If multiple threads access a tree set concurrently, and at least one - * of the threads modifies the set, it <i>must</i> be synchronized - * externally. This is typically accomplished by synchronizing on some - * object that naturally encapsulates the set. - * If no such object exists, the set should be "wrapped" using the - * {@link Collections#synchronizedSortedSet Collections.synchronizedSortedSet} - * method. This is best done at creation time, to prevent accidental - * unsynchronized access to the set: <pre> - * SortedSet s = Collections.synchronizedSortedSet(new TreeSet(...));</pre> - * - * <p>The iterators returned by this class's {@code iterator} method are - * <i>fail-fast</i>: if the set is modified at any time after the iterator is - * created, in any way except through the iterator's own {@code remove} - * method, the iterator will throw a {@link ConcurrentModificationException}. - * Thus, in the face of concurrent modification, the iterator fails quickly - * and cleanly, rather than risking arbitrary, non-deterministic behavior at - * an undetermined time in the future. - * - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed - * as it is, generally speaking, impossible to make any hard guarantees in the - * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw {@code ConcurrentModificationException} on a best-effort basis. - * Therefore, it would be wrong to write a program that depended on this - * exception for its correctness: <i>the fail-fast behavior of iterators - * should be used only to detect bugs.</i> - * - * <p>This class is a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. - * - * @param <E> the type of elements maintained by this set - * - * @author Josh Bloch - * @see Collection - * @see Set - * @see HashSet - * @see Comparable - * @see Comparator - * @see TreeMap - * @since 1.2 - */ - public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, java.io.Serializable { diff --git a/notes/src/Vector.java b/notes/src/Vector.java index 0d69591a..41cc0277 100644 --- a/notes/src/Vector.java +++ b/notes/src/Vector.java @@ -1,81 +1,5 @@ -/* - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - package java.util; -/** - * The {@code Vector} class implements a growable array of - * objects. Like an array, it contains components that can be - * accessed using an integer index. However, the size of a - * {@code Vector} can grow or shrink as needed to accommodate - * adding and removing items after the {@code Vector} has been created. - * - * <p>Each vector tries to optimize storage management by maintaining a - * {@code capacity} and a {@code capacityIncrement}. The - * {@code capacity} is always at least as large as the vector - * size; it is usually larger because as components are added to the - * vector, the vector's storage increases in chunks the size of - * {@code capacityIncrement}. An application can increase the - * capacity of a vector before inserting a large number of - * components; this reduces the amount of incremental reallocation. - * - * <p><a name="fail-fast"/> - * The iterators returned by this class's {@link #iterator() iterator} and - * {@link #listIterator(int) listIterator} methods are <em>fail-fast</em>: - * if the vector is structurally modified at any time after the iterator is - * created, in any way except through the iterator's own - * {@link ListIterator#remove() remove} or - * {@link ListIterator#add(Object) add} methods, the iterator will throw a - * {@link ConcurrentModificationException}. Thus, in the face of - * concurrent modification, the iterator fails quickly and cleanly, rather - * than risking arbitrary, non-deterministic behavior at an undetermined - * time in the future. The {@link Enumeration Enumerations} returned by - * the {@link #elements() elements} method are <em>not</em> fail-fast. - * - * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed - * as it is, generally speaking, impossible to make any hard guarantees in the - * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw {@code ConcurrentModificationException} on a best-effort basis. - * Therefore, it would be wrong to write a program that depended on this - * exception for its correctness: <i>the fail-fast behavior of iterators - * should be used only to detect bugs.</i> - * - * <p>As of the Java 2 platform v1.2, this class was retrofitted to - * implement the {@link List} interface, making it a member of the - * <a href="{@docRoot}/../technotes/guides/collections/index.html"> - * Java Collections Framework</a>. Unlike the new collection - * implementations, {@code Vector} is synchronized. If a thread-safe - * implementation is not needed, it is recommended to use {@link - * ArrayList} in place of {@code Vector}. - * - * @author Lee Boynton - * @author Jonathan Payne - * @see Collection - * @see LinkedList - * @since JDK1.0 - */ public class Vector<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable