static ArrayList<String> checkForNewTransitionsAndPlaces( String sRead, ArrayList<Transition> transitions, ArrayList<Place> places, PetriNet pn) { ArrayList<String> stParts = new ArrayList<String>(Arrays.asList(sRead.split(" "))); int k; for (int i = 0; i < stParts.size(); i++) { String st = stParts.get(i); if (isPlace(st)) { if (findPlace(st, places) == null) { Place p = new Place(st, pn); pn.addPlace(p); places.add(p); } } else { st = repairTransitionString(st); k = st.indexOf(PetrifyConstants.EDGEDOCSSEPARATOR); if (k != -1) { if (findTransition(st, transitions) == null) { Transition t = new Transition(new LogEvent(st, ""), pn); pn.addTransition(t); t.setIdentifier(st); transitions.add(t); } } } } return stParts; }
public static PetriNet read(InputStream input) throws IOException { PetriNet pn = new PetriNet(); ArrayList<Transition> transitions = new ArrayList<Transition>(); ArrayList<Place> places = new ArrayList<Place>(); BufferedReader in = new BufferedReader(new InputStreamReader(input)); ArrayList<String> events; ArrayList<String> stParts; String sRead, s; do { // go through comments sRead = in.readLine(); } while (sRead.charAt(0) == '#'); sRead = in.readLine(); // get the set of events and create PN transitions s = sRead.substring(sRead.indexOf(" ") + 2); events = new ArrayList<String>(Arrays.asList(s.split(" "))); for (String o : events) { // Transition t = new Transition(o, pn); o = repairTransitionString(o); Transition t = new Transition(new LogEvent(o, ""), pn); t.setIdentifier(o); pn.addTransition(t); transitions.add(t); } in.readLine(); // reading the main lines sRead = in.readLine(); sRead = sRead.replace("/", PetrifyConstants.EDGEDOCSSEPARATOR); // dot // doesn't // eat // '/' // symbols while (sRead.charAt(0) != '.') { // look for new transitions (with "__") and new places and add them // to the lists stParts = checkForNewTransitionsAndPlaces(sRead, transitions, places, pn); if (isPlace(stParts.get(0))) { Place placeFirst = findPlace(stParts.get(0), places); for (int i = 1; i < stParts.size(); i++) { String stRepaired = repairTransitionString(stParts.get(i)); Transition aTransition = findTransition(stRepaired, transitions); PNEdge newEdge = new PNEdge(placeFirst, aTransition); pn.addEdge(newEdge); } } else { String stRepaired = repairTransitionString(stParts.get(0)); Transition transitionFirst = findTransition(stRepaired, transitions); for (int i = 1; i < stParts.size(); i++) { Place aPlace = findPlace(stParts.get(i), places); PNEdge newEdge = new PNEdge(transitionFirst, aPlace); pn.addEdge(newEdge); } } sRead = in.readLine(); sRead = sRead.replace("/", PetrifyConstants.EDGEDOCSSEPARATOR); } // makeEndsBlack(transitions); // end transitions must be black addFinalPlace(places, transitions, pn); return pn; }