adding a test case
[IRC.git] / Robust / TransSim / Transaction.java
1 public class Transaction {
2   byte[] events;
3   int[] objects;
4   int[] indices;
5   int[] times;
6   long[] alttimes;
7   boolean started;
8
9   public String toString() {
10     String s="";
11     for(int i=0;i<numEvents();i++) {
12       if (events[i]==READ)
13         s+="Read";
14       else if(events[i]==WRITE)
15         s+="Write";
16       else 
17         s+="Delay";
18       s+=" on "+objects[i]+" at "+times[i]+"\n";
19     }
20     return s;
21   }
22
23   public static final byte READ=0;
24   public static final byte WRITE=1;
25   public static final byte BARRIER=2;
26   public static final byte DELAY=-1;
27
28   public Transaction(int size,boolean started) {
29     events=new byte[size];
30     objects=new int[size];
31     indices=new int[size];
32     times=new int[size];
33     this.started=started;
34   }
35   
36   public int numEvents() {
37     return events.length;
38   }
39
40   public byte getEvent(int index) {
41     return events[index];
42   }
43
44   public long getTime(int index) {
45     if (times!=null)
46       return times[index];
47     else
48       return alttimes[index];
49   }
50
51   public int getObject(int index) {
52     return objects[index];
53   }
54
55   public int getIndex(int index) {
56     return indices[index];
57   }
58
59   public ObjIndex getObjIndex(int index) {
60     int obj=objects[index];
61     if (obj==-1)
62       return null;
63     return new ObjIndex(obj, indices[index]);
64   }
65
66   public void setEvent(int index, byte val) {
67     events[index]=val;
68   }
69
70   public void setTime(int index, long val) {
71     if (times==null) {
72       alttimes[index]=val;
73     } else {
74       int v=(int)val;
75       if (v==val) {
76         times[index]=v;
77       } else {
78         alttimes=new long[times.length];
79         for(int i=0;i<times.length;i++)
80           alttimes[i]=times[i];
81         times=null;
82         alttimes[index]=val;
83       }
84     }
85   }
86
87   public void setObject(int index, int val) {
88     objects[index]=val;
89   }
90
91   public void setIndex(int index, int val) {
92     indices[index]=val;
93   }
94 }