lttng: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.pcap.core / src / org / eclipse / linuxtools / internal / pcap / core / protocol / udp / UDPEndpoint.java
CommitLineData
5255c030
VP
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 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
12
93d1d135 13package org.eclipse.linuxtools.internal.pcap.core.protocol.udp;
5255c030
VP
14
15import org.eclipse.jdt.annotation.NonNull;
16import org.eclipse.jdt.annotation.Nullable;
93d1d135 17import org.eclipse.linuxtools.internal.pcap.core.endpoint.ProtocolEndpoint;
5255c030
VP
18
19/**
20 * Class that extends the ProtocolEndpoint class. It represents the endpoint at
21 * an UDP level.
22 *
23 * @author Vincent Perot
24 */
25public class UDPEndpoint extends ProtocolEndpoint {
26
27 private final int fPort;
28
29 /**
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
33 * endpoint to take.
34 *
35 * @param packet
36 * The packet that contains the endpoints.
37 * @param isSourceEndpoint
38 * Whether to take the source or the destination endpoint of the
39 * packet.
40 */
41 public UDPEndpoint(UDPPacket packet, boolean isSourceEndpoint) {
42 super(packet, isSourceEndpoint);
43 fPort = isSourceEndpoint ? packet.getSourcePort() : packet.getDestinationPort();
44 }
45
46 @Override
47 public int hashCode() {
48 final int prime = 31;
49 int result = 1;
50 ProtocolEndpoint endpoint = getParentEndpoint();
51 if (endpoint == null) {
52 result = 0;
53 } else {
54 result = endpoint.hashCode();
55 }
56 result = prime * result + fPort;
57 return result;
58 }
59
60 @Override
61 public boolean equals(@Nullable Object obj) {
62 if (this == obj) {
63 return true;
64 }
65 if (!(obj instanceof UDPEndpoint)) {
66 return false;
67 }
68
69 UDPEndpoint other = (UDPEndpoint) obj;
70
71 // Check on layer
72 boolean localEquals = (fPort == other.fPort);
73 if (!localEquals) {
74 return false;
75 }
76
77 // Check above layers.
78 ProtocolEndpoint endpoint = getParentEndpoint();
79 if (endpoint != null) {
80 return endpoint.equals(other.getParentEndpoint());
81 }
82 return true;
83 }
84
85 @Override
86 public String toString() {
87 ProtocolEndpoint endpoint = getParentEndpoint();
88 if (endpoint == null) {
89 @SuppressWarnings("null")
90 @NonNull String ret = String.valueOf(fPort);
91 return ret;
92 }
93 return endpoint.toString() + '/' + fPort;
94 }
95
96}
This page took 0.031813 seconds and 5 git commands to generate.