refactor: replace while with iterator with foreach loop

This commit is contained in:
broDom
2017-07-03 16:56:25 +02:00
parent ad719d37ab
commit 9f98b0e890
2 changed files with 10 additions and 24 deletions

View File

@@ -37,18 +37,16 @@ package sonia.scm.search;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.TransformFilter;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
@@ -165,23 +163,18 @@ public final class SearchUtil
List<T> items = new ArrayList<T>();
int index = 0;
int counter = 0;
Iterator<T> it = collection.iterator();
while (it.hasNext())
{
T item = filter.accept(it.next());
for (final T aCollection : collection) {
T item = filter.accept(aCollection);
if (item != null)
{
if (item != null) {
index++;
if (searchRequest.getStartWith() <= index)
{
if (searchRequest.getStartWith() <= index) {
items.add(item);
counter++;
if (searchRequest.getMaxResults() <= counter)
{
if (searchRequest.getMaxResults() <= counter) {
break;
}
}

View File

@@ -235,22 +235,15 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
revWalk.markStart(revWalk.lookupCommit(head));
}
Iterator<RevCommit> iterator = revWalk.iterator();
while (iterator.hasNext())
{
RevCommit commit = iterator.next();
for (final RevCommit commit : revWalk) {
if ((counter >= start)
&& ((limit < 0) || (counter < start + limit)))
{
&& ((limit < 0) || (counter < start + limit))) {
changesetList.add(converter.createChangeset(commit));
}
counter++;
if ((endId != null) && commit.getId().equals(endId))
{
if ((endId != null) && commit.getId().equals(endId)) {
break;
}
}