01: // SyncLRUList.java
02: // $Id: SyncLRUList.java,v 1.7 2000/08/04 09:33:06 ylafon 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: public class SyncLRUList extends LRUList {
09: public synchronized void toHead(LRUAble node) {
10: // First remove it if it's in the list already
11: _remove(node);
12:
13: // Then link it to the front
14: node.setNext(head.next);
15: node.setPrev(head);
16: head.next.setPrev(node);
17: head.next = node;
18: }
19:
20: public synchronized void toTail(LRUAble node) {
21: // First remove it if it's in the list already
22: _remove(node);
23:
24: // Then link it to the back
25: node.setPrev(tail.prev);
26: node.setNext(tail);
27: tail.prev.setNext(node);
28: tail.prev = node;
29:
30: }
31:
32: private final synchronized void _remove(LRUAble node) {
33: LRUAble itsPrev, itsNext;
34: itsPrev = node.getPrev();
35: // note assumption: if its prev is not null, neither is its next
36: if (itsPrev == null)
37: return;
38: itsNext = node.getNext();
39: itsPrev.setNext(itsNext);
40: itsNext.setPrev(itsPrev);
41: }
42:
43: public final synchronized LRUAble remove(LRUAble node) {
44: _remove(node);
45: node.setNext((LRUAble) null);
46: node.setPrev((LRUAble) null);
47: return node;
48: }
49:
50: public final synchronized LRUAble getTail() {
51: LRUAble prev = tail.prev;
52: return (prev == head) ? null : prev;
53: }
54:
55: public final synchronized LRUAble getHead() {
56: LRUAble next = head.next;
57: return (next == tail) ? null : next;
58: }
59:
60: public final synchronized LRUAble removeTail() {
61: if (tail.prev != head)
62: return remove(tail.prev);
63: return null;
64: }
65:
66: public final synchronized LRUAble getNext(LRUAble node) {
67: LRUAble next = node.getNext();
68: return ((next == tail) || (next == head)) ? null : next;
69: }
70:
71: public final synchronized LRUAble getPrev(LRUAble node) {
72: LRUAble prev = node.getPrev();
73: return ((prev == tail) || (prev == head)) ? null : prev;
74: }
75:
76: }
|