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 package com.android.settings.intelligence.search.sitemap; 18 19 import android.content.ContentValues; 20 import android.text.TextUtils; 21 22 import com.android.settings.intelligence.search.indexing.IndexDatabaseHelper; 23 24 import java.util.Objects; 25 26 /** 27 * Data model for a parent-child page pair. 28 * <p/> 29 * A list of {@link SiteMapPair} can represent the breadcrumb for a search result from settings. 30 */ 31 public class SiteMapPair { 32 private final String mParentClass; 33 private final String mParentTitle; 34 private final String mChildClass; 35 private final String mChildTitle; 36 SiteMapPair(String parentClass, String parentTitle, String childClass, String childTitle)37 public SiteMapPair(String parentClass, String parentTitle, String childClass, 38 String childTitle) { 39 mParentClass = parentClass; 40 mParentTitle = parentTitle; 41 mChildClass = childClass; 42 mChildTitle = childTitle; 43 } 44 45 @Override hashCode()46 public int hashCode() { 47 return Objects.hash(mParentClass, mChildClass); 48 } 49 50 @Override equals(Object other)51 public boolean equals(Object other) { 52 if (other == null || !(other instanceof SiteMapPair)) { 53 return false; 54 } 55 return TextUtils.equals(mParentClass, ((SiteMapPair) other).mParentClass) 56 && TextUtils.equals(mChildClass, ((SiteMapPair) other).mChildClass); 57 } 58 getParentClass()59 public String getParentClass() { 60 return mParentClass; 61 } 62 getParentTitle()63 public String getParentTitle() { 64 return mParentTitle; 65 } 66 getChildClass()67 public String getChildClass() { 68 return mChildClass; 69 } 70 getChildTitle()71 public String getChildTitle() { 72 return mChildTitle; 73 } 74 75 /** 76 * Converts this object into {@link ContentValues}. The content follows schema in 77 * {@link IndexDatabaseHelper.SiteMapColumns}. 78 */ toContentValue()79 public ContentValues toContentValue() { 80 final ContentValues values = new ContentValues(); 81 values.put(IndexDatabaseHelper.SiteMapColumns.DOCID, hashCode()); 82 values.put(IndexDatabaseHelper.SiteMapColumns.PARENT_CLASS, mParentClass); 83 values.put(IndexDatabaseHelper.SiteMapColumns.PARENT_TITLE, mParentTitle); 84 values.put(IndexDatabaseHelper.SiteMapColumns.CHILD_CLASS, mChildClass); 85 values.put(IndexDatabaseHelper.SiteMapColumns.CHILD_TITLE, mChildTitle); 86 return values; 87 } 88 } 89