01: // AsyncLRUList.java
02: // $Id: AsyncLRUList.java,v 1.10 1998/01/22 14:24:58 bmahe Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.util;
07:
08: // All locks allocated from left to right
09:
10: public class AsyncLRUList extends LRUList {
11:
12: public final synchronized void toHead(LRUAble node) {
13: _remove(node);
14: if (head.next != null) {
15: node.setNext(head.next);
16: head.next.setPrev(node);
17: node.setPrev(head);
18: head.next = node;
19: } else {
20: node.setNext(head.next);
21: // head.next.setPrev(node) ;
22: node.setPrev(head);
23: head.next = node;
24: }
25: }
26:
27: public final synchronized void toTail(LRUAble node) {
28: _remove(node);
29: if (tail.prev != null) {
30: node.setPrev(tail.prev);
31: tail.prev.setNext(node);
32: node.setNext(tail);
33: tail.prev = node;
34: } else {
35: node.setPrev(tail.prev);
36: // tail.prev.setNext(node) ;
37: node.setNext(tail);
38: tail.prev = node;
39: }
40: }
41:
42: private final synchronized void _remove(LRUAble node) {
43: LRUAble itsPrev = node.getPrev();
44: if (itsPrev == null)
45: return;
46: LRUAble itsNext = node.getNext();
47: node.setNext(null);
48: node.setPrev(null);
49: itsPrev.setNext(itsNext);
50: if (itsNext == null)
51: return;
52: itsNext.setPrev(itsPrev);
53: }
54:
55: public final synchronized LRUAble remove(LRUAble node) {
56: _remove(node);
57: node.setNext((LRUAble) null);
58: node.setPrev((LRUAble) null);
59: return node;
60: }
61:
62: public final synchronized LRUAble getTail() {
63: if (tail.prev == null)
64: return null;
65: LRUAble prev = tail.prev;
66: return (prev == head) ? null : prev;
67: }
68:
69: public final synchronized LRUAble getHead() {
70: LRUAble next = head.next;
71: return (next == tail) ? null : next;
72: }
73:
74: public final synchronized LRUAble removeTail() {
75: return (tail.prev != head) ? remove(tail.prev) : null;
76: }
77:
78: public final synchronized LRUAble getNext(LRUAble node) {
79: LRUAble next = node.getNext();
80: return ((next == tail) || (next == head)) ? null : next;
81: }
82:
83: public final synchronized LRUAble getPrev(LRUAble node) {
84: LRUAble prev = node.getPrev();
85: return ((prev == tail) || (prev == head)) ? null : prev;
86: }
87:
88: }
|