From 02fa42445f7c8c84509bac86d3d1ebe569ca9c8f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 26 Jan 2016 11:14:29 +0000 Subject: [PATCH] Make consistent use of the diamond operator with generic types --- config/eclipse/org.eclipse.jdt.core.prefs | 2 +- .../restdocs/curl/CurlRequestSnippet.java | 6 +++--- .../headers/AbstractHeadersSnippet.java | 8 ++++---- .../restdocs/http/HttpRequestSnippet.java | 4 ++-- .../restdocs/http/HttpResponseSnippet.java | 4 ++-- .../restdocs/hypermedia/LinksSnippet.java | 6 +++--- .../payload/AbstractFieldsSnippet.java | 6 +++--- .../restdocs/payload/JsonContentHandler.java | 4 ++-- .../restdocs/payload/JsonFieldProcessor.java | 6 +++--- .../request/AbstractParametersSnippet.java | 6 +++--- .../restdocs/hypermedia/LinksSnippetTests.java | 4 ++-- .../payload/JsonFieldProcessorTests.java | 18 +++++++++--------- .../restdocs/test/OutputCapture.java | 4 ++-- .../restdocs/test/SnippetMatchers.java | 4 ++-- .../restdocs/mockmvc/IterableEnumeration.java | 4 ++-- ...ckMvcRestDocumentationIntegrationTests.java | 5 ++--- 16 files changed, 45 insertions(+), 46 deletions(-) diff --git a/config/eclipse/org.eclipse.jdt.core.prefs b/config/eclipse/org.eclipse.jdt.core.prefs index 5281c3b4..462feac8 100644 --- a/config/eclipse/org.eclipse.jdt.core.prefs +++ b/config/eclipse/org.eclipse.jdt.core.prefs @@ -71,7 +71,7 @@ org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/curl/CurlRequestSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/curl/CurlRequestSnippet.java index 56f1fd4c..3e903f37 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/curl/CurlRequestSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/curl/CurlRequestSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ public class CurlRequestSnippet extends TemplatedSnippet { private static final Set HEADER_FILTERS; static { - Set headerFilters = new HashSet(); + Set headerFilters = new HashSet<>(); headerFilters.add(new NamedHeaderFilter(HttpHeaders.HOST)); headerFilters.add(new NamedHeaderFilter(HttpHeaders.CONTENT_LENGTH)); headerFilters.add(new BasicAuthHeaderFilter()); @@ -75,7 +75,7 @@ public class CurlRequestSnippet extends TemplatedSnippet { @Override protected Map createModel(Operation operation) { - Map model = new HashMap(); + Map model = new HashMap<>(); model.put("url", getUrl(operation)); model.put("options", getOptions(operation)); return model; diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/headers/AbstractHeadersSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/headers/AbstractHeadersSnippet.java index f5e2c126..22391356 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/headers/AbstractHeadersSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/headers/AbstractHeadersSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,7 +76,7 @@ public abstract class AbstractHeadersSnippet extends TemplatedSnippet { private void validateHeaderDocumentation(Operation operation) { List missingHeaders = findMissingHeaders(operation); if (!missingHeaders.isEmpty()) { - List names = new ArrayList(); + List names = new ArrayList<>(); for (HeaderDescriptor headerDescriptor : missingHeaders) { names.add(headerDescriptor.getName()); } @@ -94,7 +94,7 @@ public abstract class AbstractHeadersSnippet extends TemplatedSnippet { * @return descriptors for the headers that are missing from the operation */ protected List findMissingHeaders(Operation operation) { - List missingHeaders = new ArrayList(); + List missingHeaders = new ArrayList<>(); Set actualHeaders = extractActualHeaders(operation); for (HeaderDescriptor headerDescriptor : this.headerDescriptors) { if (!headerDescriptor.isOptional() @@ -132,7 +132,7 @@ public abstract class AbstractHeadersSnippet extends TemplatedSnippet { * @return the model */ protected Map createModelForDescriptor(HeaderDescriptor descriptor) { - Map model = new HashMap(); + Map model = new HashMap<>(); model.put("name", descriptor.getName()); model.put("description", descriptor.getDescription()); model.put("optional", descriptor.isOptional()); diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java index 9060ada9..908b2fb8 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,7 +64,7 @@ public class HttpRequestSnippet extends TemplatedSnippet { @Override protected Map createModel(Operation operation) { - Map model = new HashMap(); + Map model = new HashMap<>(); model.put("method", operation.getRequest().getMethod()); model.put( "path", diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpResponseSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpResponseSnippet.java index 9d2de12c..c9fd1f71 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpResponseSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpResponseSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ public class HttpResponseSnippet extends TemplatedSnippet { protected Map createModel(Operation operation) { OperationResponse response = operation.getResponse(); HttpStatus status = response.getStatus(); - Map model = new HashMap(); + Map model = new HashMap<>(); model.put("responseBody", responseBody(response)); model.put("statusCode", status.value()); model.put("statusReason", status.getReasonPhrase()); diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java index 79ae0ee2..b7f868c8 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -101,7 +101,7 @@ public class LinksSnippet extends TemplatedSnippet { private void validate(Map> links) { Set actualRels = links.keySet(); - Set undocumentedRels = new HashSet(actualRels); + Set undocumentedRels = new HashSet<>(actualRels); undocumentedRels.removeAll(this.descriptorsByRel.keySet()); Set requiredRels = new HashSet<>(); @@ -112,7 +112,7 @@ public class LinksSnippet extends TemplatedSnippet { } } - Set missingRels = new HashSet(requiredRels); + Set missingRels = new HashSet<>(requiredRels); missingRels.removeAll(actualRels); if (!undocumentedRels.isEmpty() || !missingRels.isEmpty()) { diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java index 3bf98a83..3257be17 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,7 +123,7 @@ public abstract class AbstractFieldsSnippet extends TemplatedSnippet { if (message.length() > 0) { message += String.format("%n"); } - List paths = new ArrayList(); + List paths = new ArrayList<>(); for (FieldDescriptor fieldDescriptor : missingFields) { paths.add(fieldDescriptor.getPath()); } @@ -170,7 +170,7 @@ public abstract class AbstractFieldsSnippet extends TemplatedSnippet { * @return the model */ protected Map createModelForDescriptor(FieldDescriptor descriptor) { - Map model = new HashMap(); + Map model = new HashMap<>(); model.put("path", descriptor.getPath()); model.put("type", descriptor.getType().toString()); model.put("description", descriptor.getDescription()); diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/JsonContentHandler.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/JsonContentHandler.java index fab1d1a5..b08f1427 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/JsonContentHandler.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/JsonContentHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ class JsonContentHandler implements ContentHandler { @Override public List findMissingFields(List fieldDescriptors) { - List missingFields = new ArrayList(); + List missingFields = new ArrayList<>(); Object payload = readContent(); for (FieldDescriptor fieldDescriptor : fieldDescriptors) { if (!fieldDescriptor.isOptional() diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/JsonFieldProcessor.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/JsonFieldProcessor.java index 7ef5df39..5e4ed29d 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/JsonFieldProcessor.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/JsonFieldProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ import java.util.concurrent.atomic.AtomicReference; final class JsonFieldProcessor { boolean hasField(JsonFieldPath fieldPath, Object payload) { - final AtomicReference hasField = new AtomicReference(false); + final AtomicReference hasField = new AtomicReference<>(false); traverse(new ProcessingContext(payload, fieldPath), new MatchCallback() { @Override @@ -45,7 +45,7 @@ final class JsonFieldProcessor { } Object extract(JsonFieldPath path, Object payload) { - final List matches = new ArrayList(); + final List matches = new ArrayList<>(); traverse(new ProcessingContext(payload, path), new MatchCallback() { @Override diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java index 0763505b..7eb6e11c 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,9 +84,9 @@ public abstract class AbstractParametersSnippet extends TemplatedSnippet { private void verifyParameterDescriptors(Operation operation) { Set actualParameters = extractActualParameters(operation); Set expectedParameters = this.descriptorsByName.keySet(); - Set undocumentedParameters = new HashSet(actualParameters); + Set undocumentedParameters = new HashSet<>(actualParameters); undocumentedParameters.removeAll(expectedParameters); - Set missingParameters = new HashSet(expectedParameters); + Set missingParameters = new HashSet<>(expectedParameters); missingParameters.removeAll(actualParameters); if (!undocumentedParameters.isEmpty() || !missingParameters.isEmpty()) { diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java index cb9ac288..07adce26 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -174,7 +174,7 @@ public class LinksSnippetTests { private static class StubLinkExtractor implements LinkExtractor { - private MultiValueMap linksByRel = new LinkedMultiValueMap(); + private MultiValueMap linksByRel = new LinkedMultiValueMap<>(); @Override public MultiValueMap extractLinks(OperationResponse response) diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonFieldProcessorTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonFieldProcessorTests.java index d48212f0..1f941597 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonFieldProcessorTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonFieldProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -138,22 +138,22 @@ public class JsonFieldProcessorTests { @Test(expected = FieldDoesNotExistException.class) public void nonExistentNestedField() { - HashMap payload = new HashMap(); + HashMap payload = new HashMap<>(); payload.put("a", new HashMap()); this.fieldProcessor.extract(JsonFieldPath.compile("a.b"), payload); } @Test(expected = FieldDoesNotExistException.class) public void nonExistentNestedFieldWhenParentIsNotAMap() { - HashMap payload = new HashMap(); + HashMap payload = new HashMap<>(); payload.put("a", 5); this.fieldProcessor.extract(JsonFieldPath.compile("a.b"), payload); } @Test(expected = FieldDoesNotExistException.class) public void nonExistentFieldWhenParentIsAnArray() { - HashMap payload = new HashMap(); - HashMap alpha = new HashMap(); + HashMap payload = new HashMap<>(); + HashMap alpha = new HashMap<>(); alpha.put("b", Arrays.asList(new HashMap())); payload.put("a", alpha); this.fieldProcessor.extract(JsonFieldPath.compile("a.b.c"), payload); @@ -161,21 +161,21 @@ public class JsonFieldProcessorTests { @Test(expected = FieldDoesNotExistException.class) public void nonExistentArrayField() { - HashMap payload = new HashMap(); + HashMap payload = new HashMap<>(); this.fieldProcessor.extract(JsonFieldPath.compile("a[]"), payload); } @Test(expected = FieldDoesNotExistException.class) public void nonExistentArrayFieldAsTypeDoesNotMatch() { - HashMap payload = new HashMap(); + HashMap payload = new HashMap<>(); payload.put("a", 5); this.fieldProcessor.extract(JsonFieldPath.compile("a[]"), payload); } @Test(expected = FieldDoesNotExistException.class) public void nonExistentFieldBeneathAnArray() { - HashMap payload = new HashMap(); - HashMap alpha = new HashMap(); + HashMap payload = new HashMap<>(); + HashMap alpha = new HashMap<>(); alpha.put("b", Arrays.asList(new HashMap())); payload.put("a", alpha); this.fieldProcessor.extract(JsonFieldPath.compile("a.b[].id"), payload); diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/OutputCapture.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/OutputCapture.java index 4aab9668..e7b4ef75 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/OutputCapture.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/OutputCapture.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ public class OutputCapture implements TestRule { private ByteArrayOutputStream capturedOutput; - private List> matchers = new ArrayList>(); + private List> matchers = new ArrayList<>(); @Override public Statement apply(final Statement base, Description description) { diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/SnippetMatchers.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/SnippetMatchers.java index d45388a0..97818a52 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/SnippetMatchers.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/test/SnippetMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,7 +74,7 @@ public final class SnippetMatchers { private static abstract class AbstractSnippetContentMatcher extends BaseMatcher { - private List lines = new ArrayList(); + private List lines = new ArrayList<>(); protected void addLine(String line) { this.lines.add(line); diff --git a/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/IterableEnumeration.java b/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/IterableEnumeration.java index d80edb13..d4b9653f 100644 --- a/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/IterableEnumeration.java +++ b/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/IterableEnumeration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,7 +63,7 @@ final class IterableEnumeration implements Iterable { * @return the iterable */ static Iterable iterable(Enumeration enumeration) { - return new IterableEnumeration(enumeration); + return new IterableEnumeration<>(enumeration); } } diff --git a/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java b/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java index 546a17e7..76e3dd67 100644 --- a/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java +++ b/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -430,8 +430,7 @@ public class MockMvcRestDocumentationIntegrationTests { response.put("links", Arrays.asList(new Link("rel", "href"))); HttpHeaders headers = new HttpHeaders(); headers.add("a", "alpha"); - return new ResponseEntity>(response, headers, - HttpStatus.OK); + return new ResponseEntity<>(response, headers, HttpStatus.OK); } @RequestMapping(value = "/company/5", produces = MediaType.APPLICATION_JSON_VALUE)