diff src/org/tmatesoft/hg/core/HgLogCommand.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 e4ee4bf4c7d0
children 6526d8adbc0f
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgLogCommand.java	Thu May 02 19:23:35 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgLogCommand.java	Thu May 02 19:23:53 2013 +0200
@@ -30,7 +30,6 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.ListIterator;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -42,6 +41,7 @@
 import org.tmatesoft.hg.internal.Internals;
 import org.tmatesoft.hg.internal.Lifecycle;
 import org.tmatesoft.hg.internal.LifecycleProxy;
+import org.tmatesoft.hg.internal.ReverseIterator;
 import org.tmatesoft.hg.repo.HgChangelog;
 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
 import org.tmatesoft.hg.repo.HgDataFile;
@@ -446,12 +446,7 @@
 		}
 		
 		public Iterable<BatchRecord> iterate(final boolean reverse) {
-			return new Iterable<BatchRecord>() {
-				
-				public Iterator<BatchRecord> iterator() {
-					return reverse ? new ReverseIterator<BatchRecord>(batch) : batch.iterator();
-				}
-			};
+			return reverse ? ReverseIterator.reversed(batch) : batch;
 		}
 		
 		// alternative would be dispatch(HgChangelog.Inspector) and dispatchReverse()
@@ -563,24 +558,6 @@
 		progressHelper.done();
 	}
 	
-	private static class ReverseIterator<E> implements Iterator<E> {
-		private final ListIterator<E> listIterator;
-		
-		public ReverseIterator(List<E> list) {
-			listIterator = list.listIterator(list.size());
-		}
-
-		public boolean hasNext() {
-			return listIterator.hasPrevious();
-		}
-		public E next() {
-			return listIterator.previous();
-		}
-		public void remove() {
-			listIterator.remove();
-		}
-	}
-
 	/**
 	 * Utility to build sequence of file renames
 	 */