Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9d17708bdd5b89db66ff57d91b8af4d30afc7d80 (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
/*******************************************************************************
 * Copyright (c) 2013 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Cedric Dumoulin - cedric.dumoulin@lifl.fr
 ******************************************************************************/
package org.eclipse.papyrus.layers.stackmodel.util;

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


/**
 * This class is used to record a list of traces.
 * Traces are for event triggered by a method.
 * This class is for tests purpose.
 * 
 * @author cedric dumoulin
 *
 */
public class TriggeredEventTraces<E>  {


	/**
	 * List of recorded events
	 */
	public List<TriggeredEvent> traces = new ArrayList<TriggeredEvent>();

	/**
	 * Clear all traces.
	 */
	public void clear() {
		traces.clear();
	}
	
	/**
	 * Add a trace to the list of traces
	 * @param name
	 * @param notification
	 */
	public void addTrace(String name, E notification) {
		traces.add(new TriggeredEvent(name, notification));
	}

	/**
	 * Return true if one of the trace has the specified name.
	 * @param name
	 * @return
	 */
	public boolean contains(String name) {
		if( name == null)
			return false;
		
		for(TriggeredEvent event : traces) {
			if(name.equals(event.name))
				return true;
		}
		return false;
	}

	/**
	 * Return true if one of the trace has the specified name.
	 * @param name Name of the event to found
	 * @return the first event with the specified name, or null if nothing is found.
	 */
	public TriggeredEvent getFirstEvent(String name) {
		if( name == null)
			return null;
		
		for(TriggeredEvent event : traces) {
			if(name.equals(event.name))
				return event;
		}
		return null;
	}


	/**
	 * A record of an event
	 *
	 */
	public class TriggeredEvent {
		public String name;
		public E notifier;
		public Object object;
		/**
		 * Constructor.
		 *
		 * @param name
		 * @param notifier
		 */
		public TriggeredEvent(String name, E notifier) {
			this.name = name;
			this.notifier = notifier;
		}
		/**
		 * Constructor.
		 *
		 * @param name
		 * @param object
		 */
		public TriggeredEvent(String name, E notifier, Object object) {
			this.name = name;
			this.notifier = notifier;
			this.object = object;
		}
		
	}


	/**
	 * Return the number of traces
	 * @return
	 */
	public int size() {
		return traces.size();
	}

	/**
	 * Get the specified trace.
	 * @param i
	 * @return
	 */
	public TriggeredEvent get(int index) {
		return traces.get(index);
	}
}

Back to the top