Position.vala 934 B

1234567891011121314151617181920212223242526272829303132
  1. namespace Invercargill {
  2. private class PositionQuery<T> : BaseQuery<T, PositionItemPair<T>> {
  3. public PositionQuery(Enumerable<T> input) {
  4. this.input = input;
  5. }
  6. public override Tracker<PositionItemPair<T>> get_tracker() {
  7. return new PositionTracker<T>(input);
  8. }
  9. private class PositionTracker<T> : Tracker<PositionItemPair<T>> {
  10. private Tracker<T> base_tracker;
  11. private int position;
  12. public PositionTracker(Enumerable<T> input) {
  13. base_tracker = input.get_tracker();
  14. position = -1;
  15. }
  16. public override bool has_next() {
  17. return base_tracker.has_next();
  18. }
  19. public override PositionItemPair<T> get_next() {
  20. return new PositionItemPair<T>(++position, base_tracker.get_next());
  21. }
  22. }
  23. }
  24. }