summaryrefslogtreecommitdiff
path: root/repackaged/libphonenumber/src/com/android/i18n/phonenumbers/Phonenumber.java
blob: ccd46a0f03a03963cc24b25a5a0c3a1fb6da3a94 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/* GENERATED SOURCE. DO NOT MODIFY. */
/*
 * Copyright (C) 2010 The Libphonenumber Authors
 *
 * 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.
 */

/**
 * Definition of the class representing international telephone numbers. This class is hand-created
 * based on the class file compiled from phonenumber.proto. Please refer to that file for detailed
 * descriptions of the meaning of each field.
 */

package com.android.i18n.phonenumbers;

import java.io.Serializable;

/**
 * @hide This class is not part of the Android public SDK API
 */
public final class Phonenumber {
  private Phonenumber() {}
  /**
   * @hide This class is not part of the Android public SDK API
   */
  public static class PhoneNumber implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * @hide This class is not part of the Android public SDK API
     */
    @android.compat.annotation.UnsupportedAppUsage(implicitMember = "values()[Lcom/android/i18n/phonenumbers/Phonenumber$PhoneNumber$CountryCodeSource;")
    public enum CountryCodeSource {
      @android.compat.annotation.UnsupportedAppUsage
      FROM_NUMBER_WITH_PLUS_SIGN,
      @android.compat.annotation.UnsupportedAppUsage
      FROM_NUMBER_WITH_IDD,
      @android.compat.annotation.UnsupportedAppUsage
      FROM_NUMBER_WITHOUT_PLUS_SIGN,
      @android.compat.annotation.UnsupportedAppUsage
      FROM_DEFAULT_COUNTRY,
      UNSPECIFIED
    }

    public PhoneNumber() {
      countryCodeSource_ = CountryCodeSource.UNSPECIFIED;
    }

    // required int32 country_code = 1;
    private boolean hasCountryCode;
    private int countryCode_ = 0;
    @android.compat.annotation.UnsupportedAppUsage
    public boolean hasCountryCode() { return hasCountryCode; }
    @android.compat.annotation.UnsupportedAppUsage
    public int getCountryCode() { return countryCode_; }
    public PhoneNumber setCountryCode(int value) {
      hasCountryCode = true;
      countryCode_ = value;
      return this;
    }
    @android.compat.annotation.UnsupportedAppUsage
    public PhoneNumber clearCountryCode() {
      hasCountryCode = false;
      countryCode_ = 0;
      return this;
    }

    // required uint64 national_number = 2;
    private boolean hasNationalNumber;
    private long nationalNumber_ = 0L;
    public boolean hasNationalNumber() { return hasNationalNumber; }
    @android.compat.annotation.UnsupportedAppUsage
    public long getNationalNumber() { return nationalNumber_; }
    public PhoneNumber setNationalNumber(long value) {
      hasNationalNumber = true;
      nationalNumber_ = value;
      return this;
    }
    public PhoneNumber clearNationalNumber() {
      hasNationalNumber = false;
      nationalNumber_ = 0L;
      return this;
    }

    // optional string extension = 3;
    private boolean hasExtension;
    private java.lang.String extension_ = "";
    @android.compat.annotation.UnsupportedAppUsage
    public boolean hasExtension() { return hasExtension; }
    @android.compat.annotation.UnsupportedAppUsage
    public String getExtension() { return extension_; }
    public PhoneNumber setExtension(String value) {
      if (value == null) {
        throw new NullPointerException();
      }
      hasExtension = true;
      extension_ = value;
      return this;
    }
    public PhoneNumber clearExtension() {
      hasExtension = false;
      extension_ = "";
      return this;
    }

    // optional bool italian_leading_zero = 4;
    private boolean hasItalianLeadingZero;
    private boolean italianLeadingZero_ = false;
    public boolean hasItalianLeadingZero() { return hasItalianLeadingZero; }
    public boolean isItalianLeadingZero() { return italianLeadingZero_; }
    public PhoneNumber setItalianLeadingZero(boolean value) {
      hasItalianLeadingZero = true;
      italianLeadingZero_ = value;
      return this;
    }
    public PhoneNumber clearItalianLeadingZero() {
      hasItalianLeadingZero = false;
      italianLeadingZero_ = false;
      return this;
    }

    // optional int32 number_of_leading_zeros = 8 [default = 1];
    private boolean hasNumberOfLeadingZeros;
    private int numberOfLeadingZeros_ = 1;
    public boolean hasNumberOfLeadingZeros() { return hasNumberOfLeadingZeros; }
    public int getNumberOfLeadingZeros() { return numberOfLeadingZeros_; }
    public PhoneNumber setNumberOfLeadingZeros(int value) {
      hasNumberOfLeadingZeros = true;
      numberOfLeadingZeros_ = value;
      return this;
    }
    public PhoneNumber clearNumberOfLeadingZeros() {
      hasNumberOfLeadingZeros = false;
      numberOfLeadingZeros_ = 1;
      return this;
    }

    // optional string raw_input = 5;
    private boolean hasRawInput;
    private String rawInput_ = "";
    public boolean hasRawInput() { return hasRawInput; }
    public String getRawInput() { return rawInput_; }
    public PhoneNumber setRawInput(String value) {
      if (value == null) {
        throw new NullPointerException();
      }
      hasRawInput = true;
      rawInput_ = value;
      return this;
    }
    public PhoneNumber clearRawInput() {
      hasRawInput = false;
      rawInput_ = "";
      return this;
    }

    // optional CountryCodeSource country_code_source = 6;
    private boolean hasCountryCodeSource;
    private CountryCodeSource countryCodeSource_;
    public boolean hasCountryCodeSource() { return hasCountryCodeSource; }
    @android.compat.annotation.UnsupportedAppUsage
    public CountryCodeSource getCountryCodeSource() { return countryCodeSource_; }
    public PhoneNumber setCountryCodeSource(CountryCodeSource value) {
      if (value == null) {
        throw new NullPointerException();
      }
      hasCountryCodeSource = true;
      countryCodeSource_ = value;
      return this;
    }
    public PhoneNumber clearCountryCodeSource() {
      hasCountryCodeSource = false;
      countryCodeSource_ = CountryCodeSource.UNSPECIFIED;
      return this;
    }

    // optional string preferred_domestic_carrier_code = 7;
    private boolean hasPreferredDomesticCarrierCode;
    private java.lang.String preferredDomesticCarrierCode_ = "";
    public boolean hasPreferredDomesticCarrierCode() { return hasPreferredDomesticCarrierCode; }
    public String getPreferredDomesticCarrierCode() { return preferredDomesticCarrierCode_; }
    public PhoneNumber setPreferredDomesticCarrierCode(String value) {
      if (value == null) {
        throw new NullPointerException();
      }
      hasPreferredDomesticCarrierCode = true;
      preferredDomesticCarrierCode_ = value;
      return this;
    }
    public PhoneNumber clearPreferredDomesticCarrierCode() {
      hasPreferredDomesticCarrierCode = false;
      preferredDomesticCarrierCode_ = "";
      return this;
    }

    public final PhoneNumber clear() {
      clearCountryCode();
      clearNationalNumber();
      clearExtension();
      clearItalianLeadingZero();
      clearNumberOfLeadingZeros();
      clearRawInput();
      clearCountryCodeSource();
      clearPreferredDomesticCarrierCode();
      return this;
    }

    public PhoneNumber mergeFrom(PhoneNumber other) {
      if (other.hasCountryCode()) {
        setCountryCode(other.getCountryCode());
      }
      if (other.hasNationalNumber()) {
        setNationalNumber(other.getNationalNumber());
      }
      if (other.hasExtension()) {
        setExtension(other.getExtension());
      }
      if (other.hasItalianLeadingZero()) {
        setItalianLeadingZero(other.isItalianLeadingZero());
      }
      if (other.hasNumberOfLeadingZeros()) {
        setNumberOfLeadingZeros(other.getNumberOfLeadingZeros());
      }
      if (other.hasRawInput()) {
        setRawInput(other.getRawInput());
      }
      if (other.hasCountryCodeSource()) {
        setCountryCodeSource(other.getCountryCodeSource());
      }
      if (other.hasPreferredDomesticCarrierCode()) {
        setPreferredDomesticCarrierCode(other.getPreferredDomesticCarrierCode());
      }
      return this;
    }

    public boolean exactlySameAs(PhoneNumber other) {
      if (other == null) {
        return false;
      }
      if (this == other) {
        return true;
      }
      return (countryCode_ == other.countryCode_ && nationalNumber_ == other.nationalNumber_ &&
          extension_.equals(other.extension_) && italianLeadingZero_ == other.italianLeadingZero_ &&
          numberOfLeadingZeros_ == other.numberOfLeadingZeros_ &&
          rawInput_.equals(other.rawInput_) && countryCodeSource_ == other.countryCodeSource_ &&
          preferredDomesticCarrierCode_.equals(other.preferredDomesticCarrierCode_) &&
          hasPreferredDomesticCarrierCode() == other.hasPreferredDomesticCarrierCode());
    }

    @Override
    public boolean equals(Object that) {
      return (that instanceof PhoneNumber) && exactlySameAs((PhoneNumber) that);
    }

    @Override
    public int hashCode() {
      // Simplified rendition of the hashCode function automatically generated from the proto
      // compiler with java_generate_equals_and_hash set to true. We are happy with unset values to
      // be considered equal to their explicitly-set equivalents, so don't check if any value is
      // unknown. The only exception to this is the preferred domestic carrier code.
      int hash = 41;
      hash = (53 * hash) + getCountryCode();
      hash = (53 * hash) + Long.valueOf(getNationalNumber()).hashCode();
      hash = (53 * hash) + getExtension().hashCode();
      hash = (53 * hash) + (isItalianLeadingZero() ? 1231 : 1237);
      hash = (53 * hash) + getNumberOfLeadingZeros();
      hash = (53 * hash) + getRawInput().hashCode();
      hash = (53 * hash) + getCountryCodeSource().hashCode();
      hash = (53 * hash) + getPreferredDomesticCarrierCode().hashCode();
      hash = (53 * hash) + (hasPreferredDomesticCarrierCode() ? 1231 : 1237);
      return hash;
    }

    @Override
    public String toString() {
      StringBuilder outputString = new StringBuilder();
      outputString.append("Country Code: ").append(countryCode_);
      outputString.append(" National Number: ").append(nationalNumber_);
      if (hasItalianLeadingZero() && isItalianLeadingZero()) {
        outputString.append(" Leading Zero(s): true");
      }
      if (hasNumberOfLeadingZeros()) {
        outputString.append(" Number of leading zeros: ").append(numberOfLeadingZeros_);
      }
      if (hasExtension()) {
        outputString.append(" Extension: ").append(extension_);
      }
      if (hasCountryCodeSource()) {
        outputString.append(" Country Code Source: ").append(countryCodeSource_);
      }
      if (hasPreferredDomesticCarrierCode()) {
        outputString.append(" Preferred Domestic Carrier Code: ").
            append(preferredDomesticCarrierCode_);
      }
      return outputString.toString();
    }
  }
}