1 /* 2 * Copyright (C) 2017 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 */ 17 18 package com.android.settings.intelligence.search.indexing; 19 20 import android.provider.SearchIndexableData; 21 import android.util.Pair; 22 23 import java.util.ArrayList; 24 import java.util.HashMap; 25 import java.util.List; 26 import java.util.Map; 27 import java.util.Set; 28 29 30 /** 31 * Holds Data sources for indexable data. 32 */ 33 public class PreIndexData { 34 35 private final Map<String, List<SearchIndexableData>> mDataToUpdate; 36 private final Map<String, Set<String>> mNonIndexableKeys; 37 private final List<Pair<String, String>> mSiteMapPairs; 38 PreIndexData()39 public PreIndexData() { 40 mDataToUpdate = new HashMap<>(); 41 mNonIndexableKeys = new HashMap<>(); 42 mSiteMapPairs = new ArrayList<>(); 43 } 44 getNonIndexableKeys()45 public Map<String, Set<String>> getNonIndexableKeys() { 46 return mNonIndexableKeys; 47 } 48 getDataToUpdate()49 public Map<String, List<SearchIndexableData>> getDataToUpdate() { 50 return mDataToUpdate; 51 } 52 getSiteMapPairs()53 public List<Pair<String, String>> getSiteMapPairs() { 54 return mSiteMapPairs; 55 } 56 addNonIndexableKeysForAuthority(String authority, Set<String> keys)57 public void addNonIndexableKeysForAuthority(String authority, Set<String> keys) { 58 mNonIndexableKeys.put(authority, keys); 59 } 60 addDataToUpdate(String authority, List<? extends SearchIndexableData> data)61 public void addDataToUpdate(String authority, List<? extends SearchIndexableData> data) { 62 if (data.isEmpty()) { 63 return; 64 } 65 66 List<SearchIndexableData> indexableData = mDataToUpdate.get(authority); 67 if (indexableData == null) { 68 mDataToUpdate.put(authority, new ArrayList<>(data)); 69 } else { 70 indexableData.addAll(data); 71 } 72 } 73 addSiteMapPairs(List<Pair<String, String>> siteMapPairs)74 public void addSiteMapPairs(List<Pair<String, String>> siteMapPairs) { 75 if (siteMapPairs == null) { 76 return; 77 } 78 mSiteMapPairs.addAll(siteMapPairs); 79 } 80 81 } 82