From d8bdac58138d274f58407c32527cb79802454672 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 4 Nov 2018 02:05:32 +0530 Subject: [PATCH] [BAEL-9551] - Clean up code --- .../roundUpToHundred/.gitignore | 1 - .../src/com/java/src/RoundUpToHundred.java | 20 ------------- .../com/java/src/RoundUpToHundredTest.java | 14 ---------- .../com/baeldung/algorithms/RunAlgorithm.java | 16 ++--------- algorithms-miscellaneous-1/README.md | 3 +- .../roundUpToHundred/.gitignore | 1 - .../com/java/src/RoundUpToHundredTest.java | 14 ---------- .../src/main/resources/maze/maze1.txt | 12 -------- .../src/main/resources/maze/maze2.txt | 22 --------------- algorithms-miscellaneous-2/README.md | 1 - .../roundUpToHundred/.gitignore | 1 - .../src/com/java/src/RoundUpToHundred.java | 20 ------------- .../com/baeldung/algorithms/RunAlgorithm.java | 28 +++++++++++++++++++ .../algorithms/ga/dijkstra/Dijkstra.java | 0 .../algorithms/ga/dijkstra/Graph.java | 0 .../baeldung/algorithms/ga/dijkstra/Node.java | 0 .../roundedup}/RoundUpToHundred.java | 2 +- .../algorithms/slope_one/InputData.java | 0 .../baeldung/algorithms/slope_one/Item.java | 0 .../algorithms/slope_one/SlopeOne.java | 0 .../baeldung/algorithms/slope_one/User.java | 0 .../DijkstraAlgorithmLongRunningUnitTest.java | 0 .../roundedup/RoundUpToHundredUnitTest.java} | 4 +-- .../roundUpToHundred/.gitignore | 1 - .../src/com/java/src/RoundUpToHundred.java | 20 ------------- .../com/java/src/RoundUpToHundredTest.java | 14 ---------- 26 files changed, 36 insertions(+), 158 deletions(-) delete mode 100644 algorithms-genetic/roundUpToHundred/.gitignore delete mode 100644 algorithms-genetic/roundUpToHundred/src/com/java/src/RoundUpToHundred.java delete mode 100644 algorithms-genetic/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java delete mode 100644 algorithms-miscellaneous-1/roundUpToHundred/.gitignore delete mode 100644 algorithms-miscellaneous-1/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java delete mode 100644 algorithms-miscellaneous-1/src/main/resources/maze/maze1.txt delete mode 100644 algorithms-miscellaneous-1/src/main/resources/maze/maze2.txt delete mode 100644 algorithms-miscellaneous-2/roundUpToHundred/.gitignore delete mode 100644 algorithms-miscellaneous-2/roundUpToHundred/src/com/java/src/RoundUpToHundred.java create mode 100644 algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/RunAlgorithm.java rename {algorithms-genetic => algorithms-miscellaneous-2}/src/main/java/com/baeldung/algorithms/ga/dijkstra/Dijkstra.java (100%) rename {algorithms-genetic => algorithms-miscellaneous-2}/src/main/java/com/baeldung/algorithms/ga/dijkstra/Graph.java (100%) rename {algorithms-genetic => algorithms-miscellaneous-2}/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java (100%) rename {algorithms-miscellaneous-1/roundUpToHundred/src/com/java/src => algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup}/RoundUpToHundred.java (90%) rename {algorithms-genetic => algorithms-miscellaneous-2}/src/main/java/com/baeldung/algorithms/slope_one/InputData.java (100%) rename {algorithms-genetic => algorithms-miscellaneous-2}/src/main/java/com/baeldung/algorithms/slope_one/Item.java (100%) rename {algorithms-genetic => algorithms-miscellaneous-2}/src/main/java/com/baeldung/algorithms/slope_one/SlopeOne.java (100%) rename {algorithms-genetic => algorithms-miscellaneous-2}/src/main/java/com/baeldung/algorithms/slope_one/User.java (100%) rename {algorithms-genetic => algorithms-miscellaneous-2}/src/test/java/com/baeldung/algorithms/DijkstraAlgorithmLongRunningUnitTest.java (100%) rename algorithms-miscellaneous-2/{roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java => src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java} (83%) delete mode 100644 algorithms-sorting/roundUpToHundred/.gitignore delete mode 100644 algorithms-sorting/roundUpToHundred/src/com/java/src/RoundUpToHundred.java delete mode 100644 algorithms-sorting/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java diff --git a/algorithms-genetic/roundUpToHundred/.gitignore b/algorithms-genetic/roundUpToHundred/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/algorithms-genetic/roundUpToHundred/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/algorithms-genetic/roundUpToHundred/src/com/java/src/RoundUpToHundred.java b/algorithms-genetic/roundUpToHundred/src/com/java/src/RoundUpToHundred.java deleted file mode 100644 index 6c02a340d3..0000000000 --- a/algorithms-genetic/roundUpToHundred/src/com/java/src/RoundUpToHundred.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.java.src; - -import java.util.Scanner; - -public class RoundUpToHundred { - - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - double input = scanner.nextDouble(); - scanner.close(); - - RoundUpToHundred.round(input); - } - - static long round(double input) { - long i = (long) Math.ceil(input); - return ((i + 99) / 100) * 100; - }; - -} diff --git a/algorithms-genetic/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java b/algorithms-genetic/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java deleted file mode 100644 index cb541ad49c..0000000000 --- a/algorithms-genetic/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.java.src; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class RoundUpToHundredTest { - @Test - public void givenInput_whenRound_thenRoundUpToTheNearestHundred() { - assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99)); - assertEquals("Rounded up to three hundred ", 300, RoundUpToHundred.round(200.2)); - assertEquals("Returns same rounded value", 400, RoundUpToHundred.round(400)); - } -} diff --git a/algorithms-genetic/src/main/java/com/baeldung/algorithms/RunAlgorithm.java b/algorithms-genetic/src/main/java/com/baeldung/algorithms/RunAlgorithm.java index ce04d26db3..779cb9b970 100644 --- a/algorithms-genetic/src/main/java/com/baeldung/algorithms/RunAlgorithm.java +++ b/algorithms-genetic/src/main/java/com/baeldung/algorithms/RunAlgorithm.java @@ -5,7 +5,6 @@ import java.util.Scanner; import com.baeldung.algorithms.ga.annealing.SimulatedAnnealing; import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization; import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm; -import com.baeldung.algorithms.slope_one.SlopeOne; public class RunAlgorithm { @@ -13,11 +12,8 @@ public class RunAlgorithm { Scanner in = new Scanner(System.in); System.out.println("Run algorithm:"); System.out.println("1 - Simulated Annealing"); - System.out.println("2 - Slope One"); - System.out.println("3 - Simple Genetic Algorithm"); - System.out.println("4 - Ant Colony"); - System.out.println("5 - Dijkstra"); - System.out.println("6 - All pairs in an array that add up to a given sum"); + System.out.println("2 - Simple Genetic Algorithm"); + System.out.println("3 - Ant Colony"); int decision = in.nextInt(); switch (decision) { case 1: @@ -25,19 +21,13 @@ public class RunAlgorithm { "Optimized distance for travel: " + SimulatedAnnealing.simulateAnnealing(10, 10000, 0.9995)); break; case 2: - SlopeOne.slopeOne(3); - break; - case 3: SimpleGeneticAlgorithm ga = new SimpleGeneticAlgorithm(); ga.runAlgorithm(50, "1011000100000100010000100000100111001000000100000100000000001111"); break; - case 4: + case 3: AntColonyOptimization antColony = new AntColonyOptimization(21); antColony.startAntOptimization(); break; - case 5: - System.out.println("Please run the DijkstraAlgorithmTest."); - break; default: System.out.println("Unknown option"); break; diff --git a/algorithms-miscellaneous-1/README.md b/algorithms-miscellaneous-1/README.md index 9efb2233bf..a04874c4d2 100644 --- a/algorithms-miscellaneous-1/README.md +++ b/algorithms-miscellaneous-1/README.md @@ -9,4 +9,5 @@ - [How to Find the Kth Largest Element in Java](http://www.baeldung.com/java-kth-largest-element) - [Multi-Swarm Optimization Algorithm in Java](http://www.baeldung.com/java-multi-swarm-algorithm) - [String Search Algorithms for Large Texts](http://www.baeldung.com/java-full-text-search-algorithms) -- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters) \ No newline at end of file +- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters) +- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element) \ No newline at end of file diff --git a/algorithms-miscellaneous-1/roundUpToHundred/.gitignore b/algorithms-miscellaneous-1/roundUpToHundred/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/algorithms-miscellaneous-1/roundUpToHundred/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/algorithms-miscellaneous-1/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java b/algorithms-miscellaneous-1/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java deleted file mode 100644 index cb541ad49c..0000000000 --- a/algorithms-miscellaneous-1/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.java.src; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class RoundUpToHundredTest { - @Test - public void givenInput_whenRound_thenRoundUpToTheNearestHundred() { - assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99)); - assertEquals("Rounded up to three hundred ", 300, RoundUpToHundred.round(200.2)); - assertEquals("Returns same rounded value", 400, RoundUpToHundred.round(400)); - } -} diff --git a/algorithms-miscellaneous-1/src/main/resources/maze/maze1.txt b/algorithms-miscellaneous-1/src/main/resources/maze/maze1.txt deleted file mode 100644 index 8b48c325d2..0000000000 --- a/algorithms-miscellaneous-1/src/main/resources/maze/maze1.txt +++ /dev/null @@ -1,12 +0,0 @@ -S ######## -# # -# ### ## # -# # # # -# # # # # -# ## ##### -# # # -# # # # # -##### #### -# # E -# # # # -########## \ No newline at end of file diff --git a/algorithms-miscellaneous-1/src/main/resources/maze/maze2.txt b/algorithms-miscellaneous-1/src/main/resources/maze/maze2.txt deleted file mode 100644 index df5b6bc66b..0000000000 --- a/algorithms-miscellaneous-1/src/main/resources/maze/maze2.txt +++ /dev/null @@ -1,22 +0,0 @@ -S ########################## -# # # # -# # #### ############### # -# # # # # # -# # #### # # ############### -# # # # # # # -# # # #### ### ########### # -# # # # # # -# ################## # -######### # # # # # -# # #### # ####### # # -# # ### ### # # # # # -# # ## # ##### # # -##### ####### # # # # # -# # ## ## #### # # -# ##### ####### # # -# # ############ -####### ######### # # -# # ######## # -# ####### ###### ## # E -# # # ## # -############################ \ No newline at end of file diff --git a/algorithms-miscellaneous-2/README.md b/algorithms-miscellaneous-2/README.md index 2634fd6b56..6772a94a8d 100644 --- a/algorithms-miscellaneous-2/README.md +++ b/algorithms-miscellaneous-2/README.md @@ -10,7 +10,6 @@ - [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations) - [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic) - [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity) -- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element) - [An Introduction to the Theory of Big-O Notation](http://www.baeldung.com/big-o-notation) - [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap) - [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points) diff --git a/algorithms-miscellaneous-2/roundUpToHundred/.gitignore b/algorithms-miscellaneous-2/roundUpToHundred/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/algorithms-miscellaneous-2/roundUpToHundred/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/algorithms-miscellaneous-2/roundUpToHundred/src/com/java/src/RoundUpToHundred.java b/algorithms-miscellaneous-2/roundUpToHundred/src/com/java/src/RoundUpToHundred.java deleted file mode 100644 index 6c02a340d3..0000000000 --- a/algorithms-miscellaneous-2/roundUpToHundred/src/com/java/src/RoundUpToHundred.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.java.src; - -import java.util.Scanner; - -public class RoundUpToHundred { - - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - double input = scanner.nextDouble(); - scanner.close(); - - RoundUpToHundred.round(input); - } - - static long round(double input) { - long i = (long) Math.ceil(input); - return ((i + 99) / 100) * 100; - }; - -} diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/RunAlgorithm.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/RunAlgorithm.java new file mode 100644 index 0000000000..a1a096bc30 --- /dev/null +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/RunAlgorithm.java @@ -0,0 +1,28 @@ +package com.baeldung.algorithms; + +import java.util.Scanner; + +import com.baeldung.algorithms.slope_one.SlopeOne; + +public class RunAlgorithm { + + public static void main(String[] args) throws InstantiationException, IllegalAccessException { + Scanner in = new Scanner(System.in); + System.out.println("1 - Slope One"); + System.out.println("2 - Dijkstra"); + int decision = in.nextInt(); + switch (decision) { + case 1: + SlopeOne.slopeOne(3); + break; + case 2: + System.out.println("Please run the DijkstraAlgorithmLongRunningUnitTest."); + break; + default: + System.out.println("Unknown option"); + break; + } + in.close(); + } + +} diff --git a/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/dijkstra/Dijkstra.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Dijkstra.java similarity index 100% rename from algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/dijkstra/Dijkstra.java rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Dijkstra.java diff --git a/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/dijkstra/Graph.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Graph.java similarity index 100% rename from algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/dijkstra/Graph.java rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Graph.java diff --git a/algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java similarity index 100% rename from algorithms-genetic/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/ga/dijkstra/Node.java diff --git a/algorithms-miscellaneous-1/roundUpToHundred/src/com/java/src/RoundUpToHundred.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java similarity index 90% rename from algorithms-miscellaneous-1/roundUpToHundred/src/com/java/src/RoundUpToHundred.java rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java index 6c02a340d3..333019e294 100644 --- a/algorithms-miscellaneous-1/roundUpToHundred/src/com/java/src/RoundUpToHundred.java +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java @@ -1,4 +1,4 @@ -package com.java.src; +package com.baeldung.algorithms.roundedup; import java.util.Scanner; diff --git a/algorithms-genetic/src/main/java/com/baeldung/algorithms/slope_one/InputData.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/InputData.java similarity index 100% rename from algorithms-genetic/src/main/java/com/baeldung/algorithms/slope_one/InputData.java rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/InputData.java diff --git a/algorithms-genetic/src/main/java/com/baeldung/algorithms/slope_one/Item.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/Item.java similarity index 100% rename from algorithms-genetic/src/main/java/com/baeldung/algorithms/slope_one/Item.java rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/Item.java diff --git a/algorithms-genetic/src/main/java/com/baeldung/algorithms/slope_one/SlopeOne.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/SlopeOne.java similarity index 100% rename from algorithms-genetic/src/main/java/com/baeldung/algorithms/slope_one/SlopeOne.java rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/SlopeOne.java diff --git a/algorithms-genetic/src/main/java/com/baeldung/algorithms/slope_one/User.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/User.java similarity index 100% rename from algorithms-genetic/src/main/java/com/baeldung/algorithms/slope_one/User.java rename to algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/slope_one/User.java diff --git a/algorithms-genetic/src/test/java/com/baeldung/algorithms/DijkstraAlgorithmLongRunningUnitTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/DijkstraAlgorithmLongRunningUnitTest.java similarity index 100% rename from algorithms-genetic/src/test/java/com/baeldung/algorithms/DijkstraAlgorithmLongRunningUnitTest.java rename to algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/DijkstraAlgorithmLongRunningUnitTest.java diff --git a/algorithms-miscellaneous-2/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java similarity index 83% rename from algorithms-miscellaneous-2/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java rename to algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java index cb541ad49c..5191d65787 100644 --- a/algorithms-miscellaneous-2/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java +++ b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java @@ -1,10 +1,10 @@ -package com.java.src; +package com.baeldung.algorithms.roundedup; import static org.junit.Assert.assertEquals; import org.junit.Test; -public class RoundUpToHundredTest { +public class RoundUpToHundredUnitTest { @Test public void givenInput_whenRound_thenRoundUpToTheNearestHundred() { assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99)); diff --git a/algorithms-sorting/roundUpToHundred/.gitignore b/algorithms-sorting/roundUpToHundred/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/algorithms-sorting/roundUpToHundred/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/algorithms-sorting/roundUpToHundred/src/com/java/src/RoundUpToHundred.java b/algorithms-sorting/roundUpToHundred/src/com/java/src/RoundUpToHundred.java deleted file mode 100644 index 6c02a340d3..0000000000 --- a/algorithms-sorting/roundUpToHundred/src/com/java/src/RoundUpToHundred.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.java.src; - -import java.util.Scanner; - -public class RoundUpToHundred { - - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - double input = scanner.nextDouble(); - scanner.close(); - - RoundUpToHundred.round(input); - } - - static long round(double input) { - long i = (long) Math.ceil(input); - return ((i + 99) / 100) * 100; - }; - -} diff --git a/algorithms-sorting/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java b/algorithms-sorting/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java deleted file mode 100644 index cb541ad49c..0000000000 --- a/algorithms-sorting/roundUpToHundred/src/com/java/src/RoundUpToHundredTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.java.src; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class RoundUpToHundredTest { - @Test - public void givenInput_whenRound_thenRoundUpToTheNearestHundred() { - assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99)); - assertEquals("Rounded up to three hundred ", 300, RoundUpToHundred.round(200.2)); - assertEquals("Returns same rounded value", 400, RoundUpToHundred.round(400)); - } -}