From 52a5a7cc24629d8d738f7f653a74f3f05fdf4037 Mon Sep 17 00:00:00 2001 From: Alexander Danilchenko <39950413+OlexanderD@users.noreply.github.com> Date: Sun, 12 Jan 2020 18:34:55 +0200 Subject: [PATCH] Changed code style according to new Java versions Changed long and ugly type declarations with "var" keyword (Java 10). Also fixed warning about raw usage of HashSet without type specification. --- .../java/01_set_covering/src/SetCovering.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java b/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java index 9afd2c8..c9cbff6 100644 --- a/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java +++ b/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java @@ -1,10 +1,9 @@ import java.util.*; public class SetCovering { - - public static void main(String[] args) { - Set statesNeeded = new HashSet(Arrays.asList("mt", "wa", "or", "id", "nv", "ut", "ca", "az")); - Map> stations = new LinkedHashMap<>(); + public static void main(String... args) { + var statesNeeded = new HashSet<>(Arrays.asList("mt", "wa", "or", "id", "nv", "ut", "ca", "az")); + var stations = new LinkedHashMap>(); stations.put("kone", new HashSet<>(Arrays.asList("id", "nv", "ut"))); stations.put("ktwo", new HashSet<>(Arrays.asList("wa", "id", "mt"))); @@ -12,13 +11,13 @@ public class SetCovering { stations.put("kfour", new HashSet<>(Arrays.asList("nv", "ut"))); stations.put("kfive", new HashSet<>(Arrays.asList("ca", "az"))); - Set finalStations = new HashSet(); + var finalStations = new HashSet(); while (!statesNeeded.isEmpty()) { String bestStation = null; - Set statesCovered = new HashSet<>(); + var statesCovered = new HashSet(); - for (Map.Entry> station : stations.entrySet()) { - Set covered = new HashSet<>(statesNeeded); + for (var station : stations.entrySet()) { + var covered = new HashSet<>(statesNeeded); covered.retainAll(station.getValue()); if (covered.size() > statesCovered.size()) {