Skip to content

Commit

Permalink
Renaming method to get clear name
Browse files Browse the repository at this point in the history
Because firstElement is more clear than get(elements, 0).
  • Loading branch information
garcia-jj committed Nov 14, 2014
1 parent 35352d7 commit 5901351
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package br.com.caelum.vraptor.interceptor;

import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.newHashSet;

Expand Down Expand Up @@ -113,15 +112,19 @@ private String cycle() {
}

private List<E> findCycle() {
E node = get(graph.keySet(), 0);
E node = firstElement(graph.keySet());
List<E> cycle = new ArrayList<>();
do {
cycle.add(node);
} while(!cycle.contains(node = get(graph.get(node), 0)));
} while(!cycle.contains(node = firstElement(graph.get(node))));

return cycle.subList(cycle.indexOf(node), cycle.size());
}

private E firstElement(Iterable<E> elements) {
return elements.iterator().next();
}

private void removeLeaves() {
Set<E> leaves = findLeaves();
if (leaves.isEmpty()) {
Expand All @@ -139,4 +142,4 @@ private void removeLeaves() {
private Set<E> findLeaves() {
return difference(newHashSet(graph.values()), graph.keySet());
}
}
}

0 comments on commit 5901351

Please sign in to comment.