01: // Segment.java
02: // $Id: Segment.java,v 1.3 2000/08/16 21:37:43 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1998.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigsaw.pagecompile;
07:
08: import java.util.Vector;
09:
10: /**
11: * @version $Revision: 1.3 $
12: * @author Benoît Mahé (bmahe@w3.org)
13: */
14: public class Segment {
15:
16: public static final int CODE = 1;
17: public static final int IMPORT = 2;
18: public static final int EXTENDS = 3;
19: public static final int IMPLEMENTS = 4;
20: public static final int CLASS = 5;
21: public static final int PRINT = 6;
22: public static final int TEXT = 7;
23:
24: int start = -1;
25: int end = -1;
26: int TYPE = -1;
27:
28: /**
29: * get the default type.
30: * @return an int.
31: */
32: public static int getDefaultType() {
33: return CODE;
34: }
35:
36: /**
37: * Get the segments with the same type.
38: * @param segments an array of Segment.
39: * @param type the type
40: * @return an array of Segment.
41: */
42: public static Segment[] getSegmentMatching(Segment segments[],
43: int type) {
44: Vector segs = new Vector(10);
45: for (int i = 0; i < segments.length; i++) {
46: if (segments[i].TYPE == type)
47: segs.addElement(segments[i]);
48: }
49: Segment[] matchingSegs = new Segment[segs.size()];
50: segs.copyInto(matchingSegs);
51: return matchingSegs;
52: }
53:
54: /**
55: * get the type relative to the given String.
56: * @param type The String type.
57: * @return an int.
58: */
59: public static int getType(String type) {
60: if (type.equalsIgnoreCase("import"))
61: return IMPORT;
62: else if (type.equalsIgnoreCase("extends"))
63: return EXTENDS;
64: else if (type.equalsIgnoreCase("class"))
65: return CLASS;
66: else if (type.equalsIgnoreCase("implements"))
67: return IMPLEMENTS;
68: else if (type.equalsIgnoreCase("print"))
69: return PRINT;
70: else if (type.equalsIgnoreCase("code"))
71: return CODE;
72: else
73: return CODE;
74: }
75:
76: public int getType() {
77: return TYPE;
78: }
79:
80: Segment(int start, int end) {
81: this .start = start;
82: this .end = end;
83: this .TYPE = TEXT;
84: }
85:
86: Segment(int start, int end, int TYPE) {
87: this.start = start;
88: this.end = end;
89: this.TYPE = TYPE;
90: }
91: }
|