01 /*
02 * Copyright (c) 1995-2010, The University of Sheffield. See the file
03 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
04 *
05 * This file is part of GATE (see http://gate.ac.uk/), and is free
06 * software, licenced under the GNU Library General Public License,
07 * Version 2, June 1991 (in the distribution as file licence.html,
08 * and also available at http://gate.ac.uk/gate/licence.html).
09 *
10 * Valentin Tablan 02/10/2001
11 *
12 * $Id: OffsetComparator.java 12006 2009-12-01 17:24:28Z thomas_heitz $
13 *
14 */
15 package gate.util;
16
17 import java.util.Comparator;
18
19 import gate.Annotation;
20
21 /**
22 * Compares annotations by start offset
23 */
24 public class OffsetComparator implements Comparator<Annotation> {
25
26 public int compare(Annotation a1, Annotation a2){
27 int result;
28
29 // compare start offsets
30 result = a1.getStartNode().getOffset().compareTo(
31 a2.getStartNode().getOffset());
32
33 // if start offsets are equal compare end offsets
34 if(result == 0) {
35 result = a1.getEndNode().getOffset().compareTo(
36 a2.getEndNode().getOffset());
37 } // if
38
39 return result;
40 }
41 }
|