MCPcopy Create free account
hub / github.com/dumbledore/AlbiteREADER / lookUp

Method lookUp

src/org/albite/dictionary/Dictionary.java:118–194  ·  view source on GitHub ↗
(final String lookingFor)

Source from the content-addressed store, hash-verified

116 }
117
118 public final String[] lookUp(final String lookingFor)
119 throws DictionaryException {
120
121 final DictEntries de = load();
122
123 //#debug
124 AlbiteMIDlet.LOGGER.log("lowercasing");
125 final char[] text =
126 AlbiteCharacter.toLowerCase(lookingFor.toCharArray());
127
128 //#debug
129 AlbiteMIDlet.LOGGER.log("binary search");
130 int searchResult = TextTools.binarySearch(de.names, text);
131
132 if (searchResult >= 0) {
133 /*
134 * The word was found, so no suggestions neccessary.
135 */
136
137 //#debug
138 AlbiteMIDlet.LOGGER.log("word found. getting definitions");
139 return new String[] {getDefinition(searchResult)};
140 }
141
142 /*
143 * We need to increment the found index by one
144 * as it has been decreased by one by the indexSearch method.
145 */
146 searchResult = -searchResult + 1;
147
148 /*
149 * Returns a maximum of 11 suggestions.
150 */
151 final int offset = NUMBER_OF_SUGGESTIONS / 2;
152
153 int left = searchResult - offset;
154 int right = searchResult + offset;
155
156 /*
157 * First check left side, if the "center" (i.e. searchResult)
158 * is too much in the left
159 */
160 if (left < 0) {
161 left = 0;
162 right = NUMBER_OF_SUGGESTIONS;
163 }
164
165 /*
166 * Check if the "center" is too much in the right.
167 */
168 if (right >= de.names.length) {
169 right = de.names.length - 1;
170 left = right - NUMBER_OF_SUGGESTIONS;
171 }
172
173 /*
174 * This might happen in the extreme case of a dictionary
175 * having less number of items than NUMBER_OF_SUGGESTIONS

Callers 1

executeMethod · 0.80

Calls 5

loadMethod · 0.95
toLowerCaseMethod · 0.95
binarySearchMethod · 0.95
getDefinitionMethod · 0.95
logMethod · 0.80

Tested by

no test coverage detected