1 33 34 package edu.rice.cs.drjava.model; 35 36 import java.util.List ; 37 import java.util.LinkedList ; 38 39 42 public class ClipboardHistoryModel { 43 44 private int _maxSize; 45 46 47 private LinkedList <String > _history = new LinkedList <String >(); 48 49 50 private static ClipboardHistoryModel ONLY = null; 51 52 53 public static synchronized ClipboardHistoryModel singleton() { 54 if (ONLY==null) { 55 ONLY = new ClipboardHistoryModel(10); 56 } 57 return ONLY; 58 } 59 60 62 private ClipboardHistoryModel(int maxSize) { 63 _maxSize = maxSize; 64 } 65 66 67 public void resize(int maxSize) { 68 _maxSize = maxSize; 69 while (_history.size()>_maxSize) { _history.removeFirst(); } 70 } 71 72 74 public synchronized void put(String s) { 75 _history.remove(s); 76 _history.add(s); 77 while (_history.size()>_maxSize) { _history.removeFirst(); } 78 } 79 80 81 public synchronized List <String > getStrings() { 82 return new LinkedList <String >(_history); 83 } 84 85 86 public synchronized String getMostRecent() { 87 if (_history.size()==0) { return null; } 88 else { return _history.getLast(); } 89 } 90 } 91 | Popular Tags |