????afterNodeAccess????
void afterNodeAccess(Node<K??V> e) { // move node to last
LinkedHashMap.Entry<K??V> last;
// ?????????accessOrder????????????????????
if (accessOrder && (last = tail) != e) {
LinkedHashMap.Entry<K??V> p =
(LinkedHashMap.Entry<K??V>)e?? b = p.before?? a = p.after;
p.after = null;
if (b == null)
head = a;
else
b.after = a;
if (a != null)
a.before = b;
else
last = b;
if (last == null)
head = p;
else {
p.before = last;
last.after = p;
}
tail = p;
++modCount;
}
}
????????????put???????????????????????????????????????????????????????
????afterNodeInsertion????
????void afterNodeInsertion(boolean evict) { // possibly remove eldest
????LinkedHashMap.Entry<K??V> first;
????// ?????????????????????????????
????if (evict && (first = head) != null && removeEldestEntry(first)) {
????K key = first.key;
????removeNode(hash(key)?? key?? null?? false?? true);
????}
????}
????????????????removeEldestEntry??????????????????????????????
????afterNodeRemoval????
????void afterNodeRemoval(Node<K??V> e) { // unlink
????// ??????????????
????LinkedHashMap.Entry<K??V> p =
????(LinkedHashMap.Entry<K??V>)e?? b = p.before?? a = p.after;
????p.before = p.after = null;
????if (b == null)
????head = a;
????else
????b.after = a;
????if (a == null)
????tail = b;
????else
????a.before = b;
????}
????????????????????????????????????????????????
?????????????3????????????????????????????????????е???????????????????????????Щ????????飬????????????????н?????????eldest??youngest??
????3. put??get????
????put??????LinkedHashMap??δ????????????????afterNodeAccess??afterNodeInsertion?????????????get????????????????????afterNodeAccess??????????????????get?????????????
????public V get(Object key) {
????Node<K??V> e;
????if ((e = getNode(hash(key)?? key)) == null)
????return null;
????if (accessOrder)
????afterNodeAccess(e);
????return e.value;
????}
????????????????accessOrder???£??????get????put???????????????structural modification????????????????????
????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. In access-ordered linked hash maps?? merely querying the map with get is a structural modification.
?????????????ConcurrentModificationException with LinkedHashMap?????????
?????????LinkedHashMap??????HashMap???????????????????????????????????????LinkedHashMap???????????????????????????????????з???????????????:-)