diff options
author | 2011-04-26 21:49:09 +0900 | |
---|---|---|
committer | 2011-04-27 17:06:20 +0900 | |
commit | 4250eb27f54f8fedc388fe4825b0646a88778744 (patch) | |
tree | de7b42f5aa401d2a571f60056012c93eeb5552f4 /java/src/com/android/inputmethod/latin/DictionaryCollection.java | |
parent | aa9de267322bbf3a644da728253a224acf5a2d38 (diff) | |
download | latinime-4250eb27f54f8fedc388fe4825b0646a88778744.tar.gz latinime-4250eb27f54f8fedc388fe4825b0646a88778744.tar.xz latinime-4250eb27f54f8fedc388fe4825b0646a88778744.zip |
Create a dictionary collection and a dictionary factory.
The dictionary collection is a class complying to the Dictionary
interface that acts as a front end to a collection of arbitrarily many
dictionaries of any type.
The dictionary factory is a helper class for creating various
dictionaries and get some meta information about them.
At the same time, this change makes the BinaryDictionary class
not a singleton any more.
This also needs I9afe61a9 to not break the build.
Change-Id: I61fdcc4867fcda18342807bf1865e6e46979e5d5
Diffstat (limited to 'java/src/com/android/inputmethod/latin/DictionaryCollection.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/DictionaryCollection.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java new file mode 100644 index 000000000..4b64e5344 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * 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.android.inputmethod.latin; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * Class for a collection of dictionaries that behave like one dictionary. + */ +public class DictionaryCollection extends Dictionary { + + protected final List<Dictionary> mDictionaries; + + public DictionaryCollection() { + mDictionaries = new CopyOnWriteArrayList<Dictionary>(); + } + + public DictionaryCollection(Dictionary... dictionaries) { + mDictionaries = new CopyOnWriteArrayList<Dictionary>(dictionaries); + } + + @Override + public void getWords(final WordComposer composer, final WordCallback callback) { + for (final Dictionary dict : mDictionaries) + dict.getWords(composer, callback); + } + + @Override + public void getBigrams(final WordComposer composer, final CharSequence previousWord, + final WordCallback callback) { + for (final Dictionary dict : mDictionaries) + dict.getBigrams(composer, previousWord, callback); + } + + @Override + public boolean isValidWord(CharSequence word) { + for (final Dictionary dict : mDictionaries) + if (dict.isValidWord(word)) return true; + return false; + } + + @Override + public void close() { + for (final Dictionary dict : mDictionaries) + dict.close(); + } + + public void addDictionary(Dictionary newDict) { + mDictionaries.add(newDict); + } +} |