View Javadoc
1   package edu.uci.ics.jung.algorithms.util;
2   
3   import com.google.common.base.Predicate;
4   
5   import edu.uci.ics.jung.graph.Graph;
6   import edu.uci.ics.jung.graph.util.Context;
7   import edu.uci.ics.jung.graph.util.Pair;
8   
9   /**
10   * A <code>Predicate</code> that returns <code>true</code> if the input edge's 
11   * endpoints in the input graph are identical.  (Thus, an edge which connects
12   * its sole incident vertex to itself).
13   *
14   * @param <V> the vertex type
15   * @param <E> the edge type
16   */
17  public class SelfLoopEdgePredicate<V,E> implements Predicate<Context<Graph<V,E>,E>> {
18  
19      public boolean apply(Context<Graph<V,E>,E> context) {
20          Pair<V> endpoints = context.graph.getEndpoints(context.element);
21          return endpoints.getFirst().equals(endpoints.getSecond());
22      }
23  }