From 685b0bc0c29700edd27a1ae148b75b417947b8ac Mon Sep 17 00:00:00 2001 From: Mike Becker Date: Thu, 5 Dec 2019 18:58:06 +0100 Subject: [PATCH] renames PetriNet to Petrinet and uses the parser as a resource in Main --- src/main/java/de/yasc/example/petrinet/Main.java | 5 ++--- .../example/petrinet/{PetriNet.java => Petrinet.java} | 4 ++-- .../java/de/yasc/example/petrinet/PetrinetParser.java | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) rename src/main/java/de/yasc/example/petrinet/{PetriNet.java => Petrinet.java} (97%) diff --git a/src/main/java/de/yasc/example/petrinet/Main.java b/src/main/java/de/yasc/example/petrinet/Main.java index 8788f76..a3b5ca3 100644 --- a/src/main/java/de/yasc/example/petrinet/Main.java +++ b/src/main/java/de/yasc/example/petrinet/Main.java @@ -5,12 +5,11 @@ import java.util.Arrays; public class Main { public static void main(String arg[]) { - try { - var parser = new PetrinetParser(System.in); + try (var parser = new PetrinetParser(System.in)) { var net = parser.read(); + // test code net.step(2); - System.out.println(Arrays.asList(net.getMarking()).toString()); } catch (IOException ex) { System.err.println("Error: "+ex.getMessage()); diff --git a/src/main/java/de/yasc/example/petrinet/PetriNet.java b/src/main/java/de/yasc/example/petrinet/Petrinet.java similarity index 97% rename from src/main/java/de/yasc/example/petrinet/PetriNet.java rename to src/main/java/de/yasc/example/petrinet/Petrinet.java index 010a279..f8882f2 100644 --- a/src/main/java/de/yasc/example/petrinet/PetriNet.java +++ b/src/main/java/de/yasc/example/petrinet/Petrinet.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Random; import java.util.stream.Collectors; -public final class PetriNet { +public final class Petrinet { private static final class Place { @@ -51,7 +51,7 @@ public final class PetriNet { final private Place[] places; final private List transitions; - public PetriNet(int places) { + public Petrinet(int places) { this.places = new Place[places]; for (int i = 0 ; i < places ; i++) this.places[i] = new Place(); diff --git a/src/main/java/de/yasc/example/petrinet/PetrinetParser.java b/src/main/java/de/yasc/example/petrinet/PetrinetParser.java index 9a70a42..21d63a8 100644 --- a/src/main/java/de/yasc/example/petrinet/PetrinetParser.java +++ b/src/main/java/de/yasc/example/petrinet/PetrinetParser.java @@ -112,8 +112,8 @@ public final class PetrinetParser implements AutoCloseable { } } - public PetriNet read() throws IOException { - PetriNet result = null; + public Petrinet read() throws IOException { + Petrinet result = null; String input; int line = 0; @@ -125,7 +125,7 @@ public final class PetrinetParser implements AutoCloseable { case COMMENT: break; case PLACES: if (result == null) { - result = new PetriNet(parsedLine.val0); + result = new Petrinet(parsedLine.val0); } else { throw new IOException("places command must occur once"); } @@ -154,7 +154,7 @@ public final class PetrinetParser implements AutoCloseable { } @Override - public void close() throws Exception { + public void close() throws IOException { reader.close(); } } -- 2.43.5