-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the connection coordinates that were repeated over and over …
…into a class
- Loading branch information
Showing
3 changed files
with
114 additions
and
53 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/ConnectionParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.sfuhrm.radiobrowser4j; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
/** A tuple of parameters for creating API connections to the | ||
* radio browser API. | ||
* */ | ||
@Builder | ||
@Getter(AccessLevel.PACKAGE) | ||
class ConnectionParams { | ||
/** The URL of the radio browser API. | ||
* Must not be {@code null}. | ||
* */ | ||
private final String apiUrl; | ||
|
||
/** The timeout for connect and read requests in milliseconds. | ||
* Must be greater than zero. */ | ||
private final int timeout; | ||
|
||
/** The user agent to use for identifying with the API. | ||
* Must not be {@code null}. | ||
* */ | ||
private final String userAgent; | ||
|
||
/** The proxy URI to use. May be {@code null}. | ||
* */ | ||
private final String proxyUri; | ||
|
||
/** The proxy user to use. May be {@code null}. | ||
* */ | ||
private final String proxyUser; | ||
|
||
/** The proxy password to use. May be {@code null}. | ||
* */ | ||
private final String proxyPassword; | ||
|
||
/** Checks the parameters. | ||
* @throws IllegalArgumentException if the parameters are invalid. | ||
* */ | ||
void check() { | ||
if (apiUrl == null) { | ||
throw new IllegalArgumentException( | ||
"apiUrl must not be null"); | ||
} | ||
if (timeout <= 0) { | ||
throw new IllegalArgumentException( | ||
"timeout must be > 0, but is " | ||
+ getTimeout()); | ||
} | ||
if (userAgent == null) { | ||
throw new IllegalArgumentException( | ||
"userAgent must not be null"); | ||
} | ||
if (proxyUri != null) { | ||
if (proxyUser != null && proxyPassword == null) { | ||
throw new IllegalArgumentException( | ||
"proxyUser was given, but not a proxyPassword"); | ||
} | ||
if (proxyUser == null && proxyPassword != null) { | ||
throw new IllegalArgumentException( | ||
"proxyUser was not given, but a proxyPassword"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters