Commits

Anonymous committed 82557d4

Decouple Phonenumber.java from protocol buffer.

  • Participants
  • Parent commits dd10a3f
  • Branches default

Comments (0)

Files changed (3)

java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java

     if (number.hasExtension()) {
       // We don't want to alter the proto given to us, but we don't want to include the extension
       // when we format it, so we copy it and clear the extension here.
-      PhoneNumber.Builder protoBuilder = PhoneNumber.newBuilder();
-      protoBuilder.mergeFrom(number);
-      protoBuilder.clearExtension();
-      copiedProto = protoBuilder.build();
+      copiedProto = new PhoneNumber();
+      copiedProto.mergeFrom(number);
+      copiedProto.clearExtension();
     } else {
       copiedProto = number;
     }
    */
   public String format(PhoneNumber number, PhoneNumberFormat numberFormat) {
     StringBuffer formattedNumber = new StringBuffer(20);
-    format(number.toBuilder(), numberFormat, formattedNumber);
+    format(number, numberFormat, formattedNumber);
     return formattedNumber.toString();
   }
 
-  // Same as format(PhoneNumber, PhoneNumberFormat), but accepts mutable PhoneNumber.Builder and
-  // StringBuffer as parameters to decrease object creation when invoked many times.
-  public void format(PhoneNumber.Builder number, PhoneNumberFormat numberFormat,
+  // Same as format(PhoneNumber, PhoneNumberFormat), but accepts mutable StringBuffer as parameters
+  // to decrease object creation when invoked many times.
+  public void format(PhoneNumber number, PhoneNumberFormat numberFormat,
                      StringBuffer formattedNumber) {
     // Clear the StringBuffer first.
     formattedNumber.setLength(0);
    * @return  the national significant number of the PhoneNumber object passed in
    */
   public static String getNationalSignificantNumber(PhoneNumber number) {
-    return getNationalSignificantNumber(number.toBuilder());
-  }
-
-  // Same as getNationalSignificantNumber(PhoneNumber), but accepts mutable PhoneNumber.Builder as
-  // a parameter to decrease object creation when invoked many times.
-  public static String getNationalSignificantNumber(PhoneNumber.Builder number) {
     // The leading zero in the national (significant) number of an Italian phone number has a
     // special meaning. Unlike the rest of the world, it indicates the number is a landline
     // number. There have been plans to migrate landline numbers to start with the digit two since
    */
   private void maybeGetFormattedExtension(PhoneNumber number, String regionCode,
                                           StringBuffer formattedNumber) {
-    maybeGetFormattedExtension(number.toBuilder(), regionCode, formattedNumber);
-  }
-
-  private void maybeGetFormattedExtension(PhoneNumber.Builder number, String regionCode,
-                                          StringBuffer formattedNumber) {
     if (number.hasExtension()) {
       // Formats the extension part of the phone number by prefixing it with the appropriate
       // extension prefix. This will be the default extension prefix, unless overridden by a
    *     country code was extracted, this will be left unchanged.
    * @param storeCountryCodeSource  true if the country_code_source field of phoneNumber should be
    *     populated.
-   * @param phoneNumber  the PhoneNumber.Builder object that needs to be populated with country code
+   * @param phoneNumber  the PhoneNumber object that needs to be populated with country code
    *     and country code source. Note the country code is always populated, whereas country code
    *     source is only populated when keepCountryCodeSource is true.
    * @return  the country code extracted or 0 if none could be extracted
    */
   int maybeExtractCountryCode(String number, PhoneMetadata defaultRegionMetadata,
                               StringBuffer nationalNumber, boolean storeCountryCodeSource,
-                              PhoneNumber.Builder phoneNumber)
+                              PhoneNumber phoneNumber)
       throws NumberParseException {
     if (number.length() == 0) {
       return 0;
    */
   public PhoneNumber parse(String numberToParse, String defaultCountry)
       throws NumberParseException {
-    PhoneNumber.Builder phoneNumber = PhoneNumber.newBuilder();
+    PhoneNumber phoneNumber = new PhoneNumber();
     parse(numberToParse, defaultCountry, phoneNumber);
-    return phoneNumber.build();
+    return phoneNumber;
   }
 
-  // Same as parse(String, String), but accepts mutable PhoneNumber.Builder as a parameter to
+  // Same as parse(String, String), but accepts mutable PhoneNumber as a parameter to
   // decrease object creation when invoked many times.
-  public void parse(String numberToParse, String defaultCountry,
-                    PhoneNumber.Builder phoneNumber)
+  public void parse(String numberToParse, String defaultCountry, PhoneNumber phoneNumber)
       throws NumberParseException {
     if (!isValidRegionCode(defaultCountry)) {
       throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE,
    */
   public PhoneNumber parseAndKeepRawInput(String numberToParse, String defaultCountry)
       throws NumberParseException {
-    PhoneNumber.Builder phoneNumber = PhoneNumber.newBuilder();
+    PhoneNumber phoneNumber = new PhoneNumber();
     parseAndKeepRawInput(numberToParse, defaultCountry, phoneNumber);
-    return phoneNumber.build();
+    return phoneNumber;
   }
 
-  // Same as parseAndKeepRawInput(String, String), but accepts mutable PhoneNumber.Builder as a
-  // parameter to decrease object creation when invoked many times.
+  // Same as parseAndKeepRawInput(String, String), but accepts mutable PhoneNumber as a parameter to
+  // decrease object creation when invoked many times.
   public void parseAndKeepRawInput(String numberToParse, String defaultCountry,
-                                   PhoneNumber.Builder phoneNumber)
+                                   PhoneNumber phoneNumber)
       throws NumberParseException {
     if (!isValidRegionCode(defaultCountry)) {
       throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE,
    * isNumberMatch().
    */
   private void parseHelper(String numberToParse, String defaultCountry,
-                           Boolean keepRawInput, PhoneNumber.Builder phoneNumber)
+                           Boolean keepRawInput, PhoneNumber phoneNumber)
       throws NumberParseException {
     // Extract a possible number from the string passed in (this strips leading characters that
     // could not be the start of a phone number.)
    */
   public MatchType isNumberMatch(PhoneNumber firstNumberIn, PhoneNumber secondNumberIn) {
     // Make copies of the phone number so that the numbers passed in are not edited.
-    PhoneNumber.Builder firstNumber = PhoneNumber.newBuilder();
+    PhoneNumber firstNumber = new PhoneNumber();
     firstNumber.mergeFrom(firstNumberIn);
-    PhoneNumber.Builder secondNumber = PhoneNumber.newBuilder();
+    PhoneNumber secondNumber = new PhoneNumber();
     secondNumber.mergeFrom(secondNumberIn);
     // First clear raw_input and country_code_source field and any empty-string extensions so that
-    // we can use the proto-buffer equality method.
+    // we can use the PhoneNumber.exactlySameAs() method.
     firstNumber.clearRawInput();
     firstNumber.clearCountryCodeSource();
     secondNumber.clearRawInput();
         secondNumber.clearExtension();
     }
 
-    PhoneNumber number1 = firstNumber.build();
-    PhoneNumber number2 = secondNumber.build();
-
     // Early exit if both had extensions and these are different.
-    if (number1.hasExtension() && number2.hasExtension() &&
-        !number1.getExtension().equals(number2.getExtension())) {
+    if (firstNumber.hasExtension() && secondNumber.hasExtension() &&
+        !firstNumber.getExtension().equals(secondNumber.getExtension())) {
       return MatchType.NO_MATCH;
     }
-    int firstNumberCountryCode = number1.getCountryCode();
-    int secondNumberCountryCode = number2.getCountryCode();
+    int firstNumberCountryCode = firstNumber.getCountryCode();
+    int secondNumberCountryCode = secondNumber.getCountryCode();
     // Both had country code specified.
     if (firstNumberCountryCode != 0 && secondNumberCountryCode != 0) {
-      if (areSameMessages(number1, number2)) {
+      if (firstNumber.exactlySameAs(secondNumber)) {
         return MatchType.EXACT_MATCH;
       } else if (firstNumberCountryCode == secondNumberCountryCode &&
-                 isNationalNumberSuffixOfTheOther(number1, number2)) {
+                 isNationalNumberSuffixOfTheOther(firstNumber, secondNumber)) {
         // A SHORT_NSN_MATCH occurs if there is a difference because of the presence or absence of
         // an 'Italian leading zero', the presence or absence of an extension, or one NSN being a
         // shorter variant of the other.
     }
     // Checks cases where one or both country codes were not specified. To make equality checks
     // easier, we first set the country codes to be equal.
-    PhoneNumber newNumber =
-        PhoneNumber.newBuilder(number1).setCountryCode(secondNumberCountryCode).build();
+    firstNumber.setCountryCode(secondNumberCountryCode);
     // If all else was the same, then this is an NSN_MATCH.
-    if (areSameMessages(newNumber, number2)) {
+    if (firstNumber.exactlySameAs(secondNumber)) {
       return MatchType.NSN_MATCH;
     }
-    if (isNationalNumberSuffixOfTheOther(newNumber, number2)) {
+    if (isNationalNumberSuffixOfTheOther(firstNumber, secondNumber)) {
       return MatchType.SHORT_NSN_MATCH;
     }
     return MatchType.NO_MATCH;
    */
   public MatchType isNumberMatch(String firstNumber, String secondNumber)
       throws NumberParseException {
-    PhoneNumber.Builder number1 = PhoneNumber.newBuilder();
+    PhoneNumber number1 = new PhoneNumber();
     parseHelper(firstNumber, null, false, number1);
-    PhoneNumber.Builder number2 = PhoneNumber.newBuilder();
+    PhoneNumber number2 = new PhoneNumber();
     parseHelper(secondNumber, null, false, number2);
-    return isNumberMatch(number1.build(), number2.build());
+    return isNumberMatch(number1, number2);
   }
 
   /**
    */
   public MatchType isNumberMatch(PhoneNumber firstNumber, String secondNumber)
       throws NumberParseException {
-    PhoneNumber.Builder number2 = PhoneNumber.newBuilder();
+    PhoneNumber number2 = new PhoneNumber();
     parseHelper(secondNumber, null, false, number2);
-    return isNumberMatch(firstNumber, number2.build());
+    return isNumberMatch(firstNumber, number2);
   }
 }

java/src/com/google/i18n/phonenumbers/Phonenumber.java

-// Generated by the protocol buffer compiler.  DO NOT EDIT!
-// source: phonenumber.proto
+/*
+ * Copyright (C) 2009 Google Inc.
+ *
+ * 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.
+ *
+ * @author Shaopeng Jia
+ */
 
 package com.google.i18n.phonenumbers;
 
+import java.io.Serializable;
+
 public final class Phonenumber {
+
   private Phonenumber() {}
-  public static void registerAllExtensions(
-      com.google.protobuf.ExtensionRegistryLite registry) {
-  }
-  public static final class PhoneNumber extends
-      com.google.protobuf.GeneratedMessageLite {
-    // Use PhoneNumber.newBuilder() to construct.
-    private PhoneNumber() {
-      initFields();
+  public static final class PhoneNumber implements Serializable {
+    public enum CountryCodeSource {
+      FROM_NUMBER_WITH_PLUS_SIGN,
+      FROM_NUMBER_WITH_IDD,
+      FROM_NUMBER_WITHOUT_PLUS_SIGN,
+      FROM_DEFAULT_COUNTRY
     }
-    private PhoneNumber(boolean noInit) {}
-    
-    private static final PhoneNumber defaultInstance;
-    public static PhoneNumber getDefaultInstance() {
-      return defaultInstance;
+
+    public PhoneNumber() {
+      countryCodeSource_ = CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN;
     }
-    
-    public PhoneNumber getDefaultInstanceForType() {
-      return defaultInstance;
-    }
-    
-    public enum CountryCodeSource
-        implements com.google.protobuf.Internal.EnumLite {
-      FROM_NUMBER_WITH_PLUS_SIGN(0, 1),
-      FROM_NUMBER_WITH_IDD(1, 5),
-      FROM_NUMBER_WITHOUT_PLUS_SIGN(2, 10),
-      FROM_DEFAULT_COUNTRY(3, 20),
-      ;
-      
-      
-      public final int getNumber() { return value; }
-      
-      public static CountryCodeSource valueOf(int value) {
-        switch (value) {
-          case 1: return FROM_NUMBER_WITH_PLUS_SIGN;
-          case 5: return FROM_NUMBER_WITH_IDD;
-          case 10: return FROM_NUMBER_WITHOUT_PLUS_SIGN;
-          case 20: return FROM_DEFAULT_COUNTRY;
-          default: return null;
-        }
-      }
-      
-      public static com.google.protobuf.Internal.EnumLiteMap<CountryCodeSource>
-          internalGetValueMap() {
-        return internalValueMap;
-      }
-      private static com.google.protobuf.Internal.EnumLiteMap<CountryCodeSource>
-          internalValueMap =
-            new com.google.protobuf.Internal.EnumLiteMap<CountryCodeSource>() {
-              public CountryCodeSource findValueByNumber(int number) {
-                return CountryCodeSource.valueOf(number)
-      ;        }
-            };
-      
-      private final int index;
-      private final int value;
-      private CountryCodeSource(int index, int value) {
-        this.index = index;
-        this.value = value;
-      }
-      
-      // @@protoc_insertion_point(enum_scope:i18n.phonenumbers.PhoneNumber.CountryCodeSource)
-    }
-    
+
     // required int32 country_code = 1;
-    public static final int COUNTRY_CODE_FIELD_NUMBER = 1;
     private boolean hasCountryCode;
     private int countryCode_ = 0;
     public boolean hasCountryCode() { return hasCountryCode; }
     public int getCountryCode() { return countryCode_; }
-    
+    public PhoneNumber setCountryCode(int value) {
+      hasCountryCode = true;
+      countryCode_ = value;
+      return this;
+    }
+    public PhoneNumber clearCountryCode() {
+      hasCountryCode = false;
+      countryCode_ = 0;
+      return this;
+    }
+
     // required uint64 national_number = 2;
-    public static final int NATIONAL_NUMBER_FIELD_NUMBER = 2;
     private boolean hasNationalNumber;
     private long nationalNumber_ = 0L;
     public boolean hasNationalNumber() { return hasNationalNumber; }
     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;
-    public static final int EXTENSION_FIELD_NUMBER = 3;
     private boolean hasExtension;
     private java.lang.String extension_ = "";
     public boolean hasExtension() { return hasExtension; }
-    public java.lang.String getExtension() { return extension_; }
-    
+    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;
-    public static final int ITALIAN_LEADING_ZERO_FIELD_NUMBER = 4;
     private boolean hasItalianLeadingZero;
     private boolean italianLeadingZero_ = false;
     public boolean hasItalianLeadingZero() { return hasItalianLeadingZero; }
     public boolean getItalianLeadingZero() { return italianLeadingZero_; }
-    
+    public PhoneNumber setItalianLeadingZero(boolean value) {
+      hasItalianLeadingZero = true;
+      italianLeadingZero_ = value;
+      return this;
+    }
+    public PhoneNumber clearItalianLeadingZero() {
+      hasItalianLeadingZero = false;
+      italianLeadingZero_ = false;
+      return this;
+    }
+
     // optional string raw_input = 5;
-    public static final int RAW_INPUT_FIELD_NUMBER = 5;
     private boolean hasRawInput;
-    private java.lang.String rawInput_ = "";
+    private String rawInput_ = "";
     public boolean hasRawInput() { return hasRawInput; }
-    public java.lang.String getRawInput() { return rawInput_; }
-    
-    // optional .i18n.phonenumbers.PhoneNumber.CountryCodeSource country_code_source = 6;
-    public static final int COUNTRY_CODE_SOURCE_FIELD_NUMBER = 6;
+    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 com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource countryCodeSource_;
+    private CountryCodeSource countryCodeSource_;
     public boolean hasCountryCodeSource() { return hasCountryCodeSource; }
-    public com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource getCountryCodeSource() { return countryCodeSource_; }
-    
-    private void initFields() {
-      countryCodeSource_ = com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN;
+    public CountryCodeSource getCountryCodeSource() { return countryCodeSource_; }
+    public PhoneNumber setCountryCodeSource(CountryCodeSource value) {
+      if (value == null) {
+        throw new NullPointerException();
+      }
+      hasCountryCodeSource = true;
+      countryCodeSource_ = value;
+      return this;
     }
-    public final boolean isInitialized() {
-      if (!hasCountryCode) return false;
-      if (!hasNationalNumber) return false;
-      return true;
+    public PhoneNumber clearCountryCodeSource() {
+      hasCountryCodeSource = false;
+      countryCodeSource_ = CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN;
+      return this;
     }
-    
-    public void writeTo(com.google.protobuf.CodedOutputStream output)
-                        throws java.io.IOException {
-      getSerializedSize();
-      if (hasCountryCode()) {
-        output.writeInt32(1, getCountryCode());
+
+    public final PhoneNumber clear() {
+      clearCountryCode();
+      clearNationalNumber();
+      clearExtension();
+      clearItalianLeadingZero();
+      clearRawInput();
+      clearCountryCodeSource();
+      return this;
+    }
+
+    public PhoneNumber mergeFrom(PhoneNumber other) {
+      if (other.hasCountryCode()) {
+        setCountryCode(other.getCountryCode());
       }
-      if (hasNationalNumber()) {
-        output.writeUInt64(2, getNationalNumber());
+      if (other.hasNationalNumber()) {
+        setNationalNumber(other.getNationalNumber());
       }
-      if (hasExtension()) {
-        output.writeString(3, getExtension());
+      if (other.hasExtension()) {
+        setExtension(other.getExtension());
       }
-      if (hasItalianLeadingZero()) {
-        output.writeBool(4, getItalianLeadingZero());
+      if (other.hasItalianLeadingZero()) {
+        setItalianLeadingZero(other.getItalianLeadingZero());
       }
-      if (hasRawInput()) {
-        output.writeString(5, getRawInput());
+      if (other.hasRawInput()) {
+        setRawInput(other.getRawInput());
       }
-      if (hasCountryCodeSource()) {
-        output.writeEnum(6, getCountryCodeSource().getNumber());
+      if (other.hasCountryCodeSource()) {
+        setCountryCodeSource(other.getCountryCodeSource());
       }
+      return this;
     }
-    
-    private int memoizedSerializedSize = -1;
-    public int getSerializedSize() {
-      int size = memoizedSerializedSize;
-      if (size != -1) return size;
-    
-      size = 0;
-      if (hasCountryCode()) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeInt32Size(1, getCountryCode());
-      }
-      if (hasNationalNumber()) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeUInt64Size(2, getNationalNumber());
-      }
-      if (hasExtension()) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeStringSize(3, getExtension());
-      }
-      if (hasItalianLeadingZero()) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeBoolSize(4, getItalianLeadingZero());
-      }
-      if (hasRawInput()) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeStringSize(5, getRawInput());
-      }
-      if (hasCountryCodeSource()) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeEnumSize(6, getCountryCodeSource().getNumber());
-      }
-      memoizedSerializedSize = size;
-      return size;
+
+    public boolean exactlySameAs(PhoneNumber other) {
+      return (countryCode_ == other.countryCode_ && nationalNumber_ == other.nationalNumber_ &&
+          extension_.equals(other.extension_) && italianLeadingZero_ == other.italianLeadingZero_ &&
+          rawInput_.equals(other.rawInput_) && countryCodeSource_ == other.countryCodeSource_);
     }
-    
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseFrom(
-        com.google.protobuf.ByteString data)
-        throws com.google.protobuf.InvalidProtocolBufferException {
-      return newBuilder().mergeFrom(data).buildParsed();
-    }
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseFrom(
-        com.google.protobuf.ByteString data,
-        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
-        throws com.google.protobuf.InvalidProtocolBufferException {
-      return newBuilder().mergeFrom(data, extensionRegistry)
-               .buildParsed();
-    }
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseFrom(byte[] data)
-        throws com.google.protobuf.InvalidProtocolBufferException {
-      return newBuilder().mergeFrom(data).buildParsed();
-    }
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseFrom(
-        byte[] data,
-        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
-        throws com.google.protobuf.InvalidProtocolBufferException {
-      return newBuilder().mergeFrom(data, extensionRegistry)
-               .buildParsed();
-    }
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseFrom(java.io.InputStream input)
-        throws java.io.IOException {
-      return newBuilder().mergeFrom(input).buildParsed();
-    }
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseFrom(
-        java.io.InputStream input,
-        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
-        throws java.io.IOException {
-      return newBuilder().mergeFrom(input, extensionRegistry)
-               .buildParsed();
-    }
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseDelimitedFrom(java.io.InputStream input)
-        throws java.io.IOException {
-      Builder builder = newBuilder();
-      if (builder.mergeDelimitedFrom(input)) {
-        return builder.buildParsed();
-      } else {
-        return null;
-      }
-    }
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseDelimitedFrom(
-        java.io.InputStream input,
-        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
-        throws java.io.IOException {
-      Builder builder = newBuilder();
-      if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
-        return builder.buildParsed();
-      } else {
-        return null;
-      }
-    }
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseFrom(
-        com.google.protobuf.CodedInputStream input)
-        throws java.io.IOException {
-      return newBuilder().mergeFrom(input).buildParsed();
-    }
-    public static com.google.i18n.phonenumbers.Phonenumber.PhoneNumber parseFrom(
-        com.google.protobuf.CodedInputStream input,
-        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
-        throws java.io.IOException {
-      return newBuilder().mergeFrom(input, extensionRegistry)
-               .buildParsed();
-    }
-    
-    public static Builder newBuilder() { return Builder.create(); }
-    public Builder newBuilderForType() { return newBuilder(); }
-    public static Builder newBuilder(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber prototype) {
-      return newBuilder().mergeFrom(prototype);
-    }
-    public Builder toBuilder() { return newBuilder(this); }
-    
-    public static final class Builder extends
-        com.google.protobuf.GeneratedMessageLite.Builder<
-          com.google.i18n.phonenumbers.Phonenumber.PhoneNumber, Builder> {
-      private com.google.i18n.phonenumbers.Phonenumber.PhoneNumber result;
-      
-      // Construct using com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.newBuilder()
-      private Builder() {}
-      
-      private static Builder create() {
-        Builder builder = new Builder();
-        builder.result = new com.google.i18n.phonenumbers.Phonenumber.PhoneNumber();
-        return builder;
-      }
-      
-      protected com.google.i18n.phonenumbers.Phonenumber.PhoneNumber internalGetResult() {
-        return result;
-      }
-      
-      public Builder clear() {
-        if (result == null) {
-          throw new IllegalStateException(
-            "Cannot call clear() after build().");
-        }
-        result = new com.google.i18n.phonenumbers.Phonenumber.PhoneNumber();
-        return this;
-      }
-      
-      public Builder clone() {
-        return create().mergeFrom(result);
-      }
-      
-      public com.google.i18n.phonenumbers.Phonenumber.PhoneNumber getDefaultInstanceForType() {
-        return com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.getDefaultInstance();
-      }
-      
-      public boolean isInitialized() {
-        return result.isInitialized();
-      }
-      public com.google.i18n.phonenumbers.Phonenumber.PhoneNumber build() {
-        if (result != null && !isInitialized()) {
-          throw newUninitializedMessageException(result);
-        }
-        return buildPartial();
-      }
-      
-      private com.google.i18n.phonenumbers.Phonenumber.PhoneNumber buildParsed()
-          throws com.google.protobuf.InvalidProtocolBufferException {
-        if (!isInitialized()) {
-          throw newUninitializedMessageException(
-            result).asInvalidProtocolBufferException();
-        }
-        return buildPartial();
-      }
-      
-      public com.google.i18n.phonenumbers.Phonenumber.PhoneNumber buildPartial() {
-        if (result == null) {
-          throw new IllegalStateException(
-            "build() has already been called on this Builder.");
-        }
-        com.google.i18n.phonenumbers.Phonenumber.PhoneNumber returnMe = result;
-        result = null;
-        return returnMe;
-      }
-      
-      public Builder mergeFrom(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber other) {
-        if (other == com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.getDefaultInstance()) return this;
-        if (other.hasCountryCode()) {
-          setCountryCode(other.getCountryCode());
-        }
-        if (other.hasNationalNumber()) {
-          setNationalNumber(other.getNationalNumber());
-        }
-        if (other.hasExtension()) {
-          setExtension(other.getExtension());
-        }
-        if (other.hasItalianLeadingZero()) {
-          setItalianLeadingZero(other.getItalianLeadingZero());
-        }
-        if (other.hasRawInput()) {
-          setRawInput(other.getRawInput());
-        }
-        if (other.hasCountryCodeSource()) {
-          setCountryCodeSource(other.getCountryCodeSource());
-        }
-        return this;
-      }
-      
-      public Builder mergeFrom(
-          com.google.protobuf.CodedInputStream input,
-          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
-          throws java.io.IOException {
-        while (true) {
-          int tag = input.readTag();
-          switch (tag) {
-            case 0:
-              return this;
-            default: {
-              if (!parseUnknownField(input, extensionRegistry, tag)) {
-                return this;
-              }
-              break;
-            }
-            case 8: {
-              setCountryCode(input.readInt32());
-              break;
-            }
-            case 16: {
-              setNationalNumber(input.readUInt64());
-              break;
-            }
-            case 26: {
-              setExtension(input.readString());
-              break;
-            }
-            case 32: {
-              setItalianLeadingZero(input.readBool());
-              break;
-            }
-            case 42: {
-              setRawInput(input.readString());
-              break;
-            }
-            case 48: {
-              int rawValue = input.readEnum();
-              com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource value = com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource.valueOf(rawValue);
-              if (value != null) {
-                setCountryCodeSource(value);
-              }
-              break;
-            }
-          }
-        }
-      }
-      
-      
-      // required int32 country_code = 1;
-      public boolean hasCountryCode() {
-        return result.hasCountryCode();
-      }
-      public int getCountryCode() {
-        return result.getCountryCode();
-      }
-      public Builder setCountryCode(int value) {
-        result.hasCountryCode = true;
-        result.countryCode_ = value;
-        return this;
-      }
-      public Builder clearCountryCode() {
-        result.hasCountryCode = false;
-        result.countryCode_ = 0;
-        return this;
-      }
-      
-      // required uint64 national_number = 2;
-      public boolean hasNationalNumber() {
-        return result.hasNationalNumber();
-      }
-      public long getNationalNumber() {
-        return result.getNationalNumber();
-      }
-      public Builder setNationalNumber(long value) {
-        result.hasNationalNumber = true;
-        result.nationalNumber_ = value;
-        return this;
-      }
-      public Builder clearNationalNumber() {
-        result.hasNationalNumber = false;
-        result.nationalNumber_ = 0L;
-        return this;
-      }
-      
-      // optional string extension = 3;
-      public boolean hasExtension() {
-        return result.hasExtension();
-      }
-      public java.lang.String getExtension() {
-        return result.getExtension();
-      }
-      public Builder setExtension(java.lang.String value) {
-        if (value == null) {
-    throw new NullPointerException();
   }
-  result.hasExtension = true;
-        result.extension_ = value;
-        return this;
-      }
-      public Builder clearExtension() {
-        result.hasExtension = false;
-        result.extension_ = getDefaultInstance().getExtension();
-        return this;
-      }
-      
-      // optional bool italian_leading_zero = 4;
-      public boolean hasItalianLeadingZero() {
-        return result.hasItalianLeadingZero();
-      }
-      public boolean getItalianLeadingZero() {
-        return result.getItalianLeadingZero();
-      }
-      public Builder setItalianLeadingZero(boolean value) {
-        result.hasItalianLeadingZero = true;
-        result.italianLeadingZero_ = value;
-        return this;
-      }
-      public Builder clearItalianLeadingZero() {
-        result.hasItalianLeadingZero = false;
-        result.italianLeadingZero_ = false;
-        return this;
-      }
-      
-      // optional string raw_input = 5;
-      public boolean hasRawInput() {
-        return result.hasRawInput();
-      }
-      public java.lang.String getRawInput() {
-        return result.getRawInput();
-      }
-      public Builder setRawInput(java.lang.String value) {
-        if (value == null) {
-    throw new NullPointerException();
-  }
-  result.hasRawInput = true;
-        result.rawInput_ = value;
-        return this;
-      }
-      public Builder clearRawInput() {
-        result.hasRawInput = false;
-        result.rawInput_ = getDefaultInstance().getRawInput();
-        return this;
-      }
-      
-      // optional .i18n.phonenumbers.PhoneNumber.CountryCodeSource country_code_source = 6;
-      public boolean hasCountryCodeSource() {
-        return result.hasCountryCodeSource();
-      }
-      public com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource getCountryCodeSource() {
-        return result.getCountryCodeSource();
-      }
-      public Builder setCountryCodeSource(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource value) {
-        if (value == null) {
-          throw new NullPointerException();
-        }
-        result.hasCountryCodeSource = true;
-        result.countryCodeSource_ = value;
-        return this;
-      }
-      public Builder clearCountryCodeSource() {
-        result.hasCountryCodeSource = false;
-        result.countryCodeSource_ = com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN;
-        return this;
-      }
-      
-      // @@protoc_insertion_point(builder_scope:i18n.phonenumbers.PhoneNumber)
-    }
-    
-    static {
-      defaultInstance = new PhoneNumber(true);
-      com.google.i18n.phonenumbers.Phonenumber.internalForceInit();
-      defaultInstance.initFields();
-    }
-    
-    // @@protoc_insertion_point(class_scope:i18n.phonenumbers.PhoneNumber)
-  }
-  
-  
-  static {
-  }
-  
-  public static void internalForceInit() {}
-  
-  // @@protoc_insertion_point(outer_class_scope)
 }

java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java

     super.tearDown();
   }
 
-  private Boolean assertEquals(MessageLite message1, MessageLite message2) {
+  private boolean assertEquals(PhoneNumber number1, PhoneNumber number2) {
+    if (number1 == null && number2 == null) {
+      return true;
+    }
+    if (number1 == null || number2 == null) {
+      return false;
+    }
+    return number1.exactlySameAs(number2);
+  }
+
+  private boolean assertEquals(MessageLite message1, MessageLite message2) {
     return PhoneNumberUtil.areSameMessages(message1, message2);
   }
 
   }
 
   public void testGetLengthOfGeographicalAreaCode() {
+    PhoneNumber number = new PhoneNumber();
     // Google MTV, which has area code "650".
-    PhoneNumber usNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6502530000L).build();
-    assertEquals(3, phoneUtil.getLengthOfGeographicalAreaCode(usNumber1));
+    number.setCountryCode(1).setNationalNumber(6502530000L);
+    assertEquals(3, phoneUtil.getLengthOfGeographicalAreaCode(number));
 
     // A North America toll-free number, which has no area code.
-    PhoneNumber usNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(8002530000L).build();
-    assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(usNumber2));
+    number.setCountryCode(1).setNationalNumber(8002530000L);
+    assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(number));
 
     // An invalid US number (1 digit shorter), which has no area code.
-    PhoneNumber usNumber3 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(650253000L).build();
-    assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(usNumber3));
+    number.setCountryCode(1).setNationalNumber(650253000L);
+    assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(number));
 
     // Google London, which has area code "20".
-    PhoneNumber ukNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(2070313000L).build();
-    assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(ukNumber1));
+    number.setCountryCode(44).setNationalNumber(2070313000L);
+    assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(number));
 
     // A UK mobile phone, which has no area code.
-    PhoneNumber ukNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(7123456789L).build();
-    assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(ukNumber2));
+    number.setCountryCode(44).setNationalNumber(7123456789L);
+    assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(number));
 
     // Google Buenos Aires, which has area code "11".
-    PhoneNumber arNumber =
-        PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(1155303000L).build();
-    assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(arNumber));
+    number.setCountryCode(54).setNationalNumber(1155303000L);
+    assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(number));
 
     // Google Sydney, which has area code "2".
-    PhoneNumber auNumber =
-        PhoneNumber.newBuilder().setCountryCode(61).setNationalNumber(293744000L).build();
-    assertEquals(1, phoneUtil.getLengthOfGeographicalAreaCode(auNumber));
+    number.setCountryCode(61).setNationalNumber(293744000L);
+    assertEquals(1, phoneUtil.getLengthOfGeographicalAreaCode(number));
 
     // Google Singapore. Singapore has no area code and no national prefix.
-    PhoneNumber sgNumber =
-        PhoneNumber.newBuilder().setCountryCode(65).setNationalNumber(65218000L).build();
-    assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(sgNumber));
+    number.setCountryCode(65).setNationalNumber(65218000L);
+    assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(number));
   }
 
   public void testGetNationalSignificantNumber() {
-    PhoneNumber usNumber =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6502530000L).build();
-    assertEquals("6502530000", PhoneNumberUtil.getNationalSignificantNumber(usNumber));
+    PhoneNumber number = new PhoneNumber();
+    number.setCountryCode(1).setNationalNumber(6502530000L);
+    assertEquals("6502530000", PhoneNumberUtil.getNationalSignificantNumber(number));
 
     // An Italian mobile number.
-    PhoneNumber itNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(312345678L).build();
-    assertEquals("312345678", PhoneNumberUtil.getNationalSignificantNumber(itNumber1));
+    number.setCountryCode(39).setNationalNumber(312345678L);
+    assertEquals("312345678", PhoneNumberUtil.getNationalSignificantNumber(number));
 
     // An Italian fixed line number.
-    PhoneNumber itNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(236618300L)
-            .setItalianLeadingZero(true).build();
-    assertEquals("0236618300", PhoneNumberUtil.getNationalSignificantNumber(itNumber2));
+    number.setCountryCode(39).setNationalNumber(236618300L).setItalianLeadingZero(true);
+    assertEquals("0236618300", PhoneNumberUtil.getNationalSignificantNumber(number));
   }
 
   public void testGetExampleNumber() throws IOException {
-    PhoneNumber deNumber =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(30123456).build();
+    PhoneNumber deNumber = new PhoneNumber();
+    deNumber.setCountryCode(49).setNationalNumber(30123456);
     assertEquals(deNumber, phoneUtil.getExampleNumber("DE"));
     assertEquals(deNumber, phoneUtil.getExampleNumber("de"));
 
   }
 
   public void testFormatUSNumber() {
-    PhoneNumber usNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6502530000L).build();
-    assertEquals("650 253 0000", phoneUtil.format(usNumber1,
+    PhoneNumber usNumber = new PhoneNumber();
+    usNumber.setCountryCode(1).setNationalNumber(6502530000L);
+    assertEquals("650 253 0000", phoneUtil.format(usNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+1 650 253 0000",
-                 phoneUtil.format(usNumber1,
+                 phoneUtil.format(usNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
 
-    PhoneNumber usNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(8002530000L).build();
-    assertEquals("800 253 0000", phoneUtil.format(usNumber2,
+    usNumber.clear();
+    usNumber.setCountryCode(1).setNationalNumber(8002530000L);
+    assertEquals("800 253 0000", phoneUtil.format(usNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+1 800 253 0000",
-                 phoneUtil.format(usNumber2,
+                 phoneUtil.format(usNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
 
-    PhoneNumber usNumber3 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(9002530000L).build();
-    assertEquals("900 253 0000", phoneUtil.format(usNumber3,
+    usNumber.clear();
+    usNumber.setCountryCode(1).setNationalNumber(9002530000L);
+    assertEquals("900 253 0000", phoneUtil.format(usNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+1 900 253 0000",
-                 phoneUtil.format(usNumber3,
+                 phoneUtil.format(usNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
   }
 
   public void testFormatBSNumber() {
-    PhoneNumber bsNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2421234567L).build();
-    assertEquals("242 123 4567", phoneUtil.format(bsNumber1,
+    PhoneNumber bsNumber = new PhoneNumber();
+    bsNumber.setCountryCode(1).setNationalNumber(2421234567L);
+    assertEquals("242 123 4567", phoneUtil.format(bsNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+1 242 123 4567",
-                 phoneUtil.format(bsNumber1,
+                 phoneUtil.format(bsNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
 
-    PhoneNumber bsNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(8002530000L).build();
-    assertEquals("800 253 0000", phoneUtil.format(bsNumber2,
+    bsNumber.clear();
+    bsNumber.setCountryCode(1).setNationalNumber(8002530000L);
+    assertEquals("800 253 0000", phoneUtil.format(bsNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+1 800 253 0000",
-                 phoneUtil.format(bsNumber2,
+                 phoneUtil.format(bsNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
 
-    PhoneNumber bsNumber3 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(9002530000L).build();
-    assertEquals("900 253 0000", phoneUtil.format(bsNumber3,
+    bsNumber.clear();
+    bsNumber.setCountryCode(1).setNationalNumber(9002530000L);
+    assertEquals("900 253 0000", phoneUtil.format(bsNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+1 900 253 0000",
-                 phoneUtil.format(bsNumber3,
+                 phoneUtil.format(bsNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
   }
 
   public void testFormatGBNumber() {
-    PhoneNumber gbNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(2087389353L).build();
-    assertEquals("(020) 8738 9353", phoneUtil.format(gbNumber1,
+    PhoneNumber gbNumber = new PhoneNumber();
+    gbNumber.setCountryCode(44).setNationalNumber(2087389353L);
+    assertEquals("(020) 8738 9353", phoneUtil.format(gbNumber,
                                                      PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+44 20 8738 9353",
-                 phoneUtil.format(gbNumber1,
+                 phoneUtil.format(gbNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
 
-    PhoneNumber gbNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(7912345678L).build();
-    assertEquals("(07912) 345 678", phoneUtil.format(gbNumber2,
+    gbNumber.clear();
+    gbNumber.setCountryCode(44).setNationalNumber(7912345678L);
+    assertEquals("(07912) 345 678", phoneUtil.format(gbNumber,
                                                      PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+44 7912 345 678",
-                 phoneUtil.format(gbNumber2,
+                 phoneUtil.format(gbNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
   }
 
   public void testFormatDENumber() {
-    PhoneNumber deNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(301234L).build();
-    assertEquals("030 1234", phoneUtil.format(deNumber1,
+    PhoneNumber deNumber = new PhoneNumber();
+    deNumber.setCountryCode(49).setNationalNumber(301234L);
+    assertEquals("030 1234", phoneUtil.format(deNumber,
                                               PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+49 30 1234",
-                 phoneUtil.format(deNumber1,
+                 phoneUtil.format(deNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
 
-    PhoneNumber deNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(291123L).build();
-    assertEquals("0291 123", phoneUtil.format(deNumber2,
+    deNumber.clear();
+    deNumber.setCountryCode(49).setNationalNumber(291123L);
+    assertEquals("0291 123", phoneUtil.format(deNumber,
                                               PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+49 291 123",
-                 phoneUtil.format(deNumber2,
+                 phoneUtil.format(deNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
 
-    PhoneNumber deNumber3 =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(29112345678L).build();
-    assertEquals("0291 12345678", phoneUtil.format(deNumber3,
+    deNumber.clear();
+    deNumber.setCountryCode(49).setNationalNumber(29112345678L);
+    assertEquals("0291 12345678", phoneUtil.format(deNumber,
                                                    PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+49 291 12345678",
-                 phoneUtil.format(deNumber3,
+                 phoneUtil.format(deNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
 
-    PhoneNumber deNumber4 =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(9123123L).build();
-    assertEquals("09123 123", phoneUtil.format(deNumber4,
+    deNumber.clear();
+    deNumber.setCountryCode(49).setNationalNumber(9123123L);
+    assertEquals("09123 123", phoneUtil.format(deNumber,
                                                PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+49 9123 123",
-                 phoneUtil.format(deNumber4,
+                 phoneUtil.format(deNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
-    PhoneNumber deNumber5 =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(1234L).build();
+    deNumber.clear();
+    deNumber.setCountryCode(49).setNationalNumber(1234L);
     // Note this number is correctly formatted without national prefix. Most of the numbers that
     // are treated as invalid numbers by the library are short numbers, and they are usually not
     // dialed with national prefix.
-    assertEquals("1234", phoneUtil.format(deNumber5,
+    assertEquals("1234", phoneUtil.format(deNumber,
                                           PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+49 1234",
-                 phoneUtil.format(deNumber5,
+                 phoneUtil.format(deNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
   }
 
   public void testFormatITNumber() {
-    PhoneNumber itNumber1 =
-        PhoneNumber.newBuilder()
-            .setCountryCode(39).setNationalNumber(236618300L).setItalianLeadingZero(true).build();
-    assertEquals("02 3661 8300", phoneUtil.format(itNumber1,
+    PhoneNumber itNumber = new PhoneNumber();
+    itNumber.setCountryCode(39).setNationalNumber(236618300L).setItalianLeadingZero(true);
+    assertEquals("02 3661 8300", phoneUtil.format(itNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+39 02 3661 8300",
-                 phoneUtil.format(itNumber1,
+                 phoneUtil.format(itNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
     assertEquals("+390236618300",
-                 phoneUtil.format(itNumber1,
+                 phoneUtil.format(itNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.E164));
 
-    PhoneNumber itNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(345678901L).build();
-    assertEquals("345 678 901", phoneUtil.format(itNumber2,
+    itNumber.clear();
+    itNumber.setCountryCode(39).setNationalNumber(345678901L);
+    assertEquals("345 678 901", phoneUtil.format(itNumber,
                                                  PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+39 345 678 901",
-                 phoneUtil.format(itNumber2,
+                 phoneUtil.format(itNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
     assertEquals("+39345678901",
-                 phoneUtil.format(itNumber2,
-                                  PhoneNumberUtil.PhoneNumberFormat.E164));
-  }
+                 phoneUtil.format(itNumber,
+                                  PhoneNumberUtil.PhoneNumberFormat.E164));  }
 
   public void testFormatAUNumber() {
-    PhoneNumber auNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(61).setNationalNumber(236618300L).build();
-    assertEquals("02 3661 8300", phoneUtil.format(auNumber1,
+    PhoneNumber auNumber = new PhoneNumber();
+    auNumber.setCountryCode(61).setNationalNumber(236618300L);
+    assertEquals("02 3661 8300", phoneUtil.format(auNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+61 2 3661 8300",
-                 phoneUtil.format(auNumber1,
+                 phoneUtil.format(auNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
     assertEquals("+61236618300",
-                 phoneUtil.format(auNumber1,
+                 phoneUtil.format(auNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.E164));
 
-    PhoneNumber auNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(61).setNationalNumber(1800123456L).build();
-    assertEquals("1800 123 456", phoneUtil.format(auNumber2,
+    auNumber.clear();
+    auNumber.setCountryCode(61).setNationalNumber(1800123456L);
+    assertEquals("1800 123 456", phoneUtil.format(auNumber,
                                                  PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+61 1800 123 456",
-                 phoneUtil.format(auNumber2,
+                 phoneUtil.format(auNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
     assertEquals("+611800123456",
-                 phoneUtil.format(auNumber2,
+                 phoneUtil.format(auNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.E164));
   }
 
   public void testFormatARNumber() {
-    PhoneNumber arNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(1187654321L).build();
-    assertEquals("011 8765-4321", phoneUtil.format(arNumber1,
+    PhoneNumber arNumber = new PhoneNumber();
+    arNumber.setCountryCode(54).setNationalNumber(1187654321L);
+    assertEquals("011 8765-4321", phoneUtil.format(arNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+54 11 8765-4321",
-                 phoneUtil.format(arNumber1,
+                 phoneUtil.format(arNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
     assertEquals("+541187654321",
-                 phoneUtil.format(arNumber1,
+                 phoneUtil.format(arNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.E164));
 
-    PhoneNumber arNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(91187654321L).build();
-    assertEquals("011 15 8765-4321", phoneUtil.format(arNumber2,
+    arNumber.clear();
+    arNumber.setCountryCode(54).setNationalNumber(91187654321L);
+    assertEquals("011 15 8765-4321", phoneUtil.format(arNumber,
                                                       PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     assertEquals("+54 9 11 8765 4321",
-                 phoneUtil.format(arNumber2,
+                 phoneUtil.format(arNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
     assertEquals("+5491187654321",
-                 phoneUtil.format(arNumber2,
+                 phoneUtil.format(arNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.E164));
   }
 
   public void testFormatOutOfCountryCallingNumber() {
-    PhoneNumber usNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(9002530000L).build();
+    PhoneNumber usNumber = new PhoneNumber();
+    usNumber.setCountryCode(1).setNationalNumber(9002530000L);
     assertEquals("00 1 900 253 0000",
-                 phoneUtil.formatOutOfCountryCallingNumber(usNumber1, "DE"));
+                 phoneUtil.formatOutOfCountryCallingNumber(usNumber, "DE"));
 
-    PhoneNumber usNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6502530000L).build();
+    usNumber.clear();
+    usNumber.setCountryCode(1).setNationalNumber(6502530000L);
     assertEquals("1 650 253 0000",
-                 phoneUtil.formatOutOfCountryCallingNumber(usNumber2, "BS"));
+                 phoneUtil.formatOutOfCountryCallingNumber(usNumber, "BS"));
 
     assertEquals("0~0 1 650 253 0000",
-                 phoneUtil.formatOutOfCountryCallingNumber(usNumber2, "PL"));
+                 phoneUtil.formatOutOfCountryCallingNumber(usNumber, "PL"));
 
-    PhoneNumber gbNumber =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(7912345678L).build();
+    PhoneNumber gbNumber = new PhoneNumber();
+    gbNumber.setCountryCode(44).setNationalNumber(7912345678L);
     assertEquals("011 44 7912 345 678",
                  phoneUtil.formatOutOfCountryCallingNumber(gbNumber, "US"));
 
-    PhoneNumber deNumber =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(1234L).build();
+    PhoneNumber deNumber = new PhoneNumber();
+    deNumber.setCountryCode(49).setNationalNumber(1234L);
     assertEquals("00 49 1234",
                  phoneUtil.formatOutOfCountryCallingNumber(deNumber, "GB"));
     // Note this number is correctly formatted without national prefix. Most of the numbers that
     assertEquals("1234",
                  phoneUtil.formatOutOfCountryCallingNumber(deNumber, "DE"));
 
-    PhoneNumber itNumber =
-        PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(236618300L)
-            .setItalianLeadingZero(true).build();
+    PhoneNumber itNumber = new PhoneNumber();
+    itNumber.setCountryCode(39).setNationalNumber(236618300L).setItalianLeadingZero(true);
     assertEquals("011 39 02 3661 8300",
                  phoneUtil.formatOutOfCountryCallingNumber(itNumber, "US"));
     assertEquals("02 3661 8300",
     assertEquals("+39 02 3661 8300",
                  phoneUtil.formatOutOfCountryCallingNumber(itNumber, "SG"));
 
-    PhoneNumber sgNumber =
-        PhoneNumber.newBuilder().setCountryCode(65).setNationalNumber(94777892L).build();
+    PhoneNumber sgNumber = new PhoneNumber();
+    sgNumber.setCountryCode(65).setNationalNumber(94777892L);
     assertEquals("9477 7892",
                  phoneUtil.formatOutOfCountryCallingNumber(sgNumber, "SG"));
 
-    PhoneNumber arNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(91187654321L).build();
+    PhoneNumber arNumber = new PhoneNumber();
+    arNumber.setCountryCode(54).setNationalNumber(91187654321L);
     assertEquals("011 54 9 11 8765 4321",
-                 phoneUtil.formatOutOfCountryCallingNumber(arNumber1, "US"));
+                 phoneUtil.formatOutOfCountryCallingNumber(arNumber, "US"));
 
-    PhoneNumber arNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(91187654321L)
-            .setExtension("1234").build();
+    arNumber.setExtension("1234");
     assertEquals("011 54 9 11 8765 4321 ext. 1234",
-                 phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "US"));
+                 phoneUtil.formatOutOfCountryCallingNumber(arNumber, "US"));
     assertEquals("0011 54 9 11 8765 4321 ext. 1234",
-                 phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "AU"));
+                 phoneUtil.formatOutOfCountryCallingNumber(arNumber, "AU"));
     assertEquals("011 15 8765-4321 ext. 1234",
-                 phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "AR"));
+                 phoneUtil.formatOutOfCountryCallingNumber(arNumber, "AR"));
     assertEquals("011 15 8765-4321 ext. 1234",
-                 phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "ar"));
+                 phoneUtil.formatOutOfCountryCallingNumber(arNumber, "ar"));
   }
 
   public void testFormatOutOfCountryWithPreferredIntlPrefix() {
-    PhoneNumber.Builder itNumber = PhoneNumber.newBuilder();
+    PhoneNumber itNumber = new PhoneNumber();
     itNumber.setCountryCode(39).setNationalNumber(236618300L).setItalianLeadingZero(true);
     // This should use 0011, since that is the preferred international prefix (both 0011 and 0012
     // are accepted as possible international prefixes in our test metadta.)
     assertEquals("0011 39 02 3661 8300",
-                 phoneUtil.formatOutOfCountryCallingNumber(itNumber.build(), "AU"));
+                 phoneUtil.formatOutOfCountryCallingNumber(itNumber, "AU"));
   }
 
   public void testFormatByPattern() {
-    PhoneNumber usNumber =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6502530000L).build();
+    PhoneNumber usNumber = new PhoneNumber();
+    usNumber.setCountryCode(1).setNationalNumber(6502530000L);
     NumberFormat newNumFormat1 =
         NumberFormat.newBuilder().setPattern("(\\d{3})(\\d{3})(\\d{4})")
             .setFormat("($1) $2-$3").build();
                                            PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL,
                                            newNumberFormats));
 
-    PhoneNumber itNumber =
-        PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(236618300L)
-            .setItalianLeadingZero(true).build();
+    PhoneNumber itNumber = new PhoneNumber();
+    itNumber.setCountryCode(39).setNationalNumber(236618300L).setItalianLeadingZero(true);
+
     NumberFormat newNumFormat2 =
         NumberFormat.newBuilder().setPattern("(\\d{2})(\\d{5})(\\d{3})")
             .setFormat("$1-$2 $3").build();
                                            PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL,
                                            newNumberFormats));
 
-    PhoneNumber gbNumber =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(2012345678L).build();
+   PhoneNumber gbNumber = new PhoneNumber();
+   gbNumber.setCountryCode(44).setNationalNumber(2012345678L);
 
     NumberFormat newNumFormat3 =
         NumberFormat.newBuilder().setNationalPrefixFormattingRule("$NP$FG")
   }
 
   public void testFormatE164Number() {
-    PhoneNumber.Builder usNumber = PhoneNumber.newBuilder();
+    PhoneNumber usNumber = new PhoneNumber();
     usNumber.setCountryCode(1).setNationalNumber(6502530000L);
-    assertEquals("+16502530000", phoneUtil.format(usNumber.build(),
+    assertEquals("+16502530000", phoneUtil.format(usNumber,
                                                   PhoneNumberUtil.PhoneNumberFormat.E164));
-    PhoneNumber.Builder deNumber = PhoneNumber.newBuilder();
+    PhoneNumber deNumber = new PhoneNumber();
     deNumber.setCountryCode(49).setNationalNumber(301234L);
-    assertEquals("+49301234", phoneUtil.format(deNumber.build(),
+    assertEquals("+49301234", phoneUtil.format(deNumber,
                                                PhoneNumberUtil.PhoneNumberFormat.E164));
   }
 
   public void testFormatNumberWithExtension() {
-    PhoneNumber.Builder nzNumber = PhoneNumber.newBuilder();
+    PhoneNumber nzNumber = new PhoneNumber();
     nzNumber.setCountryCode(64).setNationalNumber(33316005L).setExtension("1234");
     // Uses default extension prefix:
     assertEquals("03-331 6005 ext. 1234",
-                 phoneUtil.format(nzNumber.build(),
+                 phoneUtil.format(nzNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
     // Extension prefix overridden in the territory information for the US:
-    PhoneNumber.Builder usNumber = PhoneNumber.newBuilder();
+    PhoneNumber usNumber = new PhoneNumber();
     usNumber.setCountryCode(1).setNationalNumber(6502530000L).setExtension("4567");
     assertEquals("650 253 0000 extn. 4567",
-                 phoneUtil.format(usNumber.build(),
+                 phoneUtil.format(usNumber,
                                   PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
   }
 
   }
 
   public void testIsPremiumRate() {
-    PhoneNumber premiumRateNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(9004433030L).build();
+    PhoneNumber premiumRateNumber = new PhoneNumber();
+
+    premiumRateNumber.setCountryCode(1).setNationalNumber(9004433030L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.PREMIUM_RATE,
-                 phoneUtil.getNumberType(premiumRateNumber1));
+                 phoneUtil.getNumberType(premiumRateNumber));
 
-    PhoneNumber premiumRateNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(892123L).build();
+    premiumRateNumber.clear();
+    premiumRateNumber.setCountryCode(39).setNationalNumber(892123L);
         assertEquals(PhoneNumberUtil.PhoneNumberType.PREMIUM_RATE,
-                 phoneUtil.getNumberType(premiumRateNumber2));
+                 phoneUtil.getNumberType(premiumRateNumber));
 
-    PhoneNumber premiumRateNumber3 =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(9187654321L).build();
+    premiumRateNumber.clear();
+    premiumRateNumber.setCountryCode(44).setNationalNumber(9187654321L);
         assertEquals(PhoneNumberUtil.PhoneNumberType.PREMIUM_RATE,
-                 phoneUtil.getNumberType(premiumRateNumber3));
+                 phoneUtil.getNumberType(premiumRateNumber));
 
-    PhoneNumber premiumRateNumber4 =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(9001654321L).build();
+    premiumRateNumber.clear();
+    premiumRateNumber.setCountryCode(49).setNationalNumber(9001654321L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.PREMIUM_RATE,
-                 phoneUtil.getNumberType(premiumRateNumber4));
+                 phoneUtil.getNumberType(premiumRateNumber));
 
-    PhoneNumber premiumRateNumber5 =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(90091234567L).build();
+    premiumRateNumber.clear();
+    premiumRateNumber.setCountryCode(49).setNationalNumber(90091234567L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.PREMIUM_RATE,
-                 phoneUtil.getNumberType(premiumRateNumber5));
+                 phoneUtil.getNumberType(premiumRateNumber));
   }
 
   public void testIsTollFree() {
-    PhoneNumber tollFreeNumber1
-        = PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(8881234567L).build();
+    PhoneNumber tollFreeNumber = new PhoneNumber();
+
+    tollFreeNumber.setCountryCode(1).setNationalNumber(8881234567L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.TOLL_FREE,
-                 phoneUtil.getNumberType(tollFreeNumber1));
+                 phoneUtil.getNumberType(tollFreeNumber));
 
-    PhoneNumber tollFreeNumber2
-        = PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(803123L).build();
+    tollFreeNumber.clear();
+    tollFreeNumber.setCountryCode(39).setNationalNumber(803123L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.TOLL_FREE,
-                 phoneUtil.getNumberType(tollFreeNumber2));
+                 phoneUtil.getNumberType(tollFreeNumber));
 
-    PhoneNumber tollFreeNumber3
-        = PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(8012345678L).build();
+    tollFreeNumber.clear();
+    tollFreeNumber.setCountryCode(44).setNationalNumber(8012345678L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.TOLL_FREE,
-                 phoneUtil.getNumberType(tollFreeNumber3));
+                 phoneUtil.getNumberType(tollFreeNumber));
 
-    PhoneNumber tollFreeNumber4
-        = PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(8001234567L).build();
+    tollFreeNumber.clear();
+    tollFreeNumber.setCountryCode(49).setNationalNumber(8001234567L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.TOLL_FREE,
-                 phoneUtil.getNumberType(tollFreeNumber4));
+                 phoneUtil.getNumberType(tollFreeNumber));
   }
 
   public void testIsMobile() {
-    PhoneNumber mobileNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2423570000L).build();
+    PhoneNumber mobileNumber = new PhoneNumber();
+
+    // A Bahama mobile number
+    mobileNumber.setCountryCode(1).setNationalNumber(2423570000L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.MOBILE,
-                 phoneUtil.getNumberType(mobileNumber1));
+                 phoneUtil.getNumberType(mobileNumber));
 
-    PhoneNumber mobileNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(312345678L).build();
+    mobileNumber.clear();
+    mobileNumber.setCountryCode(39).setNationalNumber(312345678L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.MOBILE,
-                 phoneUtil.getNumberType(mobileNumber2));
+                 phoneUtil.getNumberType(mobileNumber));
 
-    PhoneNumber mobileNumber3 =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(7912345678L).build();
+    mobileNumber.clear();
+    mobileNumber.setCountryCode(44).setNationalNumber(7912345678L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.MOBILE,
-                 phoneUtil.getNumberType(mobileNumber3));
+                 phoneUtil.getNumberType(mobileNumber));
 
-    PhoneNumber mobileNumber4 =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(15123456789L).build();
+    mobileNumber.clear();
+    mobileNumber.setCountryCode(49).setNationalNumber(15123456789L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.MOBILE,
-                 phoneUtil.getNumberType(mobileNumber4));
+                 phoneUtil.getNumberType(mobileNumber));
 
-    PhoneNumber mobileNumber5 =
-        PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(91187654321L).build();
+    mobileNumber.clear();
+    mobileNumber.setCountryCode(54).setNationalNumber(91187654321L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.MOBILE,
-                 phoneUtil.getNumberType(mobileNumber5));
+                 phoneUtil.getNumberType(mobileNumber));
   }
 
   public void testIsFixedLine() {
+    PhoneNumber fixedLineNumber = new PhoneNumber();
+
     // A Bahama fixed-line number
-    PhoneNumber fixedLineNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2423651234L).build();
+    fixedLineNumber.setCountryCode(1).setNationalNumber(2423651234L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.FIXED_LINE,
-                 phoneUtil.getNumberType(fixedLineNumber1));
+                 phoneUtil.getNumberType(fixedLineNumber));
 
     // An Italian fixed-line number
-    PhoneNumber fixedLineNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(236618300L)
-            .setItalianLeadingZero(true).build();
+    fixedLineNumber.clear();
+    fixedLineNumber.setCountryCode(39).setNationalNumber(236618300L).setItalianLeadingZero(true);
     assertEquals(PhoneNumberUtil.PhoneNumberType.FIXED_LINE,
-                 phoneUtil.getNumberType(fixedLineNumber2));
+                 phoneUtil.getNumberType(fixedLineNumber));
 
-    PhoneNumber fixedLineNumber3 =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(2012345678L).build();
+    fixedLineNumber.clear();
+    fixedLineNumber.setCountryCode(44).setNationalNumber(2012345678L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.FIXED_LINE,
-                 phoneUtil.getNumberType(fixedLineNumber3));
+                 phoneUtil.getNumberType(fixedLineNumber));
 
-    PhoneNumber fixedLineNumber4 =
-        PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(301234L).build();
+    fixedLineNumber.clear();
+    fixedLineNumber.setCountryCode(49).setNationalNumber(301234L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.FIXED_LINE,
-                 phoneUtil.getNumberType(fixedLineNumber4));
+                 phoneUtil.getNumberType(fixedLineNumber));
   }
 
   public void testIsFixedLineAndMobile() {
-    PhoneNumber fixedLineAndMobileNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6502531111L).build();
+    PhoneNumber fixedLineAndMobileNumber = new PhoneNumber();
+    fixedLineAndMobileNumber.setCountryCode(1).setNationalNumber(6502531111L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.FIXED_LINE_OR_MOBILE,
-                 phoneUtil.getNumberType(fixedLineAndMobileNumber1));
+                 phoneUtil.getNumberType(fixedLineAndMobileNumber));
 
-    PhoneNumber fixedLineAndMobileNumber2 =
-        PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(1987654321L).build();
+    fixedLineAndMobileNumber.clear();
+    fixedLineAndMobileNumber.setCountryCode(54).setNationalNumber(1987654321L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.FIXED_LINE_OR_MOBILE,
-                 phoneUtil.getNumberType(fixedLineAndMobileNumber2));
+                 phoneUtil.getNumberType(fixedLineAndMobileNumber));
   }
 
   public void testIsSharedCost() {
-    PhoneNumber.Builder gbNumber = PhoneNumber.newBuilder();
+    PhoneNumber gbNumber = new PhoneNumber();
     gbNumber.setCountryCode(44).setNationalNumber(8431231234L);
-    assertEquals(PhoneNumberUtil.PhoneNumberType.SHARED_COST,
-        phoneUtil.getNumberType(gbNumber.build()));
+    assertEquals(PhoneNumberUtil.PhoneNumberType.SHARED_COST, phoneUtil.getNumberType(gbNumber));
   }
 
   public void testIsVoip() {
-    PhoneNumber.Builder gbNumber = PhoneNumber.newBuilder();
+    PhoneNumber gbNumber = new PhoneNumber();
     gbNumber.setCountryCode(44).setNationalNumber(5631231234L);
-    assertEquals(PhoneNumberUtil.PhoneNumberType.VOIP, phoneUtil.getNumberType(gbNumber.build()));
+    assertEquals(PhoneNumberUtil.PhoneNumberType.VOIP, phoneUtil.getNumberType(gbNumber));
   }
 
   public void testIsPersonalNumber() {
-    PhoneNumber.Builder gbNumber = PhoneNumber.newBuilder();
+    PhoneNumber gbNumber = new PhoneNumber();
     gbNumber.setCountryCode(44).setNationalNumber(7031231234L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.PERSONAL_NUMBER,
-                 phoneUtil.getNumberType(gbNumber.build()));
+                 phoneUtil.getNumberType(gbNumber));
   }
 
   public void testIsUnknown() {
-    PhoneNumber.Builder unknownNumber = PhoneNumber.newBuilder();
+    PhoneNumber unknownNumber = new PhoneNumber();
     unknownNumber.setCountryCode(1).setNationalNumber(65025311111L);
     assertEquals(PhoneNumberUtil.PhoneNumberType.UNKNOWN,
-                 phoneUtil.getNumberType(unknownNumber.build()));
+                 phoneUtil.getNumberType(unknownNumber));
   }
 
   public void testIsValidNumber() {
-    PhoneNumber.Builder usNumber = PhoneNumber.newBuilder();
+    PhoneNumber usNumber = new PhoneNumber();
     usNumber.setCountryCode(1).setNationalNumber(6502530000L);
-    assertTrue(phoneUtil.isValidNumber(usNumber.build()));
+    assertTrue(phoneUtil.isValidNumber(usNumber));
 
-    PhoneNumber.Builder itNumber = PhoneNumber.newBuilder();
+    PhoneNumber itNumber = new PhoneNumber();
     itNumber.setCountryCode(39).setNationalNumber(236618300L).setItalianLeadingZero(true);
-    assertTrue(phoneUtil.isValidNumber(itNumber.build()));
+    assertTrue(phoneUtil.isValidNumber(itNumber));
 
-    PhoneNumber.Builder gbNumber = PhoneNumber.newBuilder();
+    PhoneNumber gbNumber = new PhoneNumber();
     gbNumber.setCountryCode(44).setNationalNumber(7912345678L);
-    assertTrue(phoneUtil.isValidNumber(gbNumber.build()));
+    assertTrue(phoneUtil.isValidNumber(gbNumber));
 
-    PhoneNumber.Builder nzNumber = PhoneNumber.newBuilder();
+    PhoneNumber nzNumber = new PhoneNumber();
     nzNumber.setCountryCode(64).setNationalNumber(21387835L);
-    assertTrue(phoneUtil.isValidNumber(nzNumber.build()));
+    assertTrue(phoneUtil.isValidNumber(nzNumber));
   }
 
+
   public void testIsValidForRegion() {
     // This number is valid for the Bahamas, but is not a valid US number.
-    PhoneNumber bsNumber1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2423232345L).build();
-    assertTrue(phoneUtil.isValidNumber(bsNumber1));
-    assertTrue(phoneUtil.isValidNumberForRegion(bsNumber1, "BS"));
-    assertTrue(phoneUtil.isValidNumberForRegion(bsNumber1, "bs"));
-    assertFalse(phoneUtil.isValidNumberForRegion(bsNumber1, "US"));
-    PhoneNumber bsNumber2 =
-        PhoneNumber.newBuilder(bsNumber1).setNationalNumber(2421232345L).build();
+    PhoneNumber bsNumber = new PhoneNumber();
+    bsNumber.setCountryCode(1).setNationalNumber(2423232345L);
+    assertTrue(phoneUtil.isValidNumber(bsNumber));
+    assertTrue(phoneUtil.isValidNumberForRegion(bsNumber, "BS"));
+    assertTrue(phoneUtil.isValidNumberForRegion(bsNumber, "bs"));
+    assertFalse(phoneUtil.isValidNumberForRegion(bsNumber, "US"));
+    bsNumber.setNationalNumber(2421232345L);
     // This number is no longer valid.
-    assertFalse(phoneUtil.isValidNumber(bsNumber2));
+    assertFalse(phoneUtil.isValidNumber(bsNumber));
   }
 
   public void testIsNotValidNumber() {
-    PhoneNumber.Builder usNumber = PhoneNumber.newBuilder();
+    PhoneNumber usNumber = new PhoneNumber();
     usNumber.setCountryCode(1).setNationalNumber(2530000L);
-    assertFalse(phoneUtil.isValidNumber(usNumber.build()));
+    assertFalse(phoneUtil.isValidNumber(usNumber));
 
-    PhoneNumber.Builder itNumber = PhoneNumber.newBuilder();
+    PhoneNumber itNumber = new PhoneNumber();
     itNumber.setCountryCode(39).setNationalNumber(23661830000L).setItalianLeadingZero(true);
-    assertFalse(phoneUtil.isValidNumber(itNumber.build()));
+    assertFalse(phoneUtil.isValidNumber(itNumber));
 
-    PhoneNumber.Builder gbNumber = PhoneNumber.newBuilder();
+    PhoneNumber gbNumber = new PhoneNumber();
     gbNumber.setCountryCode(44).setNationalNumber(791234567L);
-    assertFalse(phoneUtil.isValidNumber(gbNumber.build()));
+    assertFalse(phoneUtil.isValidNumber(gbNumber));
 
-    PhoneNumber.Builder deNumber = PhoneNumber.newBuilder();
+    PhoneNumber deNumber = new PhoneNumber();
     deNumber.setCountryCode(49).setNationalNumber(1234L);
-    assertFalse(phoneUtil.isValidNumber(deNumber.build()));
+    assertFalse(phoneUtil.isValidNumber(deNumber));
 
-    PhoneNumber.Builder nzNumber = PhoneNumber.newBuilder();
+    PhoneNumber nzNumber = new PhoneNumber();
     nzNumber.setCountryCode(64).setNationalNumber(3316005L);
-    assertFalse(phoneUtil.isValidNumber(nzNumber.build()));
+    assertFalse(phoneUtil.isValidNumber(nzNumber));
   }
 
   public void testGetRegionCodeForCountryCode() {
   }
 
   public void testGetRegionCodeForNumber() {
-    PhoneNumber.Builder bsNumber = PhoneNumber.newBuilder();
+    PhoneNumber bsNumber = new PhoneNumber();
     bsNumber.setCountryCode(1).setNationalNumber(2423027000L);
-    assertEquals("BS", phoneUtil.getRegionCodeForNumber(bsNumber.build()));
+    assertEquals("BS", phoneUtil.getRegionCodeForNumber(bsNumber));
 
-    PhoneNumber.Builder usNumber = PhoneNumber.newBuilder();
+    PhoneNumber usNumber = new PhoneNumber();
     usNumber.setCountryCode(1).setNationalNumber(6502530000L);
-    assertEquals("US", phoneUtil.getRegionCodeForNumber(usNumber.build()));
+    assertEquals("US", phoneUtil.getRegionCodeForNumber(usNumber));
 
-    PhoneNumber.Builder gbNumber = PhoneNumber.newBuilder();
+    PhoneNumber gbNumber = new PhoneNumber();
     gbNumber.setCountryCode(44).setNationalNumber(7912345678L);
-    assertEquals("GB", phoneUtil.getRegionCodeForNumber(gbNumber.build()));
+    assertEquals("GB", phoneUtil.getRegionCodeForNumber(gbNumber));
   }
 
   public void testGetCountryCodeForRegion() {
   }
 
   public void testIsPossibleNumber() {
-    PhoneNumber number1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6502530000L).build();
-    assertTrue(phoneUtil.isPossibleNumber(number1));
+    PhoneNumber number = new PhoneNumber();
+    number.setCountryCode(1).setNationalNumber(6502530000L);
+    assertTrue(phoneUtil.isPossibleNumber(number));
 
-    PhoneNumber number2 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2530000L).build();
-    assertTrue(phoneUtil.isPossibleNumber(number2));
+    number.clear();
+    number.setCountryCode(1).setNationalNumber(2530000L);
+    assertTrue(phoneUtil.isPossibleNumber(number));
 
-    PhoneNumber number3 =
-        PhoneNumber.newBuilder().setCountryCode(44).setNationalNumber(2070313000L).build();
-    assertTrue(phoneUtil.isPossibleNumber(number3));
+    number.clear();
+    number.setCountryCode(44).setNationalNumber(2070313000L);
+    assertTrue(phoneUtil.isPossibleNumber(number));
+
     assertTrue(phoneUtil.isPossibleNumber("+1 650 253 0000", "US"));
     assertTrue(phoneUtil.isPossibleNumber("+1 650 GOO OGLE", "US"));
     assertTrue(phoneUtil.isPossibleNumber("(650) 253-0000", "US"));
 
   public void testIsPossibleNumberWithReason() {
     // FYI, national numbers for country code +1 that are within 7 to 10 digits are possible.
-    PhoneNumber number1 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6502530000L).build();
+    PhoneNumber number = new PhoneNumber();
+    number.setCountryCode(1).setNationalNumber(6502530000L);
     assertEquals(PhoneNumberUtil.ValidationResult.IS_POSSIBLE,
-                 phoneUtil.isPossibleNumberWithReason(number1));
+                 phoneUtil.isPossibleNumberWithReason(number));
 
-    PhoneNumber number2 =
-        PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2530000L).build();
+    number.clear();
+    number.setCountryCode(1).setNationalNumber(2530000L);
     assertEquals(PhoneNumberUtil.ValidationResult.IS_POSSIBLE,
-                 phoneUtil.isPossibleNumberWithReason(number2));
+