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
21/**
22 * Stores a phone number of a call with the country code where it originally occurred. This object
23 * is used as a key in the {@code ContactInfoCache}.
24 *
25 * The country does not necessarily specify the country of the phone number itself, but rather
26 * it is the country in which the user was in when the call was placed or received.
27 */
28public final class NumberWithCountryIso {
29    public final String number;
30    public final String countryIso;
31
32    public NumberWithCountryIso(String number, String countryIso) {
33        this.number = number;
34        this.countryIso = countryIso;
35    }
36
37    @Override
38    public boolean equals(Object o) {
39        if (o == null) return false;
40        if (!(o instanceof NumberWithCountryIso)) return false;
41        NumberWithCountryIso other = (NumberWithCountryIso) o;
42        return TextUtils.equals(number, other.number)
43                && TextUtils.equals(countryIso, other.countryIso);
44    }
45
46    @Override
47    public int hashCode() {
48        int numberHashCode = number == null ? 0 : number.hashCode();
49        int countryHashCode = countryIso == null ? 0 : countryIso.hashCode();
50
51        return numberHashCode ^ countryHashCode;
52    }
53}
54