[CTF] fix support for traces with per-event contexts
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / request / TmfBlockFilter.java
CommitLineData
8584dc20
FC
1/*******************************************************************************
2 * Copyright (c) 2012 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
13package org.eclipse.linuxtools.tmf.core.request;
14
15import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
16import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
17import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
18
19/**
20 * An event filter based on the requested event block (start event index +
21 * number of requested events).
22 *
23 * @author Francois Chouinard
24 * @version 1.0
25 * @since 2.0
26 */
27public final class TmfBlockFilter implements ITmfFilter {
28
29 // ------------------------------------------------------------------------
30 // Constants
31 // ------------------------------------------------------------------------
32
33 /**
34 * Filter for all events by index
35 */
36 public static final TmfBlockFilter ALL_EVENTS = new TmfBlockFilter(0, Long.MAX_VALUE);
37
38 // ------------------------------------------------------------------------
39 // Attributes
40 // ------------------------------------------------------------------------
41
42 /**
43 * Request start index
44 */
45 private final long fStartIndex;
46
47 /**
48 * Request end index (non-inclusive)
49 */
50 private final long fEndIndex;
51
52 /**
53 * Number of events requested
54 */
55 private final long fNbRequested;
56
57 // ------------------------------------------------------------------------
58 // Constructors
59 // ------------------------------------------------------------------------
60
61 /**
62 * Standard constructor
63 *
64 * @param startIndex start index
65 * @param nbRequested nb requested events
66 */
67 public TmfBlockFilter(long startIndex, long nbRequested) {
68 fStartIndex = startIndex >= 0 ? startIndex : 0;
69 fNbRequested = nbRequested >= 0 ? nbRequested : Long.MAX_VALUE;
70 fEndIndex = (Long.MAX_VALUE - fNbRequested) > fStartIndex ? fStartIndex + nbRequested : Long.MAX_VALUE;
71 }
72
73 /**
74 * Copy constructor
75 *
76 * @param other the other filter
77 */
78 public TmfBlockFilter(TmfBlockFilter other) {
79 fStartIndex = other.fStartIndex;
80 fEndIndex = other.fEndIndex;
81 fNbRequested = other.fNbRequested;
82 }
83
84 // ------------------------------------------------------------------------
85 // Getters
86 // ------------------------------------------------------------------------
87
88 /**
89 * @return the filter start index
90 */
91 public long getStartIndex() {
92 return fStartIndex;
93 }
94
95 /**
96 * @return the filter end index (non-inclusive)
97 */
98 public long getEndIndex() {
99 return fEndIndex;
100 }
101
102 /**
103 * @return the filter number of events requested
104 */
105 public long getNbRequested() {
106 return fNbRequested;
107 }
108
109 // ------------------------------------------------------------------------
110 // ITmfFilter
111 // ------------------------------------------------------------------------
112
113 /* (non-Javadoc)
114 * @see org.eclipse.linuxtools.tmf.core.filter.ITmfFilter#matches(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
115 */
116 @Override
117 public boolean matches(ITmfEvent event) {
118 long rank = event.getRank();
119 return ((rank == ITmfContext.UNKNOWN_RANK) || (rank >= fStartIndex && rank < (fStartIndex + fNbRequested)));
120 }
121
122 // ------------------------------------------------------------------------
123 // Object
124 // ------------------------------------------------------------------------
125
126 /* (non-Javadoc)
127 * @see java.lang.Object#hashCode()
128 */
129 @Override
130 public int hashCode() {
131 final int prime = 31;
132 int result = 1;
133 result = prime * result + (int) (fEndIndex ^ (fEndIndex >>> 32));
134 result = prime * result + (int) (fNbRequested ^ (fNbRequested >>> 32));
135 result = prime * result + (int) (fStartIndex ^ (fStartIndex >>> 32));
136 return result;
137 }
138
139 /* (non-Javadoc)
140 * @see java.lang.Object#equals(java.lang.Object)
141 */
142 @Override
143 public boolean equals(Object obj) {
144 if (this == obj) {
145 return true;
146 }
147 if (obj == null) {
148 return false;
149 }
150 if (!(obj instanceof TmfBlockFilter)) {
151 return false;
152 }
153 TmfBlockFilter other = (TmfBlockFilter) obj;
154 if (fEndIndex != other.fEndIndex) {
155 return false;
156 }
157 if (fNbRequested != other.fNbRequested) {
158 return false;
159 }
160 if (fStartIndex != other.fStartIndex) {
161 return false;
162 }
163 return true;
164 }
165
166 /* (non-Javadoc)
167 * @see java.lang.Object#toString()
168 */
169 @Override
170 @SuppressWarnings("nls")
171 public String toString() {
172 return "TmfBlockFilter [fStartIndex=" + fStartIndex + ", fEndIndex=" + fEndIndex + ", fNbRequested=" + fNbRequested + "]";
173 }
174
175}
This page took 0.030681 seconds and 5 git commands to generate.