summaryrefslogtreecommitdiff
path: root/src/com/android/settings/intelligence/search/sitemap/SiteMapPair.java
blob: cf30dc4cd3659ae7b8f722a7f1abc0e35b685416 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Copyright (C) 2017 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.settings.intelligence.search.sitemap;

import android.content.ContentValues;
import android.text.TextUtils;

import com.android.settings.intelligence.search.indexing.IndexDatabaseHelper;

import java.util.Objects;

/**
 * Data model for a parent-child page pair.
 * <p/>
 * A list of {@link SiteMapPair} can represent the breadcrumb for a search result from settings.
 */
public class SiteMapPair {
    private final String mParentClass;
    private final String mParentTitle;
    private final String mChildClass;
    private final String mChildTitle;

    public SiteMapPair(String parentClass, String parentTitle, String childClass,
            String childTitle) {
        mParentClass = parentClass;
        mParentTitle = parentTitle;
        mChildClass = childClass;
        mChildTitle = childTitle;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mParentClass, mChildClass);
    }

    @Override
    public boolean equals(Object other) {
        if (other == null || !(other instanceof SiteMapPair)) {
            return false;
        }
        return TextUtils.equals(mParentClass, ((SiteMapPair) other).mParentClass)
                && TextUtils.equals(mChildClass, ((SiteMapPair) other).mChildClass);
    }

    public String getParentClass() {
        return mParentClass;
    }

    public String getParentTitle() {
        return mParentTitle;
    }

    public String getChildClass() {
        return mChildClass;
    }

    public String getChildTitle() {
        return mChildTitle;
    }

    /**
     * Converts this object into {@link ContentValues}. The content follows schema in
     * {@link IndexDatabaseHelper.SiteMapColumns}.
     */
    public ContentValues toContentValue() {
        final ContentValues values = new ContentValues();
        values.put(IndexDatabaseHelper.SiteMapColumns.DOCID, hashCode());
        values.put(IndexDatabaseHelper.SiteMapColumns.PARENT_CLASS, mParentClass);
        values.put(IndexDatabaseHelper.SiteMapColumns.PARENT_TITLE, mParentTitle);
        values.put(IndexDatabaseHelper.SiteMapColumns.CHILD_CLASS, mChildClass);
        values.put(IndexDatabaseHelper.SiteMapColumns.CHILD_TITLE, mChildTitle);
        return values;
    }
}