From 4250eb27f54f8fedc388fe4825b0646a88778744 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 26 Apr 2011 21:49:09 +0900 Subject: 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 --- .../inputmethod/latin/DictionaryCollection.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 java/src/com/android/inputmethod/latin/DictionaryCollection.java (limited to 'java/src/com/android/inputmethod/latin/DictionaryCollection.java') 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 mDictionaries; + + public DictionaryCollection() { + mDictionaries = new CopyOnWriteArrayList(); + } + + public DictionaryCollection(Dictionary... dictionaries) { + mDictionaries = new CopyOnWriteArrayList(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); + } +} -- cgit v1.2.3-83-g751a