1   /*
2    *  NodeImpl.java
3    *
4    *  Copyright (c) 1998-2001, The University of Sheffield.
5    *
6    *  This file is part of GATE (see http://gate.ac.uk/), and is free
7    *  software, licenced under the GNU Library General Public License,
8    *  Version 2, June 1991 (in the distribution as file licence.html,
9    *  and also available at http://gate.ac.uk/gate/licence.html).
10   *
11   *  Valentin Tablan, 24.01.2000
12   *
13   *  $Id: NodeImpl.java,v 1.9 2001/03/21 18:38:47 cursu Exp $
14   */
15  
16  package  gate.annotation;
17  
18  import java.util.*;
19  import gate.*;
20  import gate.util.*;
21  
22  /** Provides an implementation for the interface gate.Node.
23   *
24   */
25  public class NodeImpl implements Node, Comparable
26  {
27    /** Debug flag
28     */
29    private static final boolean DEBUG = false;
30  
31    /** Freeze the serialization UID. */
32    static final long serialVersionUID = -8240414984367916298L;
33  
34    /** Construction from id. Creates an unrooted node.
35     */
36    public NodeImpl (Integer id) {
37      this.id = id;
38      offset = null;
39    } // Node()
40  
41    /** Construction from id and offset.
42     *
43     * @param id the Id of the new node
44     * @param offset the (temporal) offset of the Node; Should be <b>null</b>
45     *     for non-anchored nodes.
46     */
47    public NodeImpl (Integer id, Long offset) {
48        this.id = id;
49        this.offset = offset;
50    } // Node(id, offset)
51  
52    /** Returns the Id of the Node.
53     */
54    public Integer getId () { return  id; }
55  
56    /** Offset (will be null when the node is not anchored)
57     */
58    public Long getOffset () { return  offset; }
59  
60    /** String representation
61     */
62    public String toString() {
63      return "NodeImpl: id=" + id + "; offset=" + offset;
64    } // toString()
65  
66    /** Ordering
67     */
68    public int compareTo(Object o) throws ClassCastException {
69      Node other = (Node) o;
70      return id.compareTo(other.getId());
71    } // compareTo
72  
73    /** To allow AnnotationSet to revise offsets during editing
74     */
75    void setOffset(Long offset) { this.offset = offset; }
76  
77    /**
78     * The id of this node (used for persistency)
79     *
80     */
81    Integer id;
82    /**
83     * The offset of this node
84     *
85     */
86    Long offset;
87  }
88