Commit | Line | Data |
---|---|---|
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 | ||
13 | package org.eclipse.linuxtools.tmf.core.request; | |
14 | ||
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; | |
18 | ||
19 | /** | |
20 | * An event filter based on the requested time range. | |
21 | * | |
22 | * @author Francois Chouinard | |
23 | * @version 1.0 | |
24 | * @since 2.0 | |
25 | */ | |
26 | public final class TmfRangeFilter implements ITmfFilter { | |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Constants | |
30 | // ------------------------------------------------------------------------ | |
31 | ||
32 | /** | |
33 | * Filter for all events by time range | |
34 | */ | |
35 | public static final TmfRangeFilter ALL_EVENTS = new TmfRangeFilter(TmfTimeRange.ETERNITY); | |
36 | ||
37 | // ------------------------------------------------------------------------ | |
38 | // Attributes | |
39 | // ------------------------------------------------------------------------ | |
40 | ||
41 | /** The time range requested */ | |
42 | private final TmfTimeRange fTimeRange; | |
43 | ||
44 | // ------------------------------------------------------------------------ | |
45 | // Constructors | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
48 | /** | |
49 | * Standard constructor | |
50 | * | |
51 | * @param timeRange the time range of interest | |
52 | */ | |
53 | public TmfRangeFilter(TmfTimeRange timeRange) { | |
54 | fTimeRange = timeRange != null ? timeRange : TmfTimeRange.ETERNITY; | |
55 | } | |
56 | ||
57 | /** | |
58 | * Copy constructor | |
59 | * | |
60 | * @param other the other filter | |
61 | */ | |
62 | public TmfRangeFilter(TmfRangeFilter other) { | |
63 | fTimeRange = other.fTimeRange; | |
64 | } | |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // Getters | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
70 | /** | |
71 | * @return the filter time range | |
72 | */ | |
73 | public TmfTimeRange getTimeRange() { | |
74 | return fTimeRange; | |
75 | } | |
76 | ||
77 | // ------------------------------------------------------------------------ | |
78 | // ITmfFilter | |
79 | // ------------------------------------------------------------------------ | |
80 | ||
81 | /* (non-Javadoc) | |
82 | * @see org.eclipse.linuxtools.tmf.core.filter.ITmfFilter#matches(org.eclipse.linuxtools.tmf.core.event.ITmfEvent) | |
83 | */ | |
84 | @Override | |
85 | public boolean matches(ITmfEvent event) { | |
86 | return fTimeRange.contains(event.getTimestamp()); | |
87 | } | |
88 | ||
89 | // ------------------------------------------------------------------------ | |
90 | // Object | |
91 | // ------------------------------------------------------------------------ | |
92 | ||
93 | @Override | |
94 | public int hashCode() { | |
95 | final int prime = 31; | |
96 | int result = 1; | |
97 | result = prime * result + ((fTimeRange == null) ? 0 : fTimeRange.hashCode()); | |
98 | return result; | |
99 | } | |
100 | ||
101 | @Override | |
102 | public boolean equals(Object obj) { | |
103 | if (this == obj) { | |
104 | return true; | |
105 | } | |
106 | if (obj == null) { | |
107 | return false; | |
108 | } | |
109 | if (!(obj instanceof TmfRangeFilter)) { | |
110 | return false; | |
111 | } | |
112 | TmfRangeFilter other = (TmfRangeFilter) obj; | |
113 | if (fTimeRange == null) { | |
114 | if (other.fTimeRange != null) { | |
115 | return false; | |
116 | } | |
117 | } else if (!fTimeRange.equals(other.fTimeRange)) { | |
118 | return false; | |
119 | } | |
120 | return true; | |
121 | } | |
122 | ||
123 | @Override | |
124 | @SuppressWarnings("nls") | |
125 | public String toString() { | |
126 | return "TmfRangeFilter [fTimeRange=" + fTimeRange + "]"; | |
127 | } | |
128 | ||
129 | } |