#788 - Remove redundant generics.

This commit is contained in:
Greg Turnquist
2019-01-18 12:03:41 -06:00
parent 74647cb5b1
commit 0f696dd637
24 changed files with 76 additions and 125 deletions

View File

@@ -137,7 +137,7 @@ public class Link implements Serializable {
this.template = template;
this.href = template.toString();
this.rel = rel;
this.affordances = new ArrayList<Affordance>();
this.affordances = new ArrayList<>();
}
public Link(String href, String rel, List<Affordance> affordances) {
@@ -153,7 +153,7 @@ public class Link implements Serializable {
* Empty constructor required by the marshalling framework.
*/
protected Link() {
this.affordances = new ArrayList<Affordance>();
this.affordances = new ArrayList<>();
}
/**
@@ -184,7 +184,7 @@ public class Link implements Serializable {
Assert.notNull(affordance, "Affordance must not be null!");
List<Affordance> newAffordances = new ArrayList<Affordance>();
List<Affordance> newAffordances = new ArrayList<>();
newAffordances.addAll(this.affordances);
newAffordances.add(affordance);
@@ -241,7 +241,7 @@ public class Link implements Serializable {
*/
public Link andAffordances(List<Affordance> affordances) {
List<Affordance> newAffordances = new ArrayList<Affordance>();
List<Affordance> newAffordances = new ArrayList<>();
newAffordances.addAll(this.affordances);
newAffordances.addAll(affordances);
@@ -437,7 +437,7 @@ public class Link implements Serializable {
return Collections.emptyMap();
}
Map<String, String> attributes = new HashMap<String, String>();
Map<String, String> attributes = new HashMap<>();
Matcher matcher = KEY_AND_VALUE_PATTERN.matcher(source);
while (matcher.find()) {

View File

@@ -41,7 +41,7 @@ public class PagedResources<T> extends Resources<T> {
* Default constructor to allow instantiation by reflection.
*/
protected PagedResources() {
this(new ArrayList<T>(), null);
this(new ArrayList<>(), null);
}
/**
@@ -88,13 +88,13 @@ public class PagedResources<T> extends Resources<T> {
public static <T extends Resource<S>, S> PagedResources<T> wrap(Iterable<S> content, PageMetadata metadata) {
Assert.notNull(content, "Content must not be null!");
ArrayList<T> resources = new ArrayList<T>();
ArrayList<T> resources = new ArrayList<>();
for (S element : content) {
resources.add((T) new Resource<S>(element));
resources.add((T) new Resource<>(element));
}
return new PagedResources<T>(resources, metadata);
return new PagedResources<>(resources, metadata);
}
/**

View File

@@ -39,7 +39,7 @@ public class Resources<T> extends ResourceSupport implements Iterable<T> {
* Creates an empty {@link Resources} instance.
*/
protected Resources() {
this(new ArrayList<T>());
this(new ArrayList<>());
}
/**
@@ -62,7 +62,7 @@ public class Resources<T> extends ResourceSupport implements Iterable<T> {
Assert.notNull(content, "Content must not be null!");
this.content = new ArrayList<T>();
this.content = new ArrayList<>();
for (T element : content) {
this.content.add(element);
@@ -80,13 +80,13 @@ public class Resources<T> extends ResourceSupport implements Iterable<T> {
public static <T extends Resource<S>, S> Resources<T> wrap(Iterable<S> content) {
Assert.notNull(content, "Content must not be null!");
ArrayList<T> resources = new ArrayList<T>();
ArrayList<T> resources = new ArrayList<>();
for (S element : content) {
resources.add((T) new Resource<S>(element));
resources.add((T) new Resource<>(element));
}
return new Resources<T>(resources);
return new Resources<>(resources);
}
/**

View File

@@ -60,7 +60,7 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
Assert.notNull(error, "Error must not be null");
this.vndErrors = new ArrayList<VndError>(errors.length + 1);
this.vndErrors = new ArrayList<>(errors.length + 1);
this.vndErrors.add(error);
this.vndErrors.addAll(Arrays.asList(errors));
}
@@ -82,7 +82,7 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
* Protected default constructor to allow JAXB marshalling.
*/
protected VndErrors() {
this.vndErrors = new ArrayList<VndError>();
this.vndErrors = new ArrayList<>();
}
/**

View File

@@ -129,7 +129,7 @@ public class Hop {
Assert.notNull(globalParameters, "Global parameters must not be null!");
Map<String, Object> mergedParameters = new HashMap<String, Object>();
Map<String, Object> mergedParameters = new HashMap<>();
mergedParameters.putAll(globalParameters);
mergedParameters.putAll(this.parameters);

View File

@@ -40,10 +40,8 @@ import org.springframework.hateoas.support.PropertyUtils;
import org.springframework.http.HttpMethod;
import org.springframework.util.ClassUtils;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
@@ -624,7 +622,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
CollectionJsonDocument<?> document = jp.getCodec().readValue(jp, wrappedType);
List<Object> contentList = new ArrayList<Object>();
List<Object> contentList = new ArrayList<>();
if (document.getCollection().getItems() != null) {
for (CollectionJsonItem<?> item : document.getCollection().getItems()) {
@@ -738,7 +736,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
public static class CollectionJsonHandlerInstantiator extends HandlerInstantiator {
private final Map<Class<?>, Object> instanceMap = new HashMap<Class<?>, Object>();
private final Map<Class<?>, Object> instanceMap = new HashMap<>();
public CollectionJsonHandlerInstantiator(MessageSourceAccessor messageSource) {

View File

@@ -131,7 +131,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer {
RequestMethod[] requestMethods = (RequestMethod[]) value;
List<HttpMethod> requestMethodNames = new ArrayList<HttpMethod>();
List<HttpMethod> requestMethodNames = new ArrayList<>();
for (RequestMethod requestMethod : requestMethods) {
requestMethodNames.add(HttpMethod.valueOf(requestMethod.toString()));

View File

@@ -87,7 +87,7 @@ public class ControllerEntityLinksFactoryBean extends AbstractFactoryBean<Contro
@Override
protected ControllerEntityLinks createInstance() {
Collection<Class<?>> controllerTypes = new HashSet<Class<?>>();
Collection<Class<?>> controllerTypes = new HashSet<>();
for (Class<?> controllerType : getBeanTypesWithAnnotation(annotation)) {
if (AnnotationUtils.findAnnotation(controllerType, ExposesResourceFor.class) != null) {
@@ -112,7 +112,7 @@ public class ControllerEntityLinksFactoryBean extends AbstractFactoryBean<Contro
private Iterable<Class<?>> getBeanTypesWithAnnotation(Class<? extends Annotation> type) {
Set<Class<?>> annotatedTypes = new HashSet<Class<?>>();
Set<Class<?>> annotatedTypes = new HashSet<>();
for (String beanName : context.getBeanDefinitionNames()) {

View File

@@ -59,7 +59,7 @@ public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkB
Assert.notNull(builder, "UriComponentsBuilder must not be null!");
this.uriComponents = builder.build();
this.affordances = new ArrayList<Affordance>();
this.affordances = new ArrayList<>();
}
/**
@@ -71,7 +71,7 @@ public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkB
Assert.notNull(uriComponents, "UriComponents must not be null!");
this.uriComponents = uriComponents;
this.affordances = new ArrayList<Affordance>();
this.affordances = new ArrayList<>();
}
/*

View File

@@ -41,7 +41,7 @@ class HalEmbeddedBuilder {
private static final String DEFAULT_REL = "content";
private static final String INVALID_EMBEDDED_WRAPPER = "Embedded wrapper %s returned null for both the static rel and the rel target type! Make sure one of the two returns a non-null value!";
private final Map<String, Object> embeddeds = new HashMap<String, Object>();
private final Map<String, Object> embeddeds = new HashMap<>();
private final RelProvider provider;
private final CurieProvider curieProvider;
private final EmbeddedWrappers wrappers;
@@ -90,7 +90,7 @@ class HalEmbeddedBuilder {
return;
}
List<Object> list = new ArrayList<Object>();
List<Object> list = new ArrayList<>();
list.addAll(asCollection(currentValue));
list.addAll(asCollection(wrapper.getValue()));

View File

@@ -807,7 +807,7 @@ public class Jackson2HalModule extends SimpleModule {
@Override
public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
jgen.writeBoolean(value.booleanValue());
jgen.writeBoolean(value);
}
/*

View File

@@ -60,7 +60,7 @@ class HalFormsDeserializers {
@Override
public List<Object> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
List<Object> result = new ArrayList<Object>();
List<Object> result = new ArrayList<>();
JsonDeserializer<Object> deser = ctxt.findRootValueDeserializer(contentType);
Object object;

View File

@@ -158,7 +158,7 @@ public class HalFormsDocument<T> {
List<Link> links = new ArrayList<>(this.links);
links.add(link);
return new HalFormsDocument<T>(resource, resources, embedded, pageMetadata, links, templates);
return new HalFormsDocument<>(resource, resources, embedded, pageMetadata, links, templates);
}
/**
@@ -176,7 +176,7 @@ public class HalFormsDocument<T> {
Map<String, HalFormsTemplate> templates = new HashMap<>(this.templates);
templates.put(name, template);
return new HalFormsDocument<T>(resource, resources, embedded, pageMetadata, links, templates);
return new HalFormsDocument<>(resource, resources, embedded, pageMetadata, links, templates);
}
/**
@@ -191,9 +191,9 @@ public class HalFormsDocument<T> {
Assert.notNull(key, "Embedded key must not be null!");
Assert.notNull(value, "Embedded value must not be null!");
Map<String, Object> embedded = new HashMap<String, Object>(this.embedded);
Map<String, Object> embedded = new HashMap<>(this.embedded);
embedded.put(key, value);
return new HalFormsDocument<T>(resource, resources, embedded, pageMetadata, links, templates);
return new HalFormsDocument<>(resource, resources, embedded, pageMetadata, links, templates);
}
}

View File

@@ -113,7 +113,7 @@ public class Jackson2HalFormsModule extends SimpleModule {
*/
public static class HalFormsHandlerInstantiator extends HalHandlerInstantiator {
private final Map<Class<?>, Object> serializers = new HashMap<Class<?>, Object>();
private final Map<Class<?>, Object> serializers = new HashMap<>();
public HalFormsHandlerInstantiator(RelProvider resolver, CurieProvider curieProvider,
MessageSourceAccessor messageSource, boolean enforceEmbeddedCollections,

View File

@@ -74,7 +74,7 @@ public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<Co
new AnnotationAttribute(PathVariable.class));
private static final AnnotatedParametersParameterAccessor REQUEST_PARAM_ACCESSOR = new RequestParamParameterAccessor();
private List<UriComponentsContributor> uriComponentsContributors = new ArrayList<UriComponentsContributor>();
private List<UriComponentsContributor> uriComponentsContributors = new ArrayList<>();
/**
* Configures the {@link UriComponentsContributor} to be used when building {@link Link} instances from method
@@ -142,7 +142,7 @@ public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<Co
UriComponentsBuilder builder = ControllerLinkBuilder.getBuilder().path(mapping);
UriTemplate template = new UriTemplate(mapping);
Map<String, Object> values = new HashMap<String, Object>();
Map<String, Object> values = new HashMap<>();
Iterator<String> names = template.getVariableNames().iterator();
while (classMappingParameters.hasNext()) {
@@ -153,7 +153,7 @@ public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<Co
values.put(parameter.getVariableName(), encodePath(parameter.asString()));
}
List<String> optionalEmptyParameters = new ArrayList<String>();
List<String> optionalEmptyParameters = new ArrayList<>();
for (BoundMethodParameter parameter : REQUEST_PARAM_ACCESSOR.getBoundParameters(invocation)) {

View File

@@ -71,9 +71,9 @@ public class HeaderLinksResponseEntity<T extends ResourceSupport> extends Respon
Assert.notNull(entity, "Given HttpEntity must not be null!");
if (entity instanceof ResponseEntity) {
return new HeaderLinksResponseEntity<S>((ResponseEntity<S>) entity);
return new HeaderLinksResponseEntity<>((ResponseEntity<S>) entity);
} else {
return new HeaderLinksResponseEntity<S>(entity);
return new HeaderLinksResponseEntity<>(entity);
}
}

View File

@@ -133,10 +133,10 @@ public class ResourceProcessorHandlerMethodReturnValueHandler implements Handler
if (originalValue instanceof ResponseEntity) {
ResponseEntity<?> source = (ResponseEntity<?>) originalValue;
entity = new ResponseEntity<ResourceSupport>(newBody, source.getHeaders(), source.getStatusCode());
entity = new ResponseEntity<>(newBody, source.getHeaders(), source.getStatusCode());
} else {
HttpEntity<?> source = (HttpEntity<?>) originalValue;
entity = new HttpEntity<ResourceSupport>(newBody, source.getHeaders());
entity = new HttpEntity<>(newBody, source.getHeaders());
}
return rootLinksAsHeaders ? HeaderLinksResponseEntity.wrap(entity) : entity;

View File

@@ -18,7 +18,6 @@ package org.springframework.hateoas.mvc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.springframework.core.Ordered;
@@ -54,7 +53,7 @@ public class ResourceProcessorInvoker {
Assert.notNull(processors, "ResourceProcessors must not be null!");
this.processors = new ArrayList<ProcessorWrapper>();
this.processors = new ArrayList<>();
for (ResourceProcessor<?> processor : processors) {
@@ -70,7 +69,7 @@ public class ResourceProcessorInvoker {
}
}
Collections.sort(this.processors, AnnotationAwareOrderComparator.INSTANCE);
this.processors.sort(AnnotationAwareOrderComparator.INSTANCE);
}
/**
@@ -105,7 +104,7 @@ public class ResourceProcessorInvoker {
Resources<?> resources = (Resources<?>) value;
ResolvableType elementTargetType = ResolvableType.forClass(Resources.class, referenceType.getRawClass())
.getGeneric(0);
List<Object> result = new ArrayList<Object>(resources.getContent().size());
List<Object> result = new ArrayList<>(resources.getContent().size());
for (Object element : resources) {

View File

@@ -63,7 +63,7 @@ public class ResourceProcessorInvokingHandlerAdapter extends RequestMappingHandl
HandlerMethodReturnValueHandlerComposite oldHandlers = getReturnValueHandlersComposite();
// Set up ResourceProcessingHandlerMethodResolver to delegate to originally configured ones
List<HandlerMethodReturnValueHandler> newHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
List<HandlerMethodReturnValueHandler> newHandlers = new ArrayList<>();
newHandlers.add(new ResourceProcessorHandlerMethodReturnValueHandler(oldHandlers, invoker));
// Configure the new handler to be used

View File

@@ -87,7 +87,7 @@ public class TypeReferences {
Assert.isTrue(parameterizedType.getActualTypeArguments().length == 1, String.format("Type must have exactly one generic type argument but has %s.", parameterizedType.getActualTypeArguments().length));
Class<?> resourceType = GenericTypeResolver.resolveType(parameterizedType.getActualTypeArguments()[0],
new HashMap<TypeVariable, Type>());
new HashMap<>());
this.type = new SyntheticParameterizedType(resourceType, domainType);
}