#1607 - Polishing.

This commit is contained in:
Oliver Drotbohm
2021-09-14 11:43:31 +02:00
parent 7d763043d2
commit 2751b11acf
9 changed files with 50 additions and 20 deletions

View File

@@ -65,12 +65,14 @@ public final class Affordance implements Iterable<AffordanceModel> {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Affordance that = (Affordance) o;
return Objects.equals(this.models, that.models);
}
@@ -80,6 +82,7 @@ public final class Affordance implements Iterable<AffordanceModel> {
return Objects.hash(this.models);
}
@Override
public String toString() {
return "Affordance(models=" + this.models + ")";
}

View File

@@ -699,6 +699,9 @@ public class Link implements Serializable {
@JsonProperty
public UriTemplate getTemplate() {
UriTemplate template = this.template;
return template == null ? UriTemplate.of(href) : template;
}

View File

@@ -38,7 +38,7 @@ public final class QueryParameter {
private final @Nullable String value;
private final boolean required;
private QueryParameter(String name, String value, boolean required) {
private QueryParameter(String name, @Nullable String value, boolean required) {
this.name = name;
this.value = value;
@@ -97,7 +97,7 @@ public final class QueryParameter {
/**
* Create a new {@link QueryParameter} by copying all attributes and applying the new {@literal value}.
*
*
* @param value
* @return
*/
@@ -119,12 +119,14 @@ public final class QueryParameter {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
QueryParameter that = (QueryParameter) o;
return this.required == that.required && Objects.equals(this.name, that.name)
&& Objects.equals(this.value, that.value);
@@ -135,6 +137,7 @@ public final class QueryParameter {
return Objects.hash(this.name, this.value, this.required);
}
@Override
public String toString() {
return "QueryParameter(name=" + this.name + ", value=" + this.value + ", required=" + this.required + ")";
}

View File

@@ -29,6 +29,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.hateoas.TemplateVariable.VariableType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -191,7 +192,7 @@ public final class TemplateVariables implements Iterable<TemplateVariable>, Seri
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;

View File

@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Objects;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -57,7 +58,7 @@ public final class Hop {
/**
* Creates a new {@link Hop} for the given relation name.
*
*
* @param rel must not be {@literal null} or empty.
* @return
*/
@@ -130,7 +131,7 @@ public final class Hop {
/**
* Returns whether the {@link Hop} has parameters declared.
*
*
* @return
*/
boolean hasParameters() {
@@ -169,12 +170,14 @@ public final class Hop {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Hop hop = (Hop) o;
return Objects.equals(this.rel, hop.rel) && Objects.equals(this.parameters, hop.parameters)
&& Objects.equals(this.headers, hop.headers);
@@ -185,6 +188,7 @@ public final class Hop {
return Objects.hash(this.rel, this.parameters, this.headers);
}
@Override
public String toString() {
return "Hop(rel=" + this.rel + ", parameters=" + this.parameters + ", headers=" + this.headers + ")";
}

View File

@@ -466,12 +466,14 @@ public class Traverson {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
UriStringAndHeaders that = (UriStringAndHeaders) o;
return Objects.equals(this.uri, that.uri) && Objects.equals(this.httpHeaders, that.httpHeaders);
}
@@ -481,6 +483,7 @@ public class Traverson {
return Objects.hash(this.uri, this.httpHeaders);
}
@Override
public String toString() {
return "Traverson.UriStringAndHeaders(uri=" + this.uri + ", httpHeaders=" + this.httpHeaders + ")";
}
@@ -509,12 +512,14 @@ public class Traverson {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
URIAndHeaders that = (URIAndHeaders) o;
return Objects.equals(this.uri, that.uri) && Objects.equals(this.httpHeaders, that.httpHeaders);
}
@@ -524,6 +529,7 @@ public class Traverson {
return Objects.hash(this.uri, this.httpHeaders);
}
@Override
public String toString() {
return "Traverson.URIAndHeaders(uri=" + this.uri + ", httpHeaders=" + this.httpHeaders + ")";
}

View File

@@ -28,6 +28,7 @@ import org.springframework.hateoas.AffordanceModel.InputPayloadMetadata;
import org.springframework.hateoas.AffordanceModel.Named;
import org.springframework.hateoas.AffordanceModel.PropertyMetadata;
import org.springframework.http.MediaType;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
/**
@@ -88,6 +89,11 @@ class TypeBasedPayloadMetadata implements InputPayloadMetadata {
return Arrays.asList(type.getName(), type.getSimpleName());
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.AffordanceModel.PayloadMetadata#getType()
*/
@NonNull
public Class<?> getType() {
return this.type;
}

View File

@@ -24,6 +24,7 @@ import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.Links;
import org.springframework.hateoas.UriTemplate;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -160,6 +161,8 @@ public class DefaultCurieProvider implements CurieProvider {
this.name = name;
}
@Override
@NonNull
public String getName() {
return this.name;
}

View File

@@ -307,6 +307,7 @@ class LinkUnitTest {
* @see #671
*/
@Test
@SuppressWarnings("null")
void rejectsInvalidRelationsOnHasRel() {
Link link = Link.of("/");