1 7 package org.jboss.cache.eviction; 8 9 import org.jboss.cache.Fqn; 10 11 import java.util.Iterator ; 12 import java.util.LinkedHashMap ; 13 import java.util.Map ; 14 15 21 public class FIFOQueue implements EvictionQueue 22 { 23 private Map nodeMap; 24 private int numElements = 0; 25 26 FIFOQueue() 27 { 28 nodeMap = new LinkedHashMap (); 29 } 32 33 public NodeEntry getFirstNodeEntry() 34 { 35 41 42 if (nodeMap.size() > 0) 44 { 45 return (NodeEntry) nodeMap.values().iterator().next(); 46 } 47 48 return null; 49 } 50 51 public NodeEntry getNodeEntry(Fqn fqn) 52 { 53 return (NodeEntry) nodeMap.get(fqn); 54 } 55 56 public NodeEntry getNodeEntry(String fqn) 57 { 58 return this.getNodeEntry(Fqn.fromString(fqn)); 59 } 60 61 public boolean containsNodeEntry(NodeEntry entry) 62 { 63 Fqn fqn = entry.getFqn(); 64 return this.getNodeEntry(fqn) != null; 65 } 66 67 public void removeNodeEntry(NodeEntry entry) 68 { 69 NodeEntry e = (NodeEntry) nodeMap.remove(entry.getFqn()); 70 this.numElements -= e.getNumberOfElements(); 71 } 72 73 public void addNodeEntry(NodeEntry entry) 74 { 75 if (!this.containsNodeEntry(entry)) 76 { 77 entry.queue = this; 78 nodeMap.put(entry.getFqn(), entry); 79 this.numElements += entry.getNumberOfElements(); 80 } 81 } 82 83 public int getNumberOfNodes() 84 { 85 return nodeMap.size(); 86 } 87 88 public int getNumberOfElements() 89 { 90 return this.numElements; 91 } 92 93 public void modifyElementCount(int difference) 94 { 95 this.numElements += difference; 96 } 97 98 public void clear() 99 { 100 nodeMap.clear(); 101 this.numElements = 0; 102 } 103 104 public Iterator iterate() 105 { 106 return nodeMap.values().iterator(); 107 } 108 } 109 | Popular Tags |