OffsetComparator.java |
1 /* 2 * Copyright (c) 1998-2005, The University of Sheffield. 3 * 4 * This file is part of GATE (see http://gate.ac.uk/), and is free 5 * software, licenced under the GNU Library General Public License, 6 * Version 2, June 1991 (in the distribution as file licence.html, 7 * and also available at http://gate.ac.uk/gate/licence.html). 8 * 9 * Valentin Tablan 02/10/2001 10 * 11 * $Id: OffsetComparator.java,v 1.6 2005/01/11 13:51:37 ian Exp $ 12 * 13 */ 14 package gate.util; 15 16 import java.util.Comparator; 17 18 import gate.Annotation; 19 20 /** 21 * Compares annotations by start offset 22 */ 23 public class OffsetComparator implements Comparator { 24 25 public int compare(Object o1, Object o2){ 26 Annotation a1 = (Annotation)o1; 27 Annotation a2 = (Annotation)o2; 28 int result; 29 30 // compare start offsets 31 result = a1.getStartNode().getOffset().compareTo( 32 a2.getStartNode().getOffset()); 33 34 // if start offsets are equal compare end offsets 35 if(result == 0) { 36 result = a1.getEndNode().getOffset().compareTo( 37 a2.getEndNode().getOffset()); 38 } // if 39 40 return result; 41 } 42 }