From c279f3940bf6cf60d0af215a54c19681ddfb0eb4 Mon Sep 17 00:00:00 2001 From: Ben Hale Date: Wed, 24 Oct 2012 13:12:20 +0100 Subject: [PATCH] Make source code Java 6 compatible For issue #4, this expands diamond operators and converts switch statements with `String`s to if statements. This makes the code Java 6 compatible. --- build.gradle | 6 ++--- .../rest/shell/commands/ContextCommands.java | 6 ++--- .../shell/commands/DiscoveryCommands.java | 4 ++-- .../shell/commands/HierarchyCommands.java | 22 +++++-------------- .../rest/shell/commands/HistoryCommands.java | 2 +- .../rest/shell/commands/HttpCommands.java | 6 ++--- .../data/rest/shell/commands/Links.java | 2 +- 7 files changed, 19 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index aacc53c..bd1a3fb 100644 --- a/build.gradle +++ b/build.gradle @@ -29,8 +29,8 @@ configurations { compile.extendsFrom providedCompile } [compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:unchecked"] -project.sourceCompatibility = 1.7 -project.targetCompatibility = 1.7 +project.sourceCompatibility = 1.6 +project.targetCompatibility = 1.6 // Repositories repositories { @@ -115,4 +115,4 @@ idea { } } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/rest/shell/commands/ContextCommands.java b/src/main/java/org/springframework/data/rest/shell/commands/ContextCommands.java index d8405a7..691efa5 100644 --- a/src/main/java/org/springframework/data/rest/shell/commands/ContextCommands.java +++ b/src/main/java/org/springframework/data/rest/shell/commands/ContextCommands.java @@ -44,7 +44,7 @@ public class ContextCommands implements CommandMarker, InitializingBean { private static final PropertyAccessor ENV_ACCESSOR = new EnvironmentAccessor(); private static final Environment ENV = new StandardEnvironment(); - final Map variables = new HashMap<>(); + final Map variables = new HashMap(); StandardEvaluationContext evalCtx; private final SpelExpressionParser parser = new SpelExpressionParser(); @@ -179,7 +179,7 @@ public String evalAsString(String expr) { private void setup() { evalCtx = new StandardEvaluationContext(variables); - List accessors = new ArrayList<>(); + List accessors = new ArrayList(); accessors.add(MAP_ACCESOR); accessors.add(BEAN_ACCESOR); accessors.add(ENV_ACCESSOR); @@ -188,4 +188,4 @@ private void setup() { variables.put("env", ENV); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/rest/shell/commands/DiscoveryCommands.java b/src/main/java/org/springframework/data/rest/shell/commands/DiscoveryCommands.java index 6055dd1..a8f638d 100644 --- a/src/main/java/org/springframework/data/rest/shell/commands/DiscoveryCommands.java +++ b/src/main/java/org/springframework/data/rest/shell/commands/DiscoveryCommands.java @@ -54,7 +54,7 @@ public class DiscoveryCommands implements CommandMarker, ApplicationEventPublish private RestTemplate client = new RestTemplate(); @Autowired(required = false) private ObjectMapper mapper = new ObjectMapper(); - private Map resources = new HashMap<>(); + private Map resources = new HashMap(); @Override public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { this.ctx = applicationEventPublisher; @@ -226,7 +226,7 @@ private class ExtractLinksHelper implements RequestCallback, ResponseExtractor extractData(ClientHttpResponse response) throws IOException { - List links = new ArrayList<>(); + List links = new ArrayList(); MediaType ct = response.getHeaders().getContentType(); if(null != ct && ct.getSubtype().endsWith("json")) { diff --git a/src/main/java/org/springframework/data/rest/shell/commands/HierarchyCommands.java b/src/main/java/org/springframework/data/rest/shell/commands/HierarchyCommands.java index e8cbe9a..9bc65e6 100644 --- a/src/main/java/org/springframework/data/rest/shell/commands/HierarchyCommands.java +++ b/src/main/java/org/springframework/data/rest/shell/commands/HierarchyCommands.java @@ -25,13 +25,8 @@ public class HierarchyCommands implements CommandMarker { @CliAvailabilityIndicator({"up"}) public boolean isHierarchyAvailable() { - switch(configCmds.getBaseUri().getPath()) { - case "": - case "/": - return false; - default: - return true; - } + String path = configCmds.getBaseUri().getPath(); + return !("".equals(path) || "/".equals(path)); } /** @@ -46,15 +41,10 @@ public void up() throws URISyntaxException { URI baseUri = configCmds.getBaseUri(); String path = baseUri.getPath(); - switch(path) { - case "": - case "/": - return; - default: { - int idx = path.lastIndexOf("/"); - String newPath = path.substring(0, idx); - configCmds.setBaseUri(UriComponentsBuilder.fromUri(baseUri).replacePath(newPath).build().toUriString()); - } + if (!("".equals(path) || "/".equals(path))) { + int idx = path.lastIndexOf("/"); + String newPath = path.substring(0, idx); + configCmds.setBaseUri(UriComponentsBuilder.fromUri(baseUri).replacePath(newPath).build().toUriString()); } } diff --git a/src/main/java/org/springframework/data/rest/shell/commands/HistoryCommands.java b/src/main/java/org/springframework/data/rest/shell/commands/HistoryCommands.java index f0a521a..f136a8f 100644 --- a/src/main/java/org/springframework/data/rest/shell/commands/HistoryCommands.java +++ b/src/main/java/org/springframework/data/rest/shell/commands/HistoryCommands.java @@ -25,7 +25,7 @@ public class HistoryCommands implements CommandMarker, ApplicationListener baseUris = new ArrayList<>(); + private List baseUris = new ArrayList(); @Override public void onApplicationEvent(BaseUriChangedEvent event) { baseUris.add(event.getBaseUri()); diff --git a/src/main/java/org/springframework/data/rest/shell/commands/HttpCommands.java b/src/main/java/org/springframework/data/rest/shell/commands/HttpCommands.java index cdda7fa..9607864 100644 --- a/src/main/java/org/springframework/data/rest/shell/commands/HttpCommands.java +++ b/src/main/java/org/springframework/data/rest/shell/commands/HttpCommands.java @@ -493,8 +493,8 @@ private class RequestHelper implements RequestCallback, private Object body; private MediaType contentType; - private HttpMessageConverterExtractor extractor = new HttpMessageConverterExtractor<>(String.class, - restTemplate.getMessageConverters()); + private HttpMessageConverterExtractor extractor = new HttpMessageConverterExtractor(String.class, + restTemplate.getMessageConverters()); private ObjectMapper mapper = new ObjectMapper(); { @@ -565,7 +565,7 @@ private RequestHelper(Object body, MediaType contentType) { body = sw.toString(); } - return new ResponseEntity<>(body, response.getHeaders(), response.getStatusCode()); + return new ResponseEntity(body, response.getHeaders(), response.getStatusCode()); } } diff --git a/src/main/java/org/springframework/data/rest/shell/commands/Links.java b/src/main/java/org/springframework/data/rest/shell/commands/Links.java index 02a5bf2..98a503c 100644 --- a/src/main/java/org/springframework/data/rest/shell/commands/Links.java +++ b/src/main/java/org/springframework/data/rest/shell/commands/Links.java @@ -17,7 +17,7 @@ public class Links { private final PropertyAccessor propertyAccessor = new Accessor(); - private final List links = new ArrayList<>(); + private final List links = new ArrayList(); public Links() { }