1
16 package gate.creole.gazetteer;
17
18
19
20
22 public class LinearNode {
23
24
25 private String list;
26
27 private String minor;
28
29 private String major;
30
31 private String language;
32
33
40 public LinearNode(String aList,String aMajor,String aMinor, String aLanguage) {
41 list = aList;
42 minor = aMinor;
43 major = aMajor;
44 language = aLanguage;
45 }
47
52 public LinearNode (String node) throws InvalidFormatException {
53 int firstColon = node.indexOf(':');
54 int secondColon = node.indexOf(':', firstColon + 1);
55 int thirdColon = node.indexOf(':', secondColon + 1);
56 if(firstColon == -1){
57 throw new InvalidFormatException("", "Line: " + node);
58 }
59 list = node.substring(0, firstColon);
60
61 if(secondColon == -1){
62 major = node.substring(firstColon + 1);
63 minor = null;
64 language = null;
65 } else {
66 major = node.substring(firstColon + 1, secondColon);
67 if(thirdColon == -1) {
68 minor = node.substring(secondColon + 1);
69 language = null;
70 } else {
71 minor = node.substring(secondColon + 1, thirdColon);
72 language = node.substring(thirdColon + 1);
73 }
74 } }
77
79 public String getList() {
80 return list;
81 }
82
83
85 public void setList(String aList) {
86 list = aList;
87 }
88
89
91 public String getLanguage() {
92 return language;
93 }
94
95
97 public void setLanguage(String aLanguage) {
98 language = aLanguage;
99 }
100
101
103 public String getMinorType() {
104 return minor;
105 }
106
107
109 public void setMinorType(String minorType) {
110 minor = minorType;
111 }
112
113
115 public String getMajorType() {
116 return major;
117 }
118
119
121 public void setMajorType(String majorType) {
122 major = majorType;
123 }
124
125
129 public String toString() {
130 String result = list+':'+major;
131
132 if ( (null!=minor) && (0 != minor.length()))
133 result += ':'+minor;
134
135 if ( (null!=language) && (0 != language.length())) {
136 if ((null==minor) || (0 == minor.length()) )
137 result +=':';
138 result += ':'+language;
139 }
140 return result;
141 }
142
143
146 public boolean equals(Object o) {
147 boolean result = false;
148 if ( o instanceof LinearNode ) {
149 LinearNode node = (LinearNode) o;
150 result = true;
151
152 if (null != this.getLanguage())
153 result &= this.getLanguage().equals(node.getLanguage());
154
155 if ( null != this.getList())
156 result &= this.getList().equals(node.getList());
157
158 if ( null!=this.getMajorType())
159 result &= this.getMajorType().equals(node.getMajorType());
160
161 if ( null!= this.getMinorType())
162 result &= this.getMinorType().equals(node.getMinorType());
163 }
164 return result;
165 }
166
167 }