+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package com.hughes.android.dictionary.parser;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Arrays;
+import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
static final Pattern CURLY_BRACED = Pattern.compile("\\{([^}]+)\\}");
static final Pattern NON_CHAR_DASH = Pattern.compile("[^-'\\p{L}0-9]+");
- static final Pattern NON_CHAR = Pattern.compile("[^\\p{L}0-9]+");
+ public static final Pattern NON_CHAR = Pattern.compile("[^\\p{L}0-9]+");
static final Pattern TRIM_PUNC = Pattern.compile("^[^\\p{L}0-9]+|[^\\p{L}0-9]+$");
for (String token : tokens) {
token = TRIM_PUNC.matcher(token).replaceAll("");
if (/*!alreadyDone.contains(token) && */token.length() > 0) {
- final List<IndexedEntry> entries = indexBuilder.getOrCreateEntries(token, entryTypeName);
- entries.add(entryData);
+ indexBuilder.addEntryWithTokens(entryData, Collections.singleton(token), entryTypeName);
// alreadyDone.add(token);
// also split words on dashes, do them, too.
final String[] dashed = token.split("-");
for (final String dashedToken : dashed) {
if (/*!alreadyDone.contains(dashedToken) && */dashedToken.length() > 0) {
- final List<IndexedEntry> dashEntries = indexBuilder.getOrCreateEntries(dashedToken, EntryTypeName.PART_OF_HYPHENATED);
- dashEntries.add(entryData);
+ indexBuilder.addEntryWithTokens(entryData, Collections.singleton(dashedToken), EntryTypeName.PART_OF_HYPHENATED);
}
}
}
for (final String token : bracketedTokens) {
assert !token.contains("-");
if (/*!alreadyDone.contains(token) && */token.length() > 0) {
- final List<IndexedEntry> entries = indexBuilder.getOrCreateEntries(token, EntryTypeName.BRACKETED);
- entries.add(entryData);
+ indexBuilder.addEntryWithTokens(entryData, Collections.singleton(token), EntryTypeName.BRACKETED);
}
}
for (final String token : parenTokens) {
assert !token.contains("-");
if (/*!alreadyDone.contains(token) && */token.length() > 0) {
- final List<IndexedEntry> entries = indexBuilder.getOrCreateEntries(token, EntryTypeName.PARENTHESIZED);
- entries.add(entryData);
+ indexBuilder.addEntryWithTokens(entryData, Collections.singleton(token), EntryTypeName.PARENTHESIZED);
}
}