Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 748ffe09a689c1d76046bb3fcd1455e27480e752 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**
 *
 */
package org.eclipse.papyrus.infra.core.serviceregistry;

import java.util.ArrayList;
import java.util.List;


/**
 * A class used to record traces for tests
 *
 * @author cedric dumoulin
 *
 */
public class TestTrace {

	public List<TraceRecord> traces = new ArrayList<TraceRecord>();

	/**
	 * Record a new trace.
	 *
	 * @param trace
	 */
	public void addTrace(String trace) {
		addTrace(null, trace, null);
	}

	/**
	 * Record a new trace.
	 *
	 * @param trace
	 */
	public void addTrace(String name, String trace) {
		addTrace(name, trace, null);
	}

	/**
	 * Record a new trace.
	 *
	 * @param trace
	 */
	public void addTrace(String name, String trace, Object value) {
		traces.add(new TraceRecord(name, trace, value));
	}

	/**
	 * Return the name and the trace in one concatenated string ("name,trace").
	 *
	 * @param i
	 *            Index of the requested trace
	 * @return
	 */
	public String getNameTrace(int i) {
		return traces.get(i).getNameTrace();
	}

	/**
	 * Get the value
	 *
	 * @param i
	 * @return
	 */
	public Object getValue(int i) {
		return traces.get(i).value;
	}

	/**
	 * Return true if the trace contains the specified events.
	 *
	 * @return
	 */
	public boolean contains(String name, String trace) {

		return indexOfNameTrace(name, trace) >= 0;
	}

	/**
	 * Returns the index of the first occurrence of the specified elements
	 * in these lists, or -1 if this list does not contain the element.
	 */
	public int indexOf(String name, String trace, Object value) {

		for (int i = 0; i < traces.size(); i++) {
			TraceRecord record = traces.get(i);

			if (name.equals(record.name) && trace.equals(record.trace)) {
				return i;
			}
		}

		return -1;
	}

	/**
	 * Returns the index of the first occurrence of the specified elements
	 * in these lists, or -1 if this list does not contain the element.
	 */
	public int indexOfNameTrace(String name, String trace) {

		for (int i = 0; i < traces.size(); i++) {
			TraceRecord record = traces.get(i);

			if (name.equals(record.name) && trace.equals(record.trace)) {
				return i;
			}
		}

		return -1;
	}

	/**
	 * Returns the index of the first occurrence of the specified elements
	 * in these lists, or -1 if this list does not contain the element.
	 */
	public int indexOfTrace(String trace) {

		for (int i = 0; i < traces.size(); i++) {
			TraceRecord record = traces.get(i);

			if (trace.equals(record.trace)) {
				return i;
			}
		}

		return -1;
	}

	/**
	 * Returns the index of the first occurrence of the specified elements
	 * in these lists, or -1 if this list does not contain the element.
	 */
	public int indexOfName(String name) {

		for (int i = 0; i < traces.size(); i++) {
			TraceRecord record = traces.get(i);

			if (name.equals(record.name)) {
				return i;
			}
		}

		return -1;
	}

	/**
	 * Reset the trace.
	 */
	public void reset() {
		traces.clear();
	}


	/**
	 * @return the traces
	 */
	public List<TraceRecord> getTraces() {
		return traces;
	}

	/**
	 * A Record of the trace.
	 */
	public class TraceRecord {
		public String name;
		public String trace;
		public Object value;

		/**
		 * Constructor.
		 *
		 * @param name
		 * @param trace
		 * @param value
		 */
		public TraceRecord(String name, String trace, Object value) {
			this.name = name;
			this.trace = trace;
			this.value = value;
		}

		/**
		 *
		 * @return
		 */
		public String getNameTrace() {
			// TODO Auto-generated method stub
			return name + "," + trace;
		}

	}

}

Back to the top