From 3a359f7bc26f63a508154eeac97d9de9b4cfb893 Mon Sep 17 00:00:00 2001 From: Patrick Shields Date: Sun, 3 Mar 2019 13:49:55 -0500 Subject: [PATCH 1/3] Remove extra java "test fixture" --- Java/com/gildedrose/GildedRoseTest.java | 17 ----------- Java/com/gildedrose/TexttestFixture.java | 37 ------------------------ 2 files changed, 54 deletions(-) delete mode 100644 Java/com/gildedrose/GildedRoseTest.java delete mode 100644 Java/com/gildedrose/TexttestFixture.java diff --git a/Java/com/gildedrose/GildedRoseTest.java b/Java/com/gildedrose/GildedRoseTest.java deleted file mode 100644 index d679c458c0..0000000000 --- a/Java/com/gildedrose/GildedRoseTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gildedrose; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class GildedRoseTest { - - @Test - public void foo() { - Item[] items = new Item[] { new Item("foo", 0, 0) }; - GildedRose app = new GildedRose(items); - app.updateQuality(); - assertEquals("fixme", app.items[0].name); - } - -} diff --git a/Java/com/gildedrose/TexttestFixture.java b/Java/com/gildedrose/TexttestFixture.java deleted file mode 100644 index 821b7f1dda..0000000000 --- a/Java/com/gildedrose/TexttestFixture.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.gildedrose; - -public class TexttestFixture { - public static void main(String[] args) { - System.out.println("OMGHAI!"); - - Item[] items = new Item[] { - new Item("+5 Dexterity Vest", 10, 20), // - new Item("Aged Brie", 2, 0), // - new Item("Elixir of the Mongoose", 5, 7), // - new Item("Sulfuras, Hand of Ragnaros", 0, 80), // - new Item("Sulfuras, Hand of Ragnaros", -1, 80), - new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), - new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), - new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), - // this conjured item does not work properly yet - new Item("Conjured Mana Cake", 3, 6) }; - - GildedRose app = new GildedRose(items); - - int days = 2; - if (args.length > 0) { - days = Integer.parseInt(args[0]) + 1; - } - - for (int i = 0; i < days; i++) { - System.out.println("-------- day " + i + " --------"); - System.out.println("name, sellIn, quality"); - for (Item item : items) { - System.out.println(item); - } - System.out.println(); - app.updateQuality(); - } - } - -} From 513ff988276c6f823abb7fbbebe9633a99caaf2b Mon Sep 17 00:00:00 2001 From: Patrick Shields Date: Sun, 3 Mar 2019 13:50:16 -0500 Subject: [PATCH 2/3] Switch java to use maven --- Java/pom.xml | 50 +++++++++++++++++++ .../main/java}/com/gildedrose/GildedRose.java | 0 .../main/java}/com/gildedrose/Item.java | 0 3 files changed, 50 insertions(+) create mode 100644 Java/pom.xml rename Java/{ => src/main/java}/com/gildedrose/GildedRose.java (100%) rename Java/{ => src/main/java}/com/gildedrose/Item.java (100%) diff --git a/Java/pom.xml b/Java/pom.xml new file mode 100644 index 0000000000..7cc3753500 --- /dev/null +++ b/Java/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + + com.mycompany.app + gilded-rose + 1.0-SNAPSHOT + + + 1.8 + 1.8 + + + + + junit + junit + 4.12 + test + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + + exec + + + + + com.gildedrose.Runner + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + diff --git a/Java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java similarity index 100% rename from Java/com/gildedrose/GildedRose.java rename to Java/src/main/java/com/gildedrose/GildedRose.java diff --git a/Java/com/gildedrose/Item.java b/Java/src/main/java/com/gildedrose/Item.java similarity index 100% rename from Java/com/gildedrose/Item.java rename to Java/src/main/java/com/gildedrose/Item.java From 85513942f5f6fe744cb5a437eecd2eff4bb656eb Mon Sep 17 00:00:00 2001 From: Patrick Shields Date: Sun, 3 Mar 2019 13:50:28 -0500 Subject: [PATCH 3/3] Add java runner --- Java/src/main/java/com/gildedrose/Runner.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Java/src/main/java/com/gildedrose/Runner.java diff --git a/Java/src/main/java/com/gildedrose/Runner.java b/Java/src/main/java/com/gildedrose/Runner.java new file mode 100644 index 0000000000..e04951de51 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/Runner.java @@ -0,0 +1,55 @@ +package com.gildedrose; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Runner { + private static Item itemFromLine(String itemLine) { + String[] pieces = itemLine.split("__"); + return new Item(pieces[0], Integer.parseInt(pieces[1]), Integer.parseInt(pieces[2])); + } + + public static void main(String[] args) { + if (args.length < 2) { + System.out.println("Please pass in and out file args"); + System.exit(1); + } + + String inFile = args[0]; + String outFile = args[1]; + + System.out.println("Reading from: " + inFile + ". Writing to: " + outFile); + + Item[] items = null; + + try (Stream stream = Files.lines(Paths.get(inFile))) { + items = stream.filter(s -> !(s.isEmpty() || s.startsWith(";"))) + .map(Runner::itemFromLine) + .toArray(Item[]::new); + } catch (IOException e) { + System.out.println("Error reading infile: " + inFile); + System.exit(1); + } + + GildedRose gildedRose = new GildedRose(items); + gildedRose.updateQuality(); + + String outString = Stream.of(gildedRose.items) + .map(item -> String.join("__", + item.name, + Integer.toString(item.sellIn), + Integer.toString(item.quality))) + .collect(Collectors.joining("\n")); + + try { + Files.write(Paths.get(outFile), outString.getBytes(StandardCharsets.US_ASCII)); + } catch (IOException e) { + System.out.println("Error writing outfile: " + outFile); + System.exit(1); + } + } +}