1/*
2 * Copyright (C) 2011 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.calllog;
18
19import android.net.Uri;
20import android.text.TextUtils;
21
22import com.android.contacts.common.util.UriUtils;
23import com.google.common.base.Objects;
24
25/**
26 * Information for a contact as needed by the Call Log.
27 */
28public class ContactInfo {
29    public Uri lookupUri;
30
31    /**
32     * Contact lookup key.  Note this may be a lookup key for a corp contact, in which case
33     * "lookup by lookup key" doesn't work on the personal profile.
34     */
35    public String lookupKey;
36    public String name;
37    public int type;
38    public String label;
39    public String number;
40    public String formattedNumber;
41    public String normalizedNumber;
42    /** The photo for the contact, if available. */
43    public long photoId;
44    /** The high-res photo for the contact, if available. */
45    public Uri photoUri;
46    public boolean isBadData;
47    public String objectId;
48
49    public static ContactInfo EMPTY = new ContactInfo();
50
51    public int sourceType = 0;
52
53    @Override
54    public int hashCode() {
55        // Uses only name and contactUri to determine hashcode.
56        // This should be sufficient to have a reasonable distribution of hash codes.
57        // Moreover, there should be no two people with the same lookupUri.
58        final int prime = 31;
59        int result = 1;
60        result = prime * result + ((lookupUri == null) ? 0 : lookupUri.hashCode());
61        result = prime * result + ((name == null) ? 0 : name.hashCode());
62        return result;
63    }
64
65    @Override
66    public boolean equals(Object obj) {
67        if (this == obj) return true;
68        if (obj == null) return false;
69        if (getClass() != obj.getClass()) return false;
70        ContactInfo other = (ContactInfo) obj;
71        if (!UriUtils.areEqual(lookupUri, other.lookupUri)) return false;
72        if (!TextUtils.equals(name, other.name)) return false;
73        if (type != other.type) return false;
74        if (!TextUtils.equals(label, other.label)) return false;
75        if (!TextUtils.equals(number, other.number)) return false;
76        if (!TextUtils.equals(formattedNumber, other.formattedNumber)) return false;
77        if (!TextUtils.equals(normalizedNumber, other.normalizedNumber)) return false;
78        if (photoId != other.photoId) return false;
79        if (!UriUtils.areEqual(photoUri, other.photoUri)) return false;
80        if (!TextUtils.equals(objectId, other.objectId)) return false;
81        return true;
82    }
83
84    @Override
85    public String toString() {
86        return Objects.toStringHelper(this).add("lookupUri", lookupUri).add("name", name).add(
87                "type", type).add("label", label).add("number", number).add("formattedNumber",
88                formattedNumber).add("normalizedNumber", normalizedNumber).add("photoId", photoId)
89                .add("photoUri", photoUri).add("objectId", objectId).toString();
90    }
91}
92