Changeset 30671 in osm for applications/editors/josm/plugins/CommandLine/src/CommandLine/History.java
- Timestamp:
- 2014-09-23T12:02:21+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/CommandLine/src/CommandLine/History.java
r25038 r30671 1 1 /* 2 2 * History.java 3 * 3 * 4 4 * Copyright 2010 Hind <foxhind@gmail.com> 5 * 5 * 6 6 */ 7 7 8 8 package CommandLine; 9 9 … … 11 11 12 12 public class History { 13 private LinkedList<String> historyList; 14 private int maxLen; 15 private int num; 16 17 public History(int len) { 18 num = 0; 19 maxLen = len; 20 historyList = new LinkedList<String>(); 21 } 22 23 public void addItem(String item) { 24 if (!item.equals("")) { 25 String prevItem = historyList.peekFirst(); 26 if (prevItem == null) { 27 historyList.addFirst(item); 28 } 29 else { 30 if (!prevItem.equalsIgnoreCase(item)) 31 historyList.addFirst(item); 32 } 33 if (historyList.size() > maxLen) { 34 historyList.removeLast(); 35 } 36 } 37 num = -1; 38 } 39 40 public String getPrevItem() { 41 num += 1; 42 if (num >= historyList.size()) { 43 num = historyList.size() - 1; 44 } 45 if (num < 0) { 46 num = -1; 47 return ""; 48 } 49 return historyList.get(num); 50 } 51 52 public String getLastItem() { 53 if (historyList.size() > 0) 54 return historyList.get(0); 55 return ""; 56 } 13 private final LinkedList<String> historyList; 14 private final int maxLen; 15 private int num; 57 16 58 public String getNextItem() { 59 num -= 1; 60 if (num < 0) { 61 num = -1; 62 return ""; 63 } 64 return historyList.get(num); 65 } 17 public History(int len) { 18 num = 0; 19 maxLen = len; 20 historyList = new LinkedList<>(); 21 } 22 23 public void addItem(String item) { 24 if (!item.equals("")) { 25 String prevItem = historyList.peekFirst(); 26 if (prevItem == null) { 27 historyList.addFirst(item); 28 } 29 else { 30 if (!prevItem.equalsIgnoreCase(item)) 31 historyList.addFirst(item); 32 } 33 if (historyList.size() > maxLen) { 34 historyList.removeLast(); 35 } 36 } 37 num = -1; 38 } 39 40 public String getPrevItem() { 41 num += 1; 42 if (num >= historyList.size()) { 43 num = historyList.size() - 1; 44 } 45 if (num < 0) { 46 num = -1; 47 return ""; 48 } 49 return historyList.get(num); 50 } 51 52 public String getLastItem() { 53 if (historyList.size() > 0) 54 return historyList.get(0); 55 return ""; 56 } 57 58 public String getNextItem() { 59 num -= 1; 60 if (num < 0) { 61 num = -1; 62 return ""; 63 } 64 return historyList.get(num); 65 } 66 66 } 67 67
Note:
See TracChangeset
for help on using the changeset viewer.
