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