01: /*
02: * StringParser.java
03: *
04: * Created on 18. Dezember 2003, 23:02
05: */
06:
07: package org.contineo.core.text;
08:
09: import java.text.BreakIterator;
10: import java.util.ArrayList;
11: import java.util.Collection;
12:
13: /**
14: * This class puts all words of a string into a collection.
15: * @author Michael Scholz
16: * @version 1.0
17: */
18: public class StringParser {
19: /**
20: * @uml.property name="wordTable"
21: * @uml.associationEnd
22: */
23: private Collection<String> wordTable = new ArrayList<String>();
24:
25: /** Creates a new instance of StringParser */
26: public StringParser(String text) {
27: init(text);
28: } // end ctor StringParser
29:
30: /**
31: * Returns the wordtable.
32: *
33: * @uml.property name="wordTable"
34: */
35: public Collection getWordTable() {
36: return wordTable;
37: } // end method getWordTable
38:
39: /**
40: * This method extracts the words of a string.
41: */
42: protected void init(String text) {
43: BreakIterator boundary = BreakIterator.getWordInstance();
44: boundary.setText(text);
45:
46: int start = boundary.first();
47:
48: for (int end = boundary.next(); end != BreakIterator.DONE; start = end, end = boundary
49: .next()) {
50: String word = text.substring(start, end).trim();
51:
52: if (word.length() > 1) {
53: wordTable.add(word);
54: }
55: }
56: } // end method init
57: } // end class StringParser
|