[290968] Contribution
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / model / trange / TimeRangeEventResource.java
CommitLineData
6e512b93
ASL
1/*******************************************************************************\r
2 * Copyright (c) 2009 Ericsson\r
3 * \r
4 * All rights reserved. This program and the accompanying materials are\r
5 * made available under the terms of the Eclipse Public License v1.0 which\r
6 * accompanies this distribution, and is available at\r
7 * http://www.eclipse.org/legal/epl-v10.html\r
8 * \r
9 * Contributors:\r
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation\r
11 *******************************************************************************/\r
12package org.eclipse.linuxtools.lttng.ui.model.trange;\r
13\r
14import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;\r
15\r
16/**\r
17 * @author alvaro\r
18 * \r
19 */\r
20public abstract class TimeRangeEventResource extends TimeRangeComposite\r
21 implements\r
22 Comparable<TimeRangeEventResource> {\r
23\r
24 // ========================================================================\r
25 // Data\r
26 // =======================================================================\r
27 public static enum ResourceTypes {\r
28 UNKNOWN, IRQ, TRAP, SOFT_IRQ, BDEV, CPU\r
29 }\r
30\r
31 private ResourceTypes type = ResourceTypes.UNKNOWN;\r
32 private Long resourceId = null;\r
33\r
34 // ========================================================================\r
35 // Constructor\r
36 // =======================================================================\r
37 /**\r
38 * Constructor<br>\r
39 * \r
40 * @param newId Id used by the UI\r
41 * @param newStartTime normally set to the Trace start time\r
42 * @param newStopTime normally set to the Trace end time\r
43 * @param newName the name of this resource\r
44 * @param newGroupName the group name of this resource. Should be same as the traceId\r
45 * @param newClassName the classname of this resource.\r
46 * @param newType the type of the resource, as defined in the ResourceTypes enum\r
47 * @param newResourceId the resourceId, unique id identifying this resource \r
48 * \r
49 */\r
50 public TimeRangeEventResource(int newId, long newStartTime,\r
51 long newStopTime, String newName, String newGroupName,\r
dfaf8391 52 String newClassName, ResourceTypes newType, Long newResourceId) {\r
6e512b93
ASL
53\r
54 super(newId, newStartTime, newStopTime, newName, newGroupName,\r
dfaf8391 55 newClassName, CompositeType.RESOURCE);\r
6e512b93
ASL
56\r
57 type = newType;\r
58 resourceId = newResourceId;\r
59 }\r
60\r
61 // ========================================================================\r
62 // Methods\r
63 // =======================================================================\r
64\r
65 /**\r
66 * Interface to add children to this resource\r
67 * \r
68 * @param newEvent\r
69 */\r
70 public void addChildren(TimeRangeEvent newEvent) {\r
71 if ((newEvent != null)) {\r
72 this.ChildEventLeafs.add(newEvent);\r
73 }\r
74 }\r
75\r
76 /**\r
77 * @return\r
78 */\r
79 public Long getResourceId() {\r
80 return resourceId;\r
81 }\r
82\r
83 /**\r
84 * @param newResId\r
85 */\r
86 public void setResourceId(Long newResId) {\r
87 this.resourceId = newResId;\r
88 }\r
89\r
90 /**\r
91 * @return\r
92 */\r
93 public ResourceTypes getType() {\r
94 return type;\r
95 }\r
96\r
97 /**\r
98 * @param type\r
99 */\r
100 public void setType(ResourceTypes type) {\r
101 this.type = type;\r
102 }\r
103\r
104 /**\r
105 * Getter for traceId.<br>\r
106 * Note : traceId and groupName are the same for EventResource\r
107 * \r
108 * @return String\r
109 */\r
110 public String getTraceId() {\r
111 return groupName;\r
112 }\r
113\r
114 /**\r
115 * Getter for traceId.<br>\r
116 * Note : traceId and groupName are the same for EventResource\r
117 * \r
118 * @return String\r
119 */\r
120 public void setTraceId(String traceId) {\r
121 this.groupName = traceId;\r
122 }\r
123\r
124 // @Override\r
125 /*\r
126 * (non-Javadoc)\r
127 * \r
128 * @see java.lang.Object#toString()\r
129 */\r
130 @Override\r
131 public String toString() {\r
132 return getResourceId().toString() + ":" + getTraceId().toString() + ":"\r
133 + getType().toString();\r
134 }\r
135\r
136 /**\r
137 * Compare function to implement Comparable<br>\r
138 * <br>\r
139 * Compare by traceId THEN IF EQUAL by resourceType THEN IF EQUAL by\r
140 * resourceId\r
141 * \r
142 * @param comparedResource\r
143 * The resource to compare to\r
144 * \r
145 * @return int 0 if equals, negative number if "smaller", positive if\r
146 * "bigger".\r
147 */\r
148 // @Override\r
149 public int compareTo(TimeRangeEventResource comparedResource) {\r
150 int returnedValue = 0;\r
151\r
152 if (comparedResource != null) {\r
153 // Compare by trace id first\r
154 returnedValue = this.getTraceId().compareTo(\r
155 comparedResource.getTraceId());\r
156\r
157 // If same, compare by resourceName\r
158 if (returnedValue == 0) {\r
159 returnedValue = this.getName().compareTo(\r
160 comparedResource.getName());\r
161\r
162 // Finally, if same, compare by ResourceId\r
163 if (returnedValue == 0) {\r
164 returnedValue = this.getResourceId().compareTo(\r
165 comparedResource.getResourceId());\r
166 }\r
167 }\r
168\r
169 }\r
170\r
171 return returnedValue;\r
172 }\r
173\r
174 public abstract String getStateMode(LttngTraceState traceState);\r
175}\r
This page took 0.038892 seconds and 5 git commands to generate.