Use Records instead of normal classes
JDK-16 has support for Records which are much superior heredev/jdk-16
parent
3598994fcd
commit
21fdc8d077
@ -1,47 +1,13 @@
|
||||
package me.goudham;
|
||||
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a Result from a {@link HttpRequest} with the resulting
|
||||
* {@code statusCode} and {@code body}
|
||||
*
|
||||
* @param statusCode The status code returned by the API Response
|
||||
* @param body The body returned by the the API Response
|
||||
*
|
||||
*/
|
||||
class Result {
|
||||
private final Integer statusCode;
|
||||
private final String body;
|
||||
|
||||
Result(Integer statusCode, String body) {
|
||||
this.statusCode = statusCode;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
Integer getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Result result = (Result) o;
|
||||
return Objects.equals(statusCode, result.statusCode) && Objects.equals(body, result.body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(statusCode, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Result{" +
|
||||
"statusCode=" + statusCode +
|
||||
", body='" + body + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
record Result(Integer statusCode, String body) { }
|
||||
|
Loading…
Reference in New Issue