1 /*
2 * Copyright (c) 2002-2012, the original author or authors.
3 *
4 * This software is distributable under the BSD license. See the terms of the
5 * BSD license in the documentation provided with this software.
6 *
7 * http://www.opensource.org/licenses/bsd-license.php
8 */
9 package jline.console.history;
10
11 import java.util.Iterator;
12 import java.util.ListIterator;
13
14 /**
15 * Console history.
16 *
17 * @author <a href="mailto:mwp1@cornell.edu">Marc Prud'hommeaux</a>
18 * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
19 * @since 2.3
20 */
21 public interface History
22 extends Iterable<History.Entry>
23 {
24 int size();
25
26 boolean isEmpty();
27
28 int index();
29
30 void clear();
31
32 CharSequence get(int index);
33
34 void add(CharSequence line);
35
36 /**
37 * Set the history item at the given index to the given CharSequence.
38 *
39 * @param index the index of the history offset
40 * @param item the new item
41 * @since 2.7
42 */
43 void set(int index, CharSequence item);
44
45 /**
46 * Remove the history element at the given index.
47 *
48 * @param i the index of the element to remove
49 * @return the removed element
50 * @since 2.7
51 */
52 CharSequence remove(int i);
53
54 /**
55 * Remove the first element from history.
56 *
57 * @return the removed element
58 * @since 2.7
59 */
60 CharSequence removeFirst();
61
62 /**
63 * Remove the last element from history
64 *
65 * @return the removed element
66 * @since 2.7
67 */
68 CharSequence removeLast();
69
70 void replace(CharSequence item);
71
72 //
73 // Entries
74 //
75
76 interface Entry
77 {
78 int index();
79
80 CharSequence value();
81 }
82
83 ListIterator<Entry> entries(int index);
84
85 ListIterator<Entry> entries();
86
87 Iterator<Entry> iterator();
88
89 //
90 // Navigation
91 //
92
93 CharSequence current();
94
95 boolean previous();
96
97 boolean next();
98
99 boolean moveToFirst();
100
101 boolean moveToLast();
102
103 boolean moveTo(int index);
104
105 void moveToEnd();
106 }