Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/ReverseIterator.java @ 596:43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 02 May 2013 19:23:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
595:92c3ad9c2a51 | 596:43cfa08ff3fd |
---|---|
1 /* | |
2 * Copyright (c) 2013 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.internal; | |
18 | |
19 import java.util.Iterator; | |
20 import java.util.List; | |
21 import java.util.ListIterator; | |
22 | |
23 /** | |
24 * @author Artem Tikhomirov | |
25 * @author TMate Software Ltd. | |
26 */ | |
27 public class ReverseIterator<E> implements Iterator<E> { | |
28 private final ListIterator<E> listIterator; | |
29 | |
30 public ReverseIterator(List<E> list) { | |
31 listIterator = list.listIterator(list.size()); | |
32 } | |
33 | |
34 public boolean hasNext() { | |
35 return listIterator.hasPrevious(); | |
36 } | |
37 public E next() { | |
38 return listIterator.previous(); | |
39 } | |
40 public void remove() { | |
41 listIterator.remove(); | |
42 } | |
43 | |
44 public static <T> Iterable<T> reversed(final List<T> list) { | |
45 return new Iterable<T>() { | |
46 | |
47 public Iterator<T> iterator() { | |
48 return new ReverseIterator<T>(list); | |
49 } | |
50 }; | |
51 } | |
52 } |