01: package com.nwalsh.saxon;
02:
03: import org.w3c.dom.*;
04:
05: /**
06: * <p>A class for maintaining information about callouts.</p>
07: *
08: * <p>To make processing callouts easier, they are parsed out of the
09: * input structure and stored in a sorted array. (The array is sorted
10: * according to the order in which the callouts occur.)</p>
11: *
12: * <p>This class is just the little record
13: * that we store in the array for each callout.</p>
14: */
15: public class Callout implements Comparable {
16: /** The callout number. */
17: private int callout = 0;
18: /** The area Element item that generated this callout. */
19: private Element area = null;
20: /** The line on which this callout occurs. */
21: private int line = 0;
22: /** The column in which this callout appears. */
23: private int col = 0;
24:
25: /** The constructor; initialize the private data structures. */
26: public Callout(int callout, Element area, int line, int col) {
27: this .callout = callout;
28: this .area = area;
29: this .line = line;
30: this .col = col;
31: }
32:
33: /**
34: * <p>The compareTo method compares this Callout with another.</p>
35: *
36: * <p>Given two Callouts, A and B, A < B if:</p>
37: *
38: * <ol>
39: * <li>A.line < B.line, or</li>
40: * <li>A.line = B.line && A.col < B.col, or</li>
41: * <li>A.line = B.line && A.col = B.col && A.callout < B.callout</li>
42: * <li>Otherwise, they're equal.</li>
43: * </ol>
44: */
45: public int compareTo(Object o) {
46: Callout c = (Callout) o;
47:
48: if (line == c.getLine()) {
49: if (col > c.getColumn()) {
50: return 1;
51: } else if (col < c.getColumn()) {
52: return -1;
53: } else {
54: if (callout < c.getCallout()) {
55: return -1;
56: } else if (callout > c.getCallout()) {
57: return 1;
58: } else {
59: return 0;
60: }
61: }
62: } else {
63: if (line > c.getLine()) {
64: return 1;
65: } else {
66: return -1;
67: }
68: }
69: }
70:
71: /** Access the Callout's area. */
72: public Element getArea() {
73: return area;
74: }
75:
76: /** Access the Callout's line. */
77: public int getLine() {
78: return line;
79: }
80:
81: /** Access the Callout's column. */
82: public int getColumn() {
83: return col;
84: }
85:
86: /** Access the Callout's callout number. */
87: public int getCallout() {
88: return callout;
89: }
90: }
|