~sword-devel/jsword/trunk

« back to all changes in this revision

Viewing changes to jsword/java/jsword/org/crosswire/jsword/control/search/CustomTokenizer.java

  • Committer: joe
  • Date: 2002-10-08 21:36:18 UTC
  • Revision ID: svn-v4:a88caf3b-7e0a-0410-8d0d-cecb45342206:trunk:80
big config and comment update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
package org.crosswire.jsword.control.search;
3
3
 
4
 
import java.util.Enumeration;
5
 
import java.util.Hashtable;
6
 
import java.util.Vector;
 
4
import java.util.ArrayList;
 
5
import java.util.Iterator;
 
6
import java.util.List;
 
7
import java.util.Map;
7
8
 
8
9
/**
9
 
* Our command line parsing is a little specialized, so StringTokenizer is not
10
 
* up to the job. The specific problem is that there is sometimes no separator
11
 
* between parts of the command, and since this is specialized we also leave the
12
 
* results in a Vector of SearchWords.
13
 
*
14
 
* <table border='1' cellPadding='3' cellSpacing='0' width="100%">
15
 
* <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
16
 
* Distribution Licence:<br />
17
 
* Project B is free software; you can redistribute it
18
 
* and/or modify it under the terms of the GNU General Public License,
19
 
* version 2 as published by the Free Software Foundation.<br />
20
 
* This program is distributed in the hope that it will be useful,
21
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
 
* General Public License for more details.<br />
24
 
* The License is available on the internet
25
 
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
26
 
* <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27
 
* MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
28
 
* The copyright to this program is held by it's authors.
29
 
* </font></td></tr></table>
30
 
* @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
31
 
* @see <{docs.Licence}>
32
 
* @author Joe Walker
33
 
*/
 
10
 * Our command line parsing is a little specialized, so StringTokenizer is not
 
11
 * up to the job. The specific problem is that there is sometimes no separator
 
12
 * between parts of the command, and since this is specialized we also leave the
 
13
 * results in a Vector of SearchWords.
 
14
 * 
 
15
 * <p><table border='1' cellPadding='3' cellSpacing='0'>
 
16
 * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
 
17
 *
 
18
 * Distribution Licence:<br />
 
19
 * JSword is free software; you can redistribute it
 
20
 * and/or modify it under the terms of the GNU General Public License,
 
21
 * version 2 as published by the Free Software Foundation.<br />
 
22
 * This program is distributed in the hope that it will be useful,
 
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
25
 * General Public License for more details.<br />
 
26
 * The License is available on the internet
 
27
 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
 
28
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
29
 * MA 02111-1307, USA<br />
 
30
 * The copyright to this program is held by it's authors.
 
31
 * </font></td></tr></table>
 
32
 * @see docs.Licence
 
33
 * @author Joe Walker [joe at eireneh dot com]
 
34
 * @version $Id$
 
35
 */
34
36
public class CustomTokenizer
35
37
{
36
38
    /**
39
41
    * @param commands The Hashtable of SearchWords to select from
40
42
    * @return An Vector of selected SearchWords
41
43
    */
42
 
    public static Vector tokenize(String sought, Hashtable commands) throws SearchException
 
44
    public static List tokenize(String sought, Map commands) throws SearchException
43
45
    {
44
 
        Vector output = new Vector();
 
46
        List output = new ArrayList();
45
47
        String command_chars = getSingleCharWords(commands);
46
48
        int current_type = charType(sought.charAt(0), command_chars);
47
49
        int start_index = 0;
107
109
    */
108
110
    private final static int charType(char sought, String commands)
109
111
    {
110
 
        if (Character.isWhitespace(sought))     return CHAR_SPACE;
111
 
        if (commands.indexOf(""+sought) != -1)  return CHAR_COMMAND;
112
 
        else                                    return CHAR_PARAM;
 
112
        if (Character.isWhitespace(sought))
 
113
            return CHAR_SPACE;
 
114
 
 
115
        if (commands.indexOf(""+sought) != -1)
 
116
            return CHAR_COMMAND;
 
117
 
 
118
        return CHAR_PARAM;
113
119
    }
114
120
 
115
121
    /**
118
124
    * @param commands The SearchWord source
119
125
    * @param word The trigger to look for
120
126
    */
121
 
    private static void addWord(Vector output, Hashtable commands, String word)
 
127
    private static void addWord(List output, Map commands, String word)
122
128
    {
123
129
        Object word_obj = commands.get(word);
124
 
        if (word_obj == null) word_obj = new DefaultParamWord(word);
125
 
        output.addElement(word_obj);
 
130
        if (word_obj == null)
 
131
            word_obj = new DefaultParamWord(word);
 
132
 
 
133
        output.add(word_obj);
126
134
    }
127
135
 
128
136
    /**
131
139
    * @param commands The SearchWord source
132
140
    * @param word The trigger to look for
133
141
    */
134
 
    private static String getSingleCharWords(Hashtable commands)
 
142
    private static String getSingleCharWords(Map commands)
135
143
    {
136
 
        Enumeration en = commands.keys();
 
144
        Iterator it = commands.keySet().iterator();
137
145
        StringBuffer buf = new StringBuffer();
138
146
 
139
 
        while (en.hasMoreElements())
 
147
        while (it.hasNext())
140
148
        {
141
 
            String cmd = (String) en.nextElement();
 
149
            String cmd = (String) it.next();
142
150
            if (cmd.length() == 1) buf.append(cmd);
143
151
        }
144
152