source: gs3-extensions/atlas-src/trunk/src/org/greenstone/server/GazetteerTrieTopLevelNode.java@ 22272

Last change on this file since 22272 was 22272, checked in by sjm84, 14 years ago

Initial version of ATLAS as an extension

File size: 2.2 KB
Line 
1package org.greenstone.server;
2
3import java.io.Serializable;
4import java.util.HashMap;
5
6public class GazetteerTrieTopLevelNode implements Serializable
7{
8 private static final long serialVersionUID = 1L;
9 protected boolean _nameEnd = false;
10 protected GazetteerTrieNode[] _children = new GazetteerTrieNode[65000];
11
12 /**
13 * Basic constructor for a non-unicode trie node
14 * @param nameEnd defines whether the new node represents the end of a place name
15 */
16 protected GazetteerTrieTopLevelNode(boolean nameEnd)
17 {
18 for(int i = 0; i < 65000; i++)
19 {
20 _children[i] = null;
21 }
22 _nameEnd = nameEnd;
23 }
24
25 /**
26 * Add a child to the current node
27 * @param c is the character used to decide where to add the child node
28 * @param nameEnd is whether or not this character represents the end of a place name
29 * @return true if a child was added and false if one already existed
30 */
31 protected boolean addChild(char c, boolean nameEnd)
32 {
33 if(c >= 65 && c <= 90)
34 {
35 c += 32;
36 }
37 //Add the ascii character if it either does not already exist or it signifies the end of a place name
38 if(_children[(int)c] != null)
39 {
40 if(_children[(int)c].isNameEnd() || nameEnd == false)
41 {
42 return false;
43 }
44 else
45 {
46 _children[(int)c].setNameEnd(true);
47 return true;
48 }
49 }
50 else
51 {
52 _children[(int)c] = new GazetteerTrieNode(nameEnd);
53 return true;
54 }
55 }
56
57 /**
58 * @return whether or not this node represents the end of a place name
59 */
60 protected boolean isNameEnd()
61 {
62 return _nameEnd;
63 }
64
65 /**
66 * Set whether or not this node represents the end of a place name
67 * @param nameEnd is the value to set it to
68 */
69 protected void setNameEnd(boolean nameEnd)
70 {
71 _nameEnd = nameEnd;
72 }
73
74 /**
75 * Returns the child at the given index
76 * @param index is the index of the child to return
77 * @return the child at the given index
78 */
79 protected GazetteerTrieNode getChild(char c)
80 {
81 if(c >= 65 && c <= 90)
82 {
83 c += 32;
84 }
85 return _children[(int)c];
86 }
87
88 public void output()
89 {
90 /*
91 if(_unicodeCharacters != null && _unicodeCharacters.size() >= 10)
92 {
93 System.out.println(_unicodeCharacters.size());
94 }
95
96 for(GazetteerTrieNode g : _children)
97 {
98 if(g != null)
99 {
100 g.output();
101 }
102 }
103 */
104 }
105}
Note: See TracBrowser for help on using the repository browser.