-
Notifications
You must be signed in to change notification settings - Fork 13
/
Ros2MessageTimestamp.java
85 lines (74 loc) · 2.37 KB
/
Ros2MessageTimestamp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**********************************************************************
* Copyright (c) 2022 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.tracecompass.incubator.internal.ros2.core.model.messages;
import org.eclipse.jdt.annotation.NonNull;
import com.google.common.base.Objects;
/**
* Container for ROS 2 message timestamp.
*
* Since timestamps are used to match published messages with received messages,
* we combine the timestamp with the full topic name to try to avoid collisions.
* We could still get collisions, for example if two publishers publish at the
* same exact time on the same topic, but the odds of this happening are very
* low.
*
* @author Christophe Bedard
*/
public class Ros2MessageTimestamp {
private final @NonNull Long fTimestamp;
private final @NonNull String fTopicName;
/**
* Constructor
*
* @param timestamp
* the timestamp
* @param topicName
* the topic name
*/
public Ros2MessageTimestamp(@NonNull Long timestamp, @NonNull String topicName) {
fTimestamp = timestamp;
fTopicName = topicName;
}
/**
* @return the timestamp
*/
public Long getTimestamp() {
return fTimestamp;
}
/**
* @return the topic name
*/
public String getTopicName() {
return fTopicName;
}
@Override
public int hashCode() {
return Objects.hashCode(fTimestamp, fTopicName);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Ros2MessageTimestamp o = (Ros2MessageTimestamp) obj;
return o.fTimestamp.equals(fTimestamp) && o.fTopicName.equals(fTopicName);
}
@Override
public @NonNull String toString() {
return String.format("Ros2MessageTimestamp: timestamp=%d, topicName=%s", fTimestamp, fTopicName); //$NON-NLS-1$
}
}