1 19 20 22 package edu.umd.cs.findbugs.graph; 23 24 import java.io.Serializable ; 25 import java.util.Comparator ; 26 27 import edu.umd.cs.findbugs.annotations.SuppressWarnings; 28 29 34 public class VisitationTimeComparator <VertexType extends GraphVertex<VertexType>> implements Comparator <VertexType>, 35 Serializable { 36 private static final long serialVersionUID = 0L; 37 40 public static final int ASCENDING = 0; 41 42 45 public static final int DESCENDING = 1; 46 47 private int[] m_visitationTimeList; 48 private int m_direction; 49 50 56 @SuppressWarnings ("EI2") 57 public VisitationTimeComparator(int[] visitationTimeList, int direction) { 58 m_visitationTimeList = visitationTimeList; 59 m_direction = direction; 60 61 if (direction != ASCENDING && direction != DESCENDING) 62 throw new IllegalArgumentException (); 63 } 64 65 public int compare(VertexType v1, VertexType v2) { 66 int f1 = m_visitationTimeList[v1.getLabel()]; 67 int f2 = m_visitationTimeList[v2.getLabel()]; 68 69 if (m_direction == ASCENDING) 70 return f1 - f2; 71 else 72 return f2 - f1; 73 } 74 75 } 76 77 | Popular Tags |