| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2014 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 | * Bernd Hufmann - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.tracecompass.tmf.tests.stubs.trace.text; |
| 14 | |
| 15 | import java.util.List; |
| 16 | |
| 17 | import org.eclipse.jdt.annotation.NonNull; |
| 18 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
| 19 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; |
| 20 | import org.eclipse.tracecompass.tmf.core.event.collapse.ITmfCollapsibleEvent; |
| 21 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
| 22 | import org.eclipse.tracecompass.tmf.core.trace.text.TextTraceEvent; |
| 23 | import org.eclipse.tracecompass.tmf.core.trace.text.TextTraceEventContent; |
| 24 | |
| 25 | /** |
| 26 | * System log trace implementation of TmfEvent. |
| 27 | */ |
| 28 | public class SyslogEvent extends TextTraceEvent implements ITmfCollapsibleEvent { |
| 29 | |
| 30 | /** |
| 31 | * Default constructor |
| 32 | */ |
| 33 | public SyslogEvent() { |
| 34 | super(null, null, new SyslogEventType(), null); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Copy constructor |
| 39 | * |
| 40 | * @param other |
| 41 | * the event to copy |
| 42 | * |
| 43 | */ |
| 44 | public SyslogEvent(final @NonNull SyslogEvent other) { |
| 45 | super(other); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Full Constructor |
| 50 | * |
| 51 | * @param parentTrace |
| 52 | * the parent trace |
| 53 | * @param timestamp |
| 54 | * the event timestamp |
| 55 | * @param type |
| 56 | * the event type |
| 57 | * @param content |
| 58 | * the event content (payload) |
| 59 | */ |
| 60 | public SyslogEvent(SyslogTrace parentTrace, final ITmfTimestamp timestamp, |
| 61 | final ITmfEventType type, final TextTraceEventContent content) { |
| 62 | super(parentTrace, timestamp, type, content); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean isCollapsibleWith(ITmfEvent otherEvent) { |
| 67 | if (this == otherEvent) { |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | if (!(otherEvent instanceof SyslogEvent)) { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | final SyslogEvent other = (SyslogEvent) otherEvent; |
| 76 | |
| 77 | if (!getTrace().equals(other.getTrace())) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | if (getType() == null) { |
| 82 | if (other.getType() != null) { |
| 83 | return false; |
| 84 | } |
| 85 | } else if (!getType().equals(other.getType())) { |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | TextTraceEventContent content = this.getContent(); |
| 90 | TextTraceEventContent otherContent = other.getContent(); |
| 91 | |
| 92 | if (content == null) { |
| 93 | if (otherContent != null) { |
| 94 | return false; |
| 95 | } |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | if (otherContent == null) { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | List<TextTraceEventContent> fields = content.getFields(); |
| 104 | List<TextTraceEventContent> otherFields = otherContent.getFields(); |
| 105 | int size = fields.size(); |
| 106 | |
| 107 | if (size != otherFields.size()) { |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | // At i = 0 the timestamp is stored and needs to be bypassed |
| 112 | for (int i = 1; i < size; i++) { |
| 113 | if (!fields.get(i).equals(otherFields.get(i))) { |
| 114 | return false; |
| 115 | } |
| 116 | } |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | } |