Mercurial > hg > Members > kono > jpf-core
changeset 9:8de43b2b023f
added choice getters for EventChoiceGenerator
added some minor Event functions
author | Peter Mehlitz <Peter.C.Mehlitz@nasa.gov> |
---|---|
date | Fri, 13 Feb 2015 20:20:15 -0800 |
parents | 54b7125309a9 |
children | 87e9c7544a06 |
files | src/main/gov/nasa/jpf/util/event/Event.java src/main/gov/nasa/jpf/util/event/EventChoiceGenerator.java |
diffstat | 2 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/gov/nasa/jpf/util/event/Event.java Wed Feb 11 19:16:10 2015 -0800 +++ b/src/main/gov/nasa/jpf/util/event/Event.java Fri Feb 13 20:20:15 2015 -0800 @@ -182,6 +182,20 @@ return n; } + public boolean hasAlternatives(){ + return (alt != null); + } + + public List<Event> getAlternatives(){ + List<Event> list = new ArrayList<Event>(); + list.add(this); + for (Event e = alt; e != null; e = e.alt) { + list.add(e); + } + return list; + } + + public Event unlinkedClone(){ try { Event e = (Event)super.clone();
--- a/src/main/gov/nasa/jpf/util/event/EventChoiceGenerator.java Wed Feb 11 19:16:10 2015 -0800 +++ b/src/main/gov/nasa/jpf/util/event/EventChoiceGenerator.java Fri Feb 13 20:20:15 2015 -0800 @@ -207,4 +207,44 @@ public Class<Event> getChoiceType() { return Event.class; } + + protected Event[] getFirstNChoices(int n){ + Event[] a = new Event[n]; + + Event e = base; + for (int i=0; i<n; i++){ + a[i] = e; + e = e.getAlt(); + } + + return a; + } + + @Override + public Event[] getAllChoices(){ + return getFirstNChoices( getTotalNumberOfChoices()); + } + + @Override + public Event[] getProcessedChoices(){ + return getFirstNChoices( getProcessedNumberOfChoices()); + } + + @Override + public Event[] getUnprocessedChoices(){ + int n=0; + for (Event e=cur; e != null; e = e.getAlt()){ + n++; + } + + Event[] a = new Event[n]; + + Event e = cur; + for (int i=0; i<n; i++){ + a[i] = e; + e = e.getAlt(); + } + + return a; + } }