1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.request
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.ITmfFilter
;
20 * An event filter based on the requested time range.
22 * @author Francois Chouinard
26 public final class TmfRangeFilter
implements ITmfFilter
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
33 * Filter for all events by time range
35 public static final TmfRangeFilter ALL_EVENTS
= new TmfRangeFilter(TmfTimeRange
.ETERNITY
);
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 /** The time range requested */
42 private final TmfTimeRange fTimeRange
;
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
49 * Standard constructor
51 * @param timeRange the time range of interest
53 public TmfRangeFilter(TmfTimeRange timeRange
) {
54 fTimeRange
= timeRange
!= null ? timeRange
: TmfTimeRange
.ETERNITY
;
60 * @param other the other filter
62 public TmfRangeFilter(TmfRangeFilter other
) {
63 fTimeRange
= other
.fTimeRange
;
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
71 * @return the filter time range
73 public TmfTimeRange
getTimeRange() {
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 * @see org.eclipse.linuxtools.tmf.core.filter.ITmfFilter#matches(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
85 public boolean matches(ITmfEvent event
) {
86 return fTimeRange
.contains(event
.getTimestamp());
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
94 public int hashCode() {
97 result
= prime
* result
+ ((fTimeRange
== null) ?
0 : fTimeRange
.hashCode());
102 public boolean equals(Object obj
) {
109 if (!(obj
instanceof TmfRangeFilter
)) {
112 TmfRangeFilter other
= (TmfRangeFilter
) obj
;
113 if (fTimeRange
== null) {
114 if (other
.fTimeRange
!= null) {
117 } else if (!fTimeRange
.equals(other
.fTimeRange
)) {
124 @SuppressWarnings("nls")
125 public String
toString() {
126 return "TmfRangeFilter [fTimeRange=" + fTimeRange
+ "]";