diff --git a/android/guava-tests/test/com/google/common/net/HostAndPortTest.java b/android/guava-tests/test/com/google/common/net/HostAndPortTest.java index e88a8134cc97..5e7eb2f73d71 100644 --- a/android/guava-tests/test/com/google/common/net/HostAndPortTest.java +++ b/android/guava-tests/test/com/google/common/net/HostAndPortTest.java @@ -193,15 +193,19 @@ public void testGetPortOrDefault() { } public void testHashCodeAndEquals() { - HostAndPort hp1 = HostAndPort.fromString("foo::123"); - HostAndPort hp2 = HostAndPort.fromString("foo::123"); - HostAndPort hp3 = HostAndPort.fromString("[foo::123]"); - HostAndPort hp4 = HostAndPort.fromParts("[foo::123]", 80); - HostAndPort hp5 = HostAndPort.fromString("[foo::123]:80"); + HostAndPort hpNoPort1 = HostAndPort.fromString("foo::123"); + HostAndPort hpNoPort2 = HostAndPort.fromString("foo::123"); + HostAndPort hpNoPort3 = HostAndPort.fromString("[foo::123]"); + HostAndPort hpNoPort4 = HostAndPort.fromHost("[foo::123]"); + HostAndPort hpNoPort5 = HostAndPort.fromHost("foo::123"); + + HostAndPort hpWithPort1 = HostAndPort.fromParts("[foo::123]", 80); + HostAndPort hpWithPort2 = HostAndPort.fromParts("foo::123", 80); + HostAndPort hpWithPort3 = HostAndPort.fromString("[foo::123]:80"); + new EqualsTester() - .addEqualityGroup(hp1, hp2) - .addEqualityGroup(hp3) - .addEqualityGroup(hp4, hp5) + .addEqualityGroup(hpNoPort1, hpNoPort2, hpNoPort3, hpNoPort4, hpNoPort5) + .addEqualityGroup(hpWithPort1, hpWithPort2, hpWithPort3) .testEquals(); } diff --git a/android/guava/src/com/google/common/net/HostAndPort.java b/android/guava/src/com/google/common/net/HostAndPort.java index 4b4babe2a0a6..df8ded405349 100644 --- a/android/guava/src/com/google/common/net/HostAndPort.java +++ b/android/guava/src/com/google/common/net/HostAndPort.java @@ -283,16 +283,14 @@ public boolean equals(@NullableDecl Object other) { } if (other instanceof HostAndPort) { HostAndPort that = (HostAndPort) other; - return Objects.equal(this.host, that.host) - && this.port == that.port - && this.hasBracketlessColons == that.hasBracketlessColons; + return Objects.equal(this.host, that.host) && this.port == that.port; } return false; } @Override public int hashCode() { - return Objects.hashCode(host, port, hasBracketlessColons); + return Objects.hashCode(host, port); } /** Rebuild the host:port string, including brackets if necessary. */ diff --git a/guava-tests/test/com/google/common/net/HostAndPortTest.java b/guava-tests/test/com/google/common/net/HostAndPortTest.java index e88a8134cc97..5e7eb2f73d71 100644 --- a/guava-tests/test/com/google/common/net/HostAndPortTest.java +++ b/guava-tests/test/com/google/common/net/HostAndPortTest.java @@ -193,15 +193,19 @@ public void testGetPortOrDefault() { } public void testHashCodeAndEquals() { - HostAndPort hp1 = HostAndPort.fromString("foo::123"); - HostAndPort hp2 = HostAndPort.fromString("foo::123"); - HostAndPort hp3 = HostAndPort.fromString("[foo::123]"); - HostAndPort hp4 = HostAndPort.fromParts("[foo::123]", 80); - HostAndPort hp5 = HostAndPort.fromString("[foo::123]:80"); + HostAndPort hpNoPort1 = HostAndPort.fromString("foo::123"); + HostAndPort hpNoPort2 = HostAndPort.fromString("foo::123"); + HostAndPort hpNoPort3 = HostAndPort.fromString("[foo::123]"); + HostAndPort hpNoPort4 = HostAndPort.fromHost("[foo::123]"); + HostAndPort hpNoPort5 = HostAndPort.fromHost("foo::123"); + + HostAndPort hpWithPort1 = HostAndPort.fromParts("[foo::123]", 80); + HostAndPort hpWithPort2 = HostAndPort.fromParts("foo::123", 80); + HostAndPort hpWithPort3 = HostAndPort.fromString("[foo::123]:80"); + new EqualsTester() - .addEqualityGroup(hp1, hp2) - .addEqualityGroup(hp3) - .addEqualityGroup(hp4, hp5) + .addEqualityGroup(hpNoPort1, hpNoPort2, hpNoPort3, hpNoPort4, hpNoPort5) + .addEqualityGroup(hpWithPort1, hpWithPort2, hpWithPort3) .testEquals(); } diff --git a/guava/src/com/google/common/net/HostAndPort.java b/guava/src/com/google/common/net/HostAndPort.java index ff9081425950..c01b87a15cd5 100644 --- a/guava/src/com/google/common/net/HostAndPort.java +++ b/guava/src/com/google/common/net/HostAndPort.java @@ -283,16 +283,14 @@ public boolean equals(@Nullable Object other) { } if (other instanceof HostAndPort) { HostAndPort that = (HostAndPort) other; - return Objects.equal(this.host, that.host) - && this.port == that.port - && this.hasBracketlessColons == that.hasBracketlessColons; + return Objects.equal(this.host, that.host) && this.port == that.port; } return false; } @Override public int hashCode() { - return Objects.hashCode(host, port, hasBracketlessColons); + return Objects.hashCode(host, port); } /** Rebuild the host:port string, including brackets if necessary. */