ContactInfo.java revision 327fb5bb609a6bee44a62888d671c951b19782fd
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 String nameAlternative;
38    public int type;
39    public String label;
40    public String number;
41    public String formattedNumber;
42    public String normalizedNumber;
43    /** The photo for the contact, if available. */
44    public long photoId;
45    /** The high-res photo for the contact, if available. */
46    public Uri photoUri;
47    public boolean isBadData;
48    public String objectId;
49
50    public static ContactInfo EMPTY = new ContactInfo();
51
52    public int sourceType = 0;
53
54    @Override
55    public int hashCode() {
56        // Uses only name and contactUri to determine hashcode.
57        // This should be sufficient to have a reasonable distribution of hash codes.
58        // Moreover, there should be no two people with the same lookupUri.
59        final int prime = 31;
60        int result = 1;
61        result = prime * result + ((lookupUri == null) ? 0 : lookupUri.hashCode());
62        result = prime * result + ((name == null) ? 0 : name.hashCode());
63        return result;
64    }
65
66    @Override
67    public boolean equals(Object obj) {
68        if (this == obj) return true;
69        if (obj == null) return false;
70        if (getClass() != obj.getClass()) return false;
71        ContactInfo other = (ContactInfo) obj;
72        if (!UriUtils.areEqual(lookupUri, other.lookupUri)) return false;
73        if (!TextUtils.equals(name, other.name)) return false;
74        if (!TextUtils.equals(nameAlternative, other.nameAlternative)) return false;
75        if (type != other.type) return false;
76        if (!TextUtils.equals(label, other.label)) return false;
77        if (!TextUtils.equals(number, other.number)) return false;
78        if (!TextUtils.equals(formattedNumber, other.formattedNumber)) return false;
79        if (!TextUtils.equals(normalizedNumber, other.normalizedNumber)) return false;
80        if (photoId != other.photoId) return false;
81        if (!UriUtils.areEqual(photoUri, other.photoUri)) return false;
82        if (!TextUtils.equals(objectId, other.objectId)) return false;
83        return true;
84    }
85
86    @Override
87    public String toString() {
88        return Objects.toStringHelper(this).add("lookupUri", lookupUri).add("name", name)
89                .add("nameAlternative", nameAlternative)
90                .add("type", type).add("label", label)
91                .add("number", number).add("formattedNumber",formattedNumber)
92                .add("normalizedNumber", normalizedNumber).add("photoId", photoId)
93                .add("photoUri", photoUri).add("objectId", objectId).toString();
94    }
95}
96