diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/Graph.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/Graph.java index 5af588670..2f202195a 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/Graph.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/Graph.java @@ -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; @@ -113,15 +112,19 @@ private String cycle() { } private List findCycle() { - E node = get(graph.keySet(), 0); + E node = firstElement(graph.keySet()); List 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 elements) { + return elements.iterator().next(); + } + private void removeLeaves() { Set leaves = findLeaves(); if (leaves.isEmpty()) { @@ -139,4 +142,4 @@ private void removeLeaves() { private Set findLeaves() { return difference(newHashSet(graph.values()), graph.keySet()); } -} \ No newline at end of file +}