1 /*******************************************************************************
2 * Copyright (c) 2014 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 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.pcap
.core
.protocol
.udp
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.internal
.pcap
.core
.endpoint
.ProtocolEndpoint
;
21 * Class that extends the ProtocolEndpoint class. It represents the endpoint at
24 * @author Vincent Perot
26 public class UDPEndpoint
extends ProtocolEndpoint
{
28 private final int fPort
;
31 * Constructor of the {@link UDPEndpoint} class. It takes a packet to get
32 * its endpoint. Since every packet has two endpoints (source and
33 * destination), the isSourceEndpoint parameter is used to specify which
37 * The packet that contains the endpoints.
38 * @param isSourceEndpoint
39 * Whether to take the source or the destination endpoint of the
42 public UDPEndpoint(UDPPacket packet
, boolean isSourceEndpoint
) {
43 super(packet
, isSourceEndpoint
);
44 fPort
= isSourceEndpoint ? packet
.getSourcePort() : packet
.getDestinationPort();
48 public int hashCode() {
51 ProtocolEndpoint endpoint
= getParentEndpoint();
52 if (endpoint
== null) {
55 result
= endpoint
.hashCode();
57 result
= prime
* result
+ fPort
;
62 public boolean equals(@Nullable Object obj
) {
66 if (!(obj
instanceof UDPEndpoint
)) {
70 UDPEndpoint other
= (UDPEndpoint
) obj
;
73 boolean localEquals
= (fPort
== other
.fPort
);
78 // Check above layers.
79 ProtocolEndpoint endpoint
= getParentEndpoint();
80 if (endpoint
!= null) {
81 return endpoint
.equals(other
.getParentEndpoint());
87 public String
toString() {
88 ProtocolEndpoint endpoint
= getParentEndpoint();
89 if (endpoint
== null) {
90 return checkNotNull(String
.valueOf(fPort
));
92 return endpoint
.toString() + '/' + fPort
;