#340 - Polishing.
More Java 8 related cleanups (diamond operator etc.).
This commit is contained in:
@@ -19,14 +19,13 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -73,18 +72,9 @@ class HalFormsAffordanceModel implements AffordanceModel {
|
||||
*/
|
||||
public List<HalFormsProperty> getProperties() {
|
||||
|
||||
List<HalFormsProperty> halFormsProperties = new ArrayList<HalFormsProperty>();
|
||||
|
||||
for (Entry<String, Class<?>> entry : this.properties.entrySet()) {
|
||||
|
||||
HalFormsProperty property = HalFormsProperty//
|
||||
.named(entry.getKey())//
|
||||
.withRequired(required);
|
||||
|
||||
halFormsProperties.add(property);
|
||||
}
|
||||
|
||||
return halFormsProperties;
|
||||
return properties.entrySet().stream() //
|
||||
.map(entry -> entry.getKey()) //
|
||||
.map(key -> HalFormsProperty.named(key).withRequired(required)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
@@ -136,7 +126,7 @@ class HalFormsAffordanceModel implements AffordanceModel {
|
||||
|
||||
LOG.debug("Gathering details about " + method.getDeclaringClass().getCanonicalName() + "." + method.getName());
|
||||
|
||||
Map<String, Class<?>> properties = new TreeMap<String, Class<?>>();
|
||||
Map<String, Class<?>> properties = new TreeMap<>();
|
||||
MethodParameters parameters = new MethodParameters(method);
|
||||
|
||||
for (MethodParameter parameter : parameters.getParametersWith(RequestBody.class)) {
|
||||
|
||||
@@ -63,5 +63,4 @@ public class HalFormsConfiguration {
|
||||
|
||||
throw new IllegalStateException("Don't know how to translate " + this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -99,12 +99,8 @@ class HalFormsDeserializers {
|
||||
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
|
||||
throws JsonMappingException {
|
||||
|
||||
if (property != null) {
|
||||
JavaType vc = property.getType().getContentType();
|
||||
return new HalFormsResourcesDeserializer(vc);
|
||||
} else {
|
||||
return new HalFormsResourcesDeserializer(ctxt.getContextualType());
|
||||
}
|
||||
return new HalFormsResourcesDeserializer(
|
||||
property == null ? ctxt.getContextualType() : property.getType().getContentType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,7 @@ public class HalFormsDocument<T> {
|
||||
@Wither(AccessLevel.PRIVATE) //
|
||||
private T resource;
|
||||
|
||||
@JsonInclude(Include.NON_EMPTY)
|
||||
@JsonIgnore //
|
||||
@JsonInclude(Include.NON_EMPTY) @JsonIgnore //
|
||||
@Wither(AccessLevel.PRIVATE) //
|
||||
private Collection<T> resources;
|
||||
|
||||
@@ -87,8 +86,7 @@ public class HalFormsDocument<T> {
|
||||
private Map<String, HalFormsTemplate> templates;
|
||||
|
||||
private HalFormsDocument() {
|
||||
this(null, null, Collections.<String, Object> emptyMap(), null, Collections.<Link> emptyList(),
|
||||
Collections.<String, HalFormsTemplate> emptyMap());
|
||||
this(null, null, Collections.emptyMap(), null, Collections.emptyList(), Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +118,7 @@ public class HalFormsDocument<T> {
|
||||
* @return
|
||||
*/
|
||||
public static HalFormsDocument<?> empty() {
|
||||
return new HalFormsDocument<Object>();
|
||||
return new HalFormsDocument<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +155,7 @@ public class HalFormsDocument<T> {
|
||||
|
||||
Assert.notNull(link, "Link must not be null!");
|
||||
|
||||
List<Link> links = new ArrayList<Link>(this.links);
|
||||
List<Link> links = new ArrayList<>(this.links);
|
||||
links.add(link);
|
||||
|
||||
return new HalFormsDocument<T>(resource, resources, embedded, pageMetadata, links, templates);
|
||||
@@ -175,7 +173,7 @@ public class HalFormsDocument<T> {
|
||||
Assert.hasText(name, "Template name must not be null or empty!");
|
||||
Assert.notNull(template, "Template must not be null!");
|
||||
|
||||
Map<String, HalFormsTemplate> templates = new HashMap<String, HalFormsTemplate>(this.templates);
|
||||
Map<String, HalFormsTemplate> templates = new HashMap<>(this.templates);
|
||||
templates.put(name, template);
|
||||
|
||||
return new HalFormsDocument<T>(resource, resources, embedded, pageMetadata, links, templates);
|
||||
|
||||
@@ -192,7 +192,8 @@ class HalFormsSerializers {
|
||||
Map<String, HalFormsTemplate> templates = new HashMap<String, HalFormsTemplate>();
|
||||
|
||||
if (resource.hasLink(Link.REL_SELF)) {
|
||||
for (Affordance affordance : resource.getLink(Link.REL_SELF).map(Link::getAffordances).orElse(Collections.emptyList())) {
|
||||
for (Affordance affordance : resource.getLink(Link.REL_SELF).map(Link::getAffordances)
|
||||
.orElse(Collections.emptyList())) {
|
||||
|
||||
HalFormsAffordanceModel model = affordance.getAffordanceModel(MediaTypes.HAL_FORMS_JSON);
|
||||
|
||||
@@ -224,6 +225,7 @@ class HalFormsSerializers {
|
||||
private static void validate(ResourceSupport resource, Affordance affordance, HalFormsAffordanceModel model) {
|
||||
|
||||
try {
|
||||
|
||||
Optional<Link> selfLink = resource.getLink(Link.REL_SELF);
|
||||
URI selfLinkUri = new URI(selfLink.map(link -> link.expand().getHref()).orElse(""));
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import lombok.experimental.Wither;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.hateoas.hal.forms.HalFormsDeserializers.MediaTypesDeserializer;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -39,7 +38,6 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
/**
|
||||
* Value object for a HAL-FORMS template. Describes the available state transition details.
|
||||
@@ -67,7 +65,7 @@ public class HalFormsTemplate {
|
||||
private List<MediaType> contentTypes;
|
||||
|
||||
private HalFormsTemplate() {
|
||||
this(null, null, Collections.<HalFormsProperty> emptyList(), Collections.<MediaType> emptyList());
|
||||
this(null, null, Collections.emptyList(), Collections.emptyList());
|
||||
}
|
||||
|
||||
public static HalFormsTemplate forMethod(HttpMethod httpMethod) {
|
||||
@@ -84,7 +82,7 @@ public class HalFormsTemplate {
|
||||
|
||||
Assert.notNull(property, "Property must not be null!");
|
||||
|
||||
ArrayList<HalFormsProperty> properties = new ArrayList<HalFormsProperty>(this.properties);
|
||||
List<HalFormsProperty> properties = new ArrayList<>(this.properties);
|
||||
properties.add(property);
|
||||
|
||||
return new HalFormsTemplate(title, httpMethod, properties, contentTypes);
|
||||
@@ -100,7 +98,7 @@ public class HalFormsTemplate {
|
||||
|
||||
Assert.notNull(mediaType, "Media type must not be null!");
|
||||
|
||||
ArrayList<MediaType> contentTypes = new ArrayList<MediaType>(this.contentTypes);
|
||||
List<MediaType> contentTypes = new ArrayList<>(this.contentTypes);
|
||||
contentTypes.add(mediaType);
|
||||
|
||||
return new HalFormsTemplate(title, httpMethod, properties, contentTypes);
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -30,7 +30,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@Configuration
|
||||
public class HalFormsWebMvcConfigurer extends WebMvcConfigurerAdapter {
|
||||
public class HalFormsWebMvcConfigurer implements WebMvcConfigurer {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
Reference in New Issue
Block a user