LengthAccessor.java
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  *  Eric Sword, 09/03/08
11  *
12  *  $Id$
13  */
14 package gate.jape.constraint;
15 
16 import gate.Annotation;
17 import gate.AnnotationSet;
18 
19 /**
20  * Accessor that returns the length of the characters spanned by the annotation
21  *
22  @version $Revision$
23  @author esword
24  */
25 public class LengthAccessor extends MetaPropertyAccessor {
26 
27   /**
28    * Return the length of the span of the annotation.
29    */
30   public Object getValue(Annotation annot, AnnotationSet context) {
31     if(annot == nullreturn 0;
32     Long retVal = annot.getEndNode().getOffset()
33             - annot.getStartNode().getOffset();
34     return retVal;
35   }
36 
37   /**
38    * Always returns "length", the name of the meta-property which this
39    * accessor provides.
40    */
41   @Override
42   public Object getKey() {
43     return "length";
44   }
45 }