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 java
.util
.Arrays
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.ITmfFilter
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
22 * An event filter based on the event's trace.
24 * @author Francois Chouinard
28 public final class TmfTraceFilter
implements ITmfFilter
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
35 * Filter for all events by time range
37 public static final TmfTraceFilter ALL_TRACES
= new TmfTraceFilter(new ITmfTrace
[0]);
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 /** The traces of interest */
44 private final ITmfTrace
[] fTraces
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
53 public TmfTraceFilter() {
58 * Standard constructor
60 * @param traces the traces of interest
62 public TmfTraceFilter(ITmfTrace
[] traces
) {
69 * @param other the other filter
71 public TmfTraceFilter(TmfTraceFilter other
) {
72 fTraces
= other
.fTraces
;
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
80 * @return the filter traces
82 public ITmfTrace
[] getTraces() {
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
91 * @see org.eclipse.linuxtools.tmf.core.filter.ITmfFilter#matches(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
94 public boolean matches(ITmfEvent event
) {
95 // The empty set is the universal element
96 if (fTraces
.length
== 0) {
99 for (ITmfTrace trace
: fTraces
) {
100 if (event
.getTrace() == trace
) {
107 // ------------------------------------------------------------------------
109 // ------------------------------------------------------------------------
112 public int hashCode() {
113 final int prime
= 31;
115 result
= prime
* result
+ Arrays
.hashCode(fTraces
);
120 public boolean equals(Object obj
) {
127 if (!(obj
instanceof TmfTraceFilter
)) {
130 TmfTraceFilter other
= (TmfTraceFilter
) obj
;
131 if (!Arrays
.equals(fTraces
, other
.fTraces
)) {
138 @SuppressWarnings("nls")
139 public String
toString() {
140 return "TmfTraceFilter [fTraces=" + Arrays
.toString(fTraces
) + "]";