(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / request / TmfCoalescedDataRequest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.request;
14
15 import java.util.Vector;
16
17 import org.eclipse.linuxtools.tmf.event.TmfData;
18
19 /**
20 * <b><u>TmfCoalescedDataRequest</u></b>
21 * <p>
22 * TODO: Implement me. Please.
23 */
24 public class TmfCoalescedDataRequest<T extends TmfData> extends TmfDataRequest<T> {
25
26 // ------------------------------------------------------------------------
27 // Attributes
28 // ------------------------------------------------------------------------
29
30 protected Vector<ITmfDataRequest<T>> fRequests = new Vector<ITmfDataRequest<T>>();
31
32 // ------------------------------------------------------------------------
33 // Constructor
34 // ------------------------------------------------------------------------
35
36 /**
37 * Default constructor
38 */
39 public TmfCoalescedDataRequest(Class<T> dataType) {
40 this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE);
41 }
42
43 /**
44 * @param nbRequested
45 */
46 public TmfCoalescedDataRequest(Class<T> dataType, int index) {
47 this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE);
48 }
49
50 /**
51 * @param index
52 * @param nbRequested
53 */
54 public TmfCoalescedDataRequest(Class<T> dataType, int index, int nbRequested) {
55 this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE);
56 }
57
58 /**
59 * @param index
60 * @param nbRequested
61 * @param blockSize
62 */
63 public TmfCoalescedDataRequest(Class<T> dataType, int index, int nbRequested, int blockSize) {
64 super(dataType, index, nbRequested, blockSize);
65 }
66
67 // ------------------------------------------------------------------------
68 // Management
69 // ------------------------------------------------------------------------
70
71 public void addRequest(ITmfDataRequest<T> request) {
72 fRequests.add(request);
73 }
74
75 public boolean isCompatible(ITmfDataRequest<T> request) {
76
77 boolean ok = request.getIndex() == getIndex();
78 ok &= request.getNbRequested() == getNbRequested();
79 ok &= request.getBlockize() == getBlockize();
80
81 return ok;
82 }
83
84 // ------------------------------------------------------------------------
85 // ITmfDataRequest
86 // ------------------------------------------------------------------------
87
88 @Override
89 public void handleData() {
90 for (ITmfDataRequest<T> request : fRequests) {
91 request.setData(getData());
92 request.handleData();
93 }
94 }
95
96 @Override
97 public void done() {
98 for (ITmfDataRequest<T> request : fRequests) {
99 request.done();
100 }
101 super.done();
102 }
103
104 @Override
105 public void fail() {
106 for (ITmfDataRequest<T> request : fRequests) {
107 request.fail();
108 }
109 super.fail();
110 }
111
112 @Override
113 public void cancel() {
114 for (ITmfDataRequest<T> request : fRequests) {
115 request.cancel();
116 }
117 super.cancel();
118 }
119
120 // ------------------------------------------------------------------------
121 // Object
122 // ------------------------------------------------------------------------
123
124 @Override
125 // All requests have a unique id
126 public int hashCode() {
127 return super.hashCode();
128 }
129
130 @Override
131 public boolean equals(Object other) {
132 if (other instanceof TmfCoalescedDataRequest<?>) {
133 TmfCoalescedDataRequest<?> request = (TmfCoalescedDataRequest<?>) other;
134 return (request.getDataType() == getDataType()) &&
135 (request.getIndex() == getIndex()) &&
136 (request.getNbRequested() == getNbRequested());
137 }
138 return false;
139 }
140
141 @Override
142 public String toString() {
143 return "[TmfCoalescedDataRequest(" + getRequestId() + "," + getDataType().getSimpleName()
144 + "," + getIndex() + "," + getNbRequested() + "," + getBlockize() + ")]";
145 }
146
147 }
This page took 0.033906 seconds and 5 git commands to generate.