1   /*
2    *  Copyright (c) 1998-2001, 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.3 2003/04/18 10:18:11 nasso Exp $
12   *
13   */
14  package gate.util;
15  
16  import java.util.Comparator;
17  import gate.*;
18  
19  /**
20   * Compares annotations by start offset
21   */
22  public class OffsetComparator implements Comparator {
23  
24    public int compare(Object o1, Object o2){
25      Annotation a1 = (Annotation)o1;
26      Annotation a2 = (Annotation)o2;
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  }