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
.linuxtools
.pcap
.core
.protocol
.udp
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.linuxtools
.pcap
.core
.endpoint
.ProtocolEndpoint
;
20 * Class that extends the ProtocolEndpoint class. It represents the endpoint at
23 * @author Vincent Perot
25 public class UDPEndpoint
extends ProtocolEndpoint
{
27 private final int fPort
;
30 * Constructor of the {@link UDPEndpoint} class. It takes a packet to get
31 * its endpoint. Since every packet has two endpoints (source and
32 * destination), the isSourceEndpoint parameter is used to specify which
36 * The packet that contains the endpoints.
37 * @param isSourceEndpoint
38 * Whether to take the source or the destination endpoint of the
41 public UDPEndpoint(UDPPacket packet
, boolean isSourceEndpoint
) {
42 super(packet
, isSourceEndpoint
);
43 fPort
= isSourceEndpoint ? packet
.getSourcePort() : packet
.getDestinationPort();
47 public int hashCode() {
50 ProtocolEndpoint endpoint
= getParentEndpoint();
51 if (endpoint
== null) {
54 result
= endpoint
.hashCode();
56 result
= prime
* result
+ fPort
;
61 public boolean equals(@Nullable Object obj
) {
65 if (!(obj
instanceof UDPEndpoint
)) {
69 UDPEndpoint other
= (UDPEndpoint
) obj
;
72 boolean localEquals
= (fPort
== other
.fPort
);
77 // Check above layers.
78 ProtocolEndpoint endpoint
= getParentEndpoint();
79 if (endpoint
!= null) {
80 return endpoint
.equals(other
.getParentEndpoint());
86 public String
toString() {
87 ProtocolEndpoint endpoint
= getParentEndpoint();
88 if (endpoint
== null) {
89 @SuppressWarnings("null")
90 @NonNull String ret
= String
.valueOf(fPort
);
93 return endpoint
.toString() + '/' + fPort
;