Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Java runner #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions Java/com/gildedrose/GildedRoseTest.java

This file was deleted.

37 changes: 0 additions & 37 deletions Java/com/gildedrose/TexttestFixture.java

This file was deleted.

50 changes: 50 additions & 0 deletions Java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>
<artifactId>gilded-rose</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.gildedrose.Runner</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
55 changes: 55 additions & 0 deletions Java/src/main/java/com/gildedrose/Runner.java
Original file line number Diff line number Diff line change
@@ -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<String> 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);
}
}
}