Remove unneeded checkNotNull() calls
[deliverable/tracecompass.git] / pcap / org.eclipse.tracecompass.pcap.core / src / org / eclipse / tracecompass / internal / pcap / core / protocol / tcp / TCPEndpoint.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
71f2817f 13package org.eclipse.tracecompass.internal.pcap.core.protocol.tcp;
5255c030 14
5255c030 15import org.eclipse.jdt.annotation.Nullable;
71f2817f 16import org.eclipse.tracecompass.internal.pcap.core.endpoint.ProtocolEndpoint;
5255c030
VP
17
18/**
19 * Class that extends the {@link ProtocolEndpoint} class. It represents the
20 * endpoint at a TCP level.
21 *
22 * @author Vincent Perot
23 */
24public class TCPEndpoint extends ProtocolEndpoint {
25
26 private final int fPort;
27
28 /**
29 * Constructor of the {@link TCPEndpoint} class. It takes a packet to get
30 * its endpoint. Since every packet has two endpoints (source and
31 * destination), the isSourceEndpoint parameter is used to specify which
32 * endpoint to take.
33 *
34 * @param packet
35 * The packet that contains the endpoints.
36 * @param isSourceEndpoint
37 * Whether to take the source or the destination endpoint of the
38 * packet.
39 */
40 public TCPEndpoint(TCPPacket packet, boolean isSourceEndpoint) {
41 super(packet, isSourceEndpoint);
42 fPort = isSourceEndpoint ? packet.getSourcePort() : packet.getDestinationPort();
43 }
44
45 @Override
46 public int hashCode() {
47 final int prime = 31;
48 int result = 1;
49 ProtocolEndpoint endpoint = getParentEndpoint();
50 if (endpoint == null) {
51 result = 0;
52 } else {
53 result = endpoint.hashCode();
54 }
55 result = prime * result + fPort;
56 return result;
57 }
58
59 @Override
60 public boolean equals(@Nullable Object obj) {
61 if (this == obj) {
62 return true;
63 }
64 if (!(obj instanceof TCPEndpoint)) {
65 return false;
66 }
67
68 TCPEndpoint other = (TCPEndpoint) obj;
69
70 // Check on layer
71 boolean localEquals = (fPort == other.fPort);
72 if (!localEquals) {
73 return false;
74 }
75
76 // Check above layers.
77 ProtocolEndpoint endpoint = getParentEndpoint();
78 if (endpoint != null) {
79 return endpoint.equals(other.getParentEndpoint());
80 }
81 return true;
82 }
83
84 @Override
85 public String toString() {
86 ProtocolEndpoint endpoint = getParentEndpoint();
87 if (endpoint == null) {
0e4f957e 88 return String.valueOf(fPort);
5255c030
VP
89 }
90 return endpoint.toString() + '/' + fPort;
91 }
92
93}
This page took 0.051967 seconds and 5 git commands to generate.