| 1 |
package iterator |
| 2 |
|
| 3 |
// Factory is the interface that wraps the NewIterator method. The |
| 4 |
// NewIterator() creates either UID or thread iterators and ensures that both |
| 5 |
// types of iterators implement the same iteration direction. |
| 6 |
type Factory interface { |
| 7 |
NewIterator(a any) Iterator |
| 8 |
} |
| 9 |
|
| 10 |
// Iterator implements an interface for iterating over UID or thread data. If |
| 11 |
// Next() returns true, the current value of the iterator can be read with |
| 12 |
// Value(). The return value of Value() is of type `any` and needs to be cast to |
| 13 |
// the correct type. |
| 14 |
// |
| 15 |
// The iterators are implemented such that the first returned value always |
| 16 |
// represents the top message in the message list. Hence, StartIndex() would |
| 17 |
// return the index of the top message whereas EndIndex() returns the index of |
| 18 |
// message at the bottom of the list. |
| 19 |
type Iterator interface { |
| 20 |
Next() bool |
| 21 |
Value() any |
| 22 |
StartIndex() int |
| 23 |
EndIndex() int |
| 24 |
} |
| 25 |
|
| 26 |
// NewFactory creates an iterator factory. When reverse is true, the iterators |
| 27 |
// are reversed in the sense that the lowest UID messages are displayed at the |
| 28 |
// top of the message list. Otherwise, the default order is with the highest |
| 29 |
// UID message on top. |
| 30 |
func NewFactory(reverse bool) Factory { |
| 31 |
if reverse { |
| 32 |
return &reverseFactory{} |
| 33 |
} |
| 34 |
return &defaultFactory{} |
| 35 |
} |