blob: d1f6b1c14eb54a501dae366e6a2377ea39e6e620 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
package net.java.sip.communicator.impl.history;
import java.util.*;
import net.java.sip.communicator.service.history.*;
/**
* This implementation is the same as DefaultQueryResultSet but the
* container holding the records is LinkedList - so guarantees that values are ordered
*
* @param <T> element type of query
* @author Damian Minkov
*/
public class OrderedQueryResultSet<T>
implements QueryResultSet<T>
{
private LinkedList<T> records = null;
private int currentPos = -1;
/**
* Constructor.
*
* @param records the <tt>Set</tt> of records
*/
public OrderedQueryResultSet(Set<T> records)
{
this.records = new LinkedList<T>(records);
}
/**
* Returns <tt>true</tt> if the iteration has more elements.
*
* @return <tt>true</tt> if the iterator has more elements.
*/
public boolean hasNext()
{
return this.currentPos + 1 < this.records.size();
}
/**
* Returns true if the iteration has elements preceeding the current one.
*
* @return true if the iterator has preceeding elements.
*/
public boolean hasPrev()
{
return this.currentPos - 1 >= 0;
}
/**
* Returns the next element in the iteration.
*
* @return the next element in the iteration.
*/
public T next()
{
this.currentPos++;
if (this.currentPos >= this.records.size())
{
throw new NoSuchElementException();
}
return records.get(this.currentPos);
}
/**
* A strongly-typed variant of <tt>next()</tt>.
*
* @return the next history record.
* @throws NoSuchElementException iteration has no more elements.
*/
public T nextRecord() throws NoSuchElementException
{
return this.next();
}
/**
* Returns the previous element in the iteration.
*
* @return the previous element in the iteration.
* @throws NoSuchElementException iteration has no more elements.
*/
public T prev() throws NoSuchElementException
{
this.currentPos--;
if (this.currentPos < 0)
{
throw new NoSuchElementException();
}
return records.get(this.currentPos);
}
/**
* A strongly-typed variant of <tt>prev()</tt>.
*
* @return the previous history record.
* @throws NoSuchElementException iteration has no more elements.
*/
public T prevRecord() throws NoSuchElementException
{
return this.prev();
}
/**
* Removes from the underlying collection the last element returned by
* the iterator (optional operation).
*/
public void remove()
{
throw new UnsupportedOperationException("Cannot remove elements "
+ "from underlaying collection.");
}
}
|