MockCorpora.java revision 04a180b52fb4100a2f3747e795fb5d26e3207a4a
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.quicksearchbox;
18
19import android.content.ComponentName;
20
21import java.util.Collection;
22import java.util.Collections;
23import java.util.HashMap;
24
25
26/**
27 * Mock implementation of {@link Corpora}.
28 */
29public class MockCorpora implements Corpora {
30
31    private HashMap<String,Corpus> mCorporaByName = new HashMap<String,Corpus>();
32    private HashMap<Source,Corpus> mCorporaBySource = new HashMap<Source,Corpus>();
33    private HashMap<ComponentName,Source> mSourcesByName = new HashMap<ComponentName,Source>();
34
35    public void addCorpus(Corpus corpus, Source... sources) {
36        mCorporaByName.put(corpus.getName(), corpus);
37        for (Source source : sources) {
38            mCorporaBySource.put(source, corpus);
39            mSourcesByName.put(source.getComponentName(), source);
40        }
41    }
42
43    public Collection<Corpus> getAllCorpora() {
44        return Collections.unmodifiableCollection(mCorporaByName.values());
45    }
46
47    public Corpus getCorpus(String name) {
48        return mCorporaByName.get(name);
49    }
50
51    public Corpus getCorpusForSource(Source source) {
52        return mCorporaBySource.get(source);
53    }
54
55    public Collection<Corpus> getEnabledCorpora() {
56        return getAllCorpora();
57    }
58
59    public Source getSource(ComponentName name) {
60        return mSourcesByName.get(name);
61    }
62
63    public boolean isCorpusDefaultEnabled(Corpus corpus) {
64        return true;
65    }
66
67    public boolean isCorpusEnabled(Corpus corpus) {
68        return true;
69    }
70
71}
72