[CTF] fix support for traces with per-event contexts
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / request / TmfEventTypeFilter.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;
17
18/**
19 * An event filter base on the requested data type.
20 *
21 * @author Francois Chouinard
22 * @version 1.0
23 * @since 2.0
24 */
25public final class TmfEventTypeFilter implements ITmfFilter {
26
27 // ------------------------------------------------------------------------
28 // Constants
29 // ------------------------------------------------------------------------
30
31 /**
32 * Filter for all types of events
33 */
34 public static final TmfEventTypeFilter ALL_EVENTS = new TmfEventTypeFilter(ITmfEvent.class);
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
40 /**
41 * Event type
42 */
43 private final Class<? extends ITmfEvent> fEventType;
44
45 // ------------------------------------------------------------------------
46 // Constructors
47 // ------------------------------------------------------------------------
48
49 /**
50 * Standard constructor
51 *
52 * @param eventType the event type
53 */
54 public TmfEventTypeFilter(Class<? extends ITmfEvent> eventType) {
55 fEventType = eventType != null ? eventType : ITmfEvent.class;
56 }
57
58 /**
59 * Copy constructor
60 *
61 * @param other the other filter
62 */
63 public TmfEventTypeFilter(TmfEventTypeFilter other) {
64 fEventType = other.fEventType;
65 }
66
67 // ------------------------------------------------------------------------
68 // Getters
69 // ------------------------------------------------------------------------
70
71 /**
72 * @return the event type
73 */
74 public Class<? extends ITmfEvent> getEventType() {
75 return fEventType;
76 }
77
78 // ------------------------------------------------------------------------
79 // ITmfFilter
80 // ------------------------------------------------------------------------
81
82 /* (non-Javadoc)
83 * @see org.eclipse.linuxtools.tmf.core.filter.ITmfFilter#matches(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
84 */
85 @Override
86 public boolean matches(ITmfEvent event) {
87 return fEventType.isInstance(event);
88 }
89
90 // ------------------------------------------------------------------------
91 // Object
92 // ------------------------------------------------------------------------
93
94 /* (non-Javadoc)
95 * @see java.lang.Object#hashCode()
96 */
97 @Override
98 public int hashCode() {
99 final int prime = 31;
100 int result = 1;
101 result = prime * result + ((fEventType == null) ? 0 : fEventType.hashCode());
102 return result;
103 }
104
105 /* (non-Javadoc)
106 * @see java.lang.Object#equals(java.lang.Object)
107 */
108 @Override
109 public boolean equals(Object obj) {
110 if (this == obj) {
111 return true;
112 }
113 if (obj == null) {
114 return false;
115 }
116 if (!(obj instanceof TmfEventTypeFilter)) {
117 return false;
118 }
119 TmfEventTypeFilter other = (TmfEventTypeFilter) obj;
120 if (fEventType == null) {
121 if (other.fEventType != null) {
122 return false;
123 }
124 } else if (!fEventType.equals(other.fEventType)) {
125 return false;
126 }
127 return true;
128 }
129
130 /* (non-Javadoc)
131 * @see java.lang.Object#toString()
132 */
133 @Override
134 @SuppressWarnings("nls")
135 public String toString() {
136 return "TmfEventTypeFilter [fEventType=" + fEventType.getSimpleName() + "]";
137 }
138
139}
This page took 0.028368 seconds and 5 git commands to generate.