1 package org.gffs.cache;
4 * Copyright 2006 University of Virginia
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
7 * obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
13 * and limitations under the License.
16 abstract class CacheList<KeyType, DataType>
18 protected int _myRole;
20 protected RoleBasedCacheNode<KeyType, DataType> _head;
21 protected RoleBasedCacheNode<KeyType, DataType> _tail;
23 protected CacheList(int role)
30 public abstract void insert(RoleBasedCacheNode<KeyType, DataType> node);
32 public RoleBasedCacheNode<KeyType, DataType> removeFirst()
37 RoleBasedCacheNode<KeyType, DataType> ret = _head;
39 _head = _head.getNext(_myRole);
41 _head.setPrevious(_myRole, null);
45 ret.clearLinks(_myRole);
49 public RoleBasedCacheNode<KeyType, DataType> peekFirst()
57 public void remove(RoleBasedCacheNode<KeyType, DataType> node)
59 if (node.getPrevious(_myRole) == null) // At the head of the list
60 _head = node.getNext(_myRole);
62 node.getPrevious(_myRole).setNext(_myRole, node.getNext(_myRole));
64 if (node.getNext(_myRole) == null) // At the tail of the list
65 _tail = node.getPrevious(_myRole);
67 node.getNext(_myRole).setPrevious(_myRole, node.getPrevious(_myRole));
69 node.clearLinks(_myRole);