1 11 package org.eclipse.help.ui.internal.views; 12 13 import java.util.LinkedList ; 14 15 public class ReusableHelpPartHistory { 16 private static final int CAPACITY = 50; 17 private LinkedList queue; 18 private int cursor = -1; 19 private boolean blocked; 20 21 public ReusableHelpPartHistory() { 22 queue = new LinkedList (); 23 } 24 25 public void addEntry(HistoryEntry entry) { 26 if (cursor!= -1) { 27 int extra = queue.size()-1 -cursor; 31 if (extra>0) { 32 for (int i=extra; i>0; i--) { 33 queue.removeLast(); 34 } 35 } 36 } 37 queue.add(entry); 38 if (queue.size()>CAPACITY) 39 queue.removeFirst(); 40 cursor = queue.size()-1; 41 } 42 43 public boolean hasNext() { 44 return cursor != -1 && cursor < queue.size()-1; 45 } 46 47 public boolean hasPrev() { 48 return cursor != -1 && cursor > 0; 49 } 50 51 public HistoryEntry getNext() { 52 return hasNext()?(HistoryEntry)queue.get(cursor+1):null; 53 } 54 55 public HistoryEntry getPrev() { 56 return hasPrev() ? (HistoryEntry)queue.get(cursor-1):null; 57 } 58 59 public HistoryEntry next() { 60 if (hasNext()) { 61 return (HistoryEntry)queue.get(++cursor); 62 } 63 return null; 64 } 65 public HistoryEntry prev() { 66 if (hasPrev()) { 67 return (HistoryEntry)queue.get(--cursor); 68 } 69 return null; 70 } 71 74 public boolean isBlocked() { 75 return blocked; 76 } 77 80 public void setBlocked(boolean blocked) { 81 this.blocked = blocked; 82 } 83 } 84 | Popular Tags |