Skip to content

Commit 32ff7cc

Browse files
committed
#340 - Polishing.
More Java 8 related cleanups (diamond operator etc.).
1 parent fed5f6c commit 32ff7cc

File tree

7 files changed

+20
-37
lines changed

7 files changed

+20
-37
lines changed

src/main/java/org/springframework/hateoas/hal/forms/HalFormsAffordanceModel.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919

2020
import java.beans.PropertyDescriptor;
2121
import java.lang.reflect.Method;
22-
import java.util.ArrayList;
2322
import java.util.Arrays;
2423
import java.util.Collection;
2524
import java.util.Collections;
2625
import java.util.List;
2726
import java.util.Map;
28-
import java.util.Map.Entry;
2927
import java.util.TreeMap;
28+
import java.util.stream.Collectors;
3029

3130
import org.springframework.beans.BeanUtils;
3231
import org.springframework.core.MethodParameter;
@@ -73,18 +72,9 @@ public HalFormsAffordanceModel(Affordance affordance, MethodInvocation invocatio
7372
*/
7473
public List<HalFormsProperty> getProperties() {
7574

76-
List<HalFormsProperty> halFormsProperties = new ArrayList<HalFormsProperty>();
77-
78-
for (Entry<String, Class<?>> entry : this.properties.entrySet()) {
79-
80-
HalFormsProperty property = HalFormsProperty//
81-
.named(entry.getKey())//
82-
.withRequired(required);
83-
84-
halFormsProperties.add(property);
85-
}
86-
87-
return halFormsProperties;
75+
return properties.entrySet().stream() //
76+
.map(entry -> entry.getKey()) //
77+
.map(key -> HalFormsProperty.named(key).withRequired(required)).collect(Collectors.toList());
8878
}
8979

9080
public String getPath() {
@@ -136,7 +126,7 @@ private Map<String, Class<?>> determineAffordanceInputs(Method method) {
136126

137127
LOG.debug("Gathering details about " + method.getDeclaringClass().getCanonicalName() + "." + method.getName());
138128

139-
Map<String, Class<?>> properties = new TreeMap<String, Class<?>>();
129+
Map<String, Class<?>> properties = new TreeMap<>();
140130
MethodParameters parameters = new MethodParameters(method);
141131

142132
for (MethodParameter parameter : parameters.getParametersWith(RequestBody.class)) {

src/main/java/org/springframework/hateoas/hal/forms/HalFormsConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@ public HalConfiguration toHalConfiguration() {
6363

6464
throw new IllegalStateException("Don't know how to translate " + this);
6565
}
66-
6766
}

src/main/java/org/springframework/hateoas/hal/forms/HalFormsDeserializers.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,8 @@ public JsonDeserializer<Object> getContentDeserializer() {
9999
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
100100
throws JsonMappingException {
101101

102-
if (property != null) {
103-
JavaType vc = property.getType().getContentType();
104-
return new HalFormsResourcesDeserializer(vc);
105-
} else {
106-
return new HalFormsResourcesDeserializer(ctxt.getContextualType());
107-
}
102+
return new HalFormsResourcesDeserializer(
103+
property == null ? ctxt.getContextualType() : property.getType().getContentType());
108104
}
109105
}
110106

src/main/java/org/springframework/hateoas/hal/forms/HalFormsDocument.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public class HalFormsDocument<T> {
6161
@Wither(AccessLevel.PRIVATE) //
6262
private T resource;
6363

64-
@JsonInclude(Include.NON_EMPTY)
65-
@JsonIgnore //
64+
@JsonInclude(Include.NON_EMPTY) @JsonIgnore //
6665
@Wither(AccessLevel.PRIVATE) //
6766
private Collection<T> resources;
6867

@@ -87,8 +86,7 @@ public class HalFormsDocument<T> {
8786
private Map<String, HalFormsTemplate> templates;
8887

8988
private HalFormsDocument() {
90-
this(null, null, Collections.<String, Object> emptyMap(), null, Collections.<Link> emptyList(),
91-
Collections.<String, HalFormsTemplate> emptyMap());
89+
this(null, null, Collections.emptyMap(), null, Collections.emptyList(), Collections.emptyMap());
9290
}
9391

9492
/**
@@ -120,7 +118,7 @@ public static <T> HalFormsDocument<T> forResources(Collection<T> resources) {
120118
* @return
121119
*/
122120
public static HalFormsDocument<?> empty() {
123-
return new HalFormsDocument<Object>();
121+
return new HalFormsDocument<>();
124122
}
125123

126124
/**
@@ -157,7 +155,7 @@ public HalFormsDocument<T> andLink(Link link) {
157155

158156
Assert.notNull(link, "Link must not be null!");
159157

160-
List<Link> links = new ArrayList<Link>(this.links);
158+
List<Link> links = new ArrayList<>(this.links);
161159
links.add(link);
162160

163161
return new HalFormsDocument<T>(resource, resources, embedded, pageMetadata, links, templates);
@@ -175,7 +173,7 @@ public HalFormsDocument<T> andTemplate(String name, HalFormsTemplate template) {
175173
Assert.hasText(name, "Template name must not be null or empty!");
176174
Assert.notNull(template, "Template must not be null!");
177175

178-
Map<String, HalFormsTemplate> templates = new HashMap<String, HalFormsTemplate>(this.templates);
176+
Map<String, HalFormsTemplate> templates = new HashMap<>(this.templates);
179177
templates.put(name, template);
180178

181179
return new HalFormsDocument<T>(resource, resources, embedded, pageMetadata, links, templates);

src/main/java/org/springframework/hateoas/hal/forms/HalFormsSerializers.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ private static Map<String, HalFormsTemplate> findTemplates(ResourceSupport resou
192192
Map<String, HalFormsTemplate> templates = new HashMap<String, HalFormsTemplate>();
193193

194194
if (resource.hasLink(Link.REL_SELF)) {
195-
for (Affordance affordance : resource.getLink(Link.REL_SELF).map(Link::getAffordances).orElse(Collections.emptyList())) {
195+
for (Affordance affordance : resource.getLink(Link.REL_SELF).map(Link::getAffordances)
196+
.orElse(Collections.emptyList())) {
196197

197198
HalFormsAffordanceModel model = affordance.getAffordanceModel(MediaTypes.HAL_FORMS_JSON);
198199

@@ -224,6 +225,7 @@ private static Map<String, HalFormsTemplate> findTemplates(ResourceSupport resou
224225
private static void validate(ResourceSupport resource, Affordance affordance, HalFormsAffordanceModel model) {
225226

226227
try {
228+
227229
Optional<Link> selfLink = resource.getLink(Link.REL_SELF);
228230
URI selfLinkUri = new URI(selfLink.map(link -> link.expand().getHref()).orElse(""));
229231

src/main/java/org/springframework/hateoas/hal/forms/HalFormsTemplate.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.ArrayList;
2727
import java.util.Collections;
2828
import java.util.List;
29-
import java.util.stream.Collectors;
3029

3130
import org.springframework.hateoas.hal.forms.HalFormsDeserializers.MediaTypesDeserializer;
3231
import org.springframework.http.HttpMethod;
@@ -39,7 +38,6 @@
3938
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4039
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4140
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
42-
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
4341

4442
/**
4543
* Value object for a HAL-FORMS template. Describes the available state transition details.
@@ -67,7 +65,7 @@ public class HalFormsTemplate {
6765
private List<MediaType> contentTypes;
6866

6967
private HalFormsTemplate() {
70-
this(null, null, Collections.<HalFormsProperty> emptyList(), Collections.<MediaType> emptyList());
68+
this(null, null, Collections.emptyList(), Collections.emptyList());
7169
}
7270

7371
public static HalFormsTemplate forMethod(HttpMethod httpMethod) {
@@ -84,7 +82,7 @@ public HalFormsTemplate andProperty(HalFormsProperty property) {
8482

8583
Assert.notNull(property, "Property must not be null!");
8684

87-
ArrayList<HalFormsProperty> properties = new ArrayList<HalFormsProperty>(this.properties);
85+
List<HalFormsProperty> properties = new ArrayList<>(this.properties);
8886
properties.add(property);
8987

9088
return new HalFormsTemplate(title, httpMethod, properties, contentTypes);
@@ -100,7 +98,7 @@ public HalFormsTemplate andContentType(MediaType mediaType) {
10098

10199
Assert.notNull(mediaType, "Media type must not be null!");
102100

103-
ArrayList<MediaType> contentTypes = new ArrayList<MediaType>(this.contentTypes);
101+
List<MediaType> contentTypes = new ArrayList<>(this.contentTypes);
104102
contentTypes.add(mediaType);
105103

106104
return new HalFormsTemplate(title, httpMethod, properties, contentTypes);

src/main/java/org/springframework/hateoas/hal/forms/HalFormsWebMvcConfigurer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import org.springframework.context.annotation.Configuration;
2121
import org.springframework.http.converter.HttpMessageConverter;
22-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
22+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
2323

2424
import com.fasterxml.jackson.databind.ObjectMapper;
2525

@@ -30,7 +30,7 @@
3030
* @author Greg Turnquist
3131
*/
3232
@Configuration
33-
public class HalFormsWebMvcConfigurer extends WebMvcConfigurerAdapter {
33+
public class HalFormsWebMvcConfigurer implements WebMvcConfigurer {
3434

3535
/*
3636
* (non-Javadoc)

0 commit comments

Comments
 (0)