Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Address to Kotlin #4787

Merged
merged 6 commits into from
Mar 26, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More idiomatic Kotlin
  • Loading branch information
ShaishavGandhi committed Mar 26, 2019
commit 2782a623aee4b2f24c83287070f45146adf0c4b5
32 changes: 14 additions & 18 deletions okhttp/src/main/java/okhttp3/Address.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import okhttp3.internal.Util

/**
* A specification for a connection to an origin server. For simple connections, this is the
* server's hostname and port. If an explicit proxy is requested (or [no][Proxy.NO_PROXY] is explicitly requested), this also includes that proxy information. For secure
* connections the address also includes the SSL socket factory, hostname verifier, and certificate
* pinner.
* server's hostname and port. If an explicit proxy is requested (or [no proxy][Proxy.NO_PROXY] is explicitly requested),
* this also includes that proxy information. For secure connections the address also includes the SSL socket factory,
* hostname verifier, and certificate pinner.
*
* HTTP requests that share the same `Address` may also share the same [Connection].
*/
Expand Down Expand Up @@ -69,9 +69,7 @@ class Address(
fun dns() = dns

/** Returns the socket factory for new connections. */
fun socketFactory(): SocketFactory {
return socketFactory
}
fun socketFactory() = socketFactory

/** Returns the client's proxy authenticator. */
fun proxyAuthenticator() = proxyAuthenticator
Expand Down Expand Up @@ -108,7 +106,7 @@ class Address(
override fun equals(other: Any?): Boolean {
return (other is Address
&& url == other.url
&& equalsNonHost((other as Address?)!!))
&& equalsNonHost(other))
}

override fun hashCode(): Int {
Expand Down Expand Up @@ -140,17 +138,15 @@ class Address(
}

override fun toString(): String {
val result = StringBuilder()
.append("Address{")
.append(url.host()).append(":").append(url.port())

if (proxy != null) {
result.append(", proxy=").append(proxy)
} else {
result.append(", proxySelector=").append(proxySelector)
return buildString {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

append("Address{")
append(url.host()).append(":").append(url.port())
if (proxy != null) {
append(", proxy=").append(proxy)
} else {
append(", proxySelector=").append(proxySelector)
}
append("}")
}

result.append("}")
return result.toString()
}
}