Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
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 org.eclipse.linuxtools.tmf.event.TmfEvent; | |
16 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
17 | ||
18 | /** | |
19 | * <b><u>TmfCoalescedEventRequest</u></b> | |
20 | * <p> | |
21 | * TODO: Implement me. Please. | |
22 | */ | |
23 | public class TmfCoalescedEventRequest<T extends TmfEvent> extends TmfCoalescedDataRequest<T> implements ITmfEventRequest<T> { | |
24 | ||
25 | // ------------------------------------------------------------------------ | |
26 | // Attributes | |
27 | // ------------------------------------------------------------------------ | |
28 | ||
29 | private final TmfTimeRange fRange; // The requested events time range | |
30 | ||
31 | // ------------------------------------------------------------------------ | |
32 | // Constructor | |
33 | // ------------------------------------------------------------------------ | |
34 | ||
35 | /** | |
36 | * @param range | |
37 | */ | |
38 | public TmfCoalescedEventRequest(Class<T> dataType) { | |
39 | this(dataType, TmfTimeRange.Eternity, ALL_DATA, DEFAULT_BLOCK_SIZE); | |
40 | } | |
41 | ||
42 | /** | |
43 | * @param range | |
44 | */ | |
45 | public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range) { | |
46 | this(dataType, range, ALL_DATA, DEFAULT_BLOCK_SIZE); | |
47 | } | |
48 | ||
49 | /** | |
50 | * @param range | |
51 | * @param nbRequested | |
52 | */ | |
53 | public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested) { | |
54 | this(dataType, range, nbRequested, DEFAULT_BLOCK_SIZE); | |
55 | } | |
56 | ||
57 | /** | |
58 | * @param range | |
59 | * @param nbRequested | |
60 | * @param blockSize Size of the largest blocks expected | |
61 | */ | |
62 | public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, int blockSize) { | |
63 | super(dataType, 0, nbRequested, blockSize); | |
64 | fRange = range; | |
65 | } | |
66 | ||
67 | // ------------------------------------------------------------------------ | |
68 | // Management | |
69 | // ------------------------------------------------------------------------ | |
70 | ||
71 | @Override | |
72 | public boolean isCompatible(ITmfDataRequest<T> request) { | |
73 | if (request instanceof ITmfEventRequest<?>) { | |
74 | boolean ok = getNbRequested() == request.getNbRequested(); | |
75 | ok &= getBlockize() == request.getBlockize(); | |
76 | ok &= fRange.equals(((ITmfEventRequest<T>) request).getRange()); | |
77 | return ok; | |
78 | } | |
79 | return false; | |
80 | } | |
81 | ||
82 | // ------------------------------------------------------------------------ | |
83 | // ITmfEventRequest | |
84 | // ------------------------------------------------------------------------ | |
85 | ||
86 | public TmfTimeRange getRange() { | |
87 | return fRange; | |
88 | } | |
89 | ||
90 | // ------------------------------------------------------------------------ | |
91 | // Object | |
92 | // ------------------------------------------------------------------------ | |
93 | ||
94 | @Override | |
95 | // All requests have a unique id | |
96 | public int hashCode() { | |
97 | return super.hashCode(); | |
98 | } | |
99 | ||
100 | @Override | |
101 | public boolean equals(Object other) { | |
102 | if (other instanceof TmfCoalescedEventRequest<?>) { | |
103 | TmfCoalescedEventRequest<?> request = (TmfCoalescedEventRequest<?>) other; | |
104 | return (request.getDataType() == getDataType()) && | |
105 | (request.getIndex() == getIndex()) && | |
106 | (request.getNbRequested() == getNbRequested()) && | |
107 | (request.getRange().equals(getRange())); | |
108 | } | |
109 | if (other instanceof TmfCoalescedDataRequest<?>) { | |
110 | return super.equals(other); | |
111 | } | |
112 | return false; | |
113 | } | |
114 | ||
115 | @Override | |
116 | public String toString() { | |
117 | return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName() | |
118 | + "," + getRange() + "," + getNbRequested() + "," + getBlockize() + ")]"; | |
119 | } | |
120 | ||
121 | } |