1/*
2 * Copyright (C) 2015 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.dialer.contactinfo;
18
19import android.text.TextUtils;
20
21import com.android.dialer.calllog.ContactInfo;
22import com.google.common.base.Objects;
23
24/**
25 * A request for contact details for the given number, used by the ContactInfoCache.
26 */
27public final class ContactInfoRequest {
28    /** The number to look-up. */
29    public final String number;
30    /** The country in which a call to or from this number was placed or received. */
31    public final String countryIso;
32    /** The cached contact information stored in the call log. */
33    public final ContactInfo callLogInfo;
34
35    public ContactInfoRequest(String number, String countryIso, ContactInfo callLogInfo) {
36        this.number = number;
37        this.countryIso = countryIso;
38        this.callLogInfo = callLogInfo;
39    }
40
41    @Override
42    public boolean equals(Object obj) {
43        if (this == obj) return true;
44        if (obj == null) return false;
45        if (!(obj instanceof ContactInfoRequest)) return false;
46
47        ContactInfoRequest other = (ContactInfoRequest) obj;
48
49        if (!TextUtils.equals(number, other.number)) return false;
50        if (!TextUtils.equals(countryIso, other.countryIso)) return false;
51        if (!Objects.equal(callLogInfo, other.callLogInfo)) return false;
52
53        return true;
54    }
55
56    @Override
57    public int hashCode() {
58        final int prime = 31;
59        int result = 1;
60        result = prime * result + ((callLogInfo == null) ? 0 : callLogInfo.hashCode());
61        result = prime * result + ((countryIso == null) ? 0 : countryIso.hashCode());
62        result = prime * result + ((number == null) ? 0 : number.hashCode());
63        return result;
64    }
65}
66