Commit | Line | Data |
---|---|---|
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 | 13 | package org.eclipse.linuxtools.internal.pcap.core.endpoint; |
5255c030 VP |
14 | |
15 | import org.eclipse.jdt.annotation.Nullable; | |
93d1d135 | 16 | import org.eclipse.linuxtools.internal.pcap.core.packet.Packet; |
5255c030 VP |
17 | |
18 | /** | |
19 | * Class that represents a pair of endpoints. This is used to find a packet | |
20 | * stream between to endpoints. | |
21 | * | |
22 | * @author Vincent Perot | |
23 | */ | |
24 | public class ProtocolEndpointPair { | |
25 | ||
26 | private final ProtocolEndpoint fEndpointA; | |
27 | private final ProtocolEndpoint fEndpointB; | |
28 | ||
29 | /** | |
30 | * Constructor of the class {@link ProtocolEndpointPair}. It constructs a | |
31 | * {@link ProtocolEndpointPair} object from a packet. | |
32 | * | |
33 | * @param packet | |
34 | * The packet that contains the endpoints. | |
35 | */ | |
36 | public ProtocolEndpointPair(Packet packet) { | |
37 | fEndpointA = packet.getSourceEndpoint(); | |
38 | fEndpointB = packet.getDestinationEndpoint(); | |
39 | } | |
40 | ||
41 | /** | |
42 | * Getter method that returns the first endpoint of the pair. | |
43 | * | |
44 | * @return The first endpoint. | |
45 | */ | |
46 | public ProtocolEndpoint getFirstEndpoint() { | |
47 | return fEndpointA; | |
48 | } | |
49 | ||
50 | /** | |
51 | * Getter method that returns the second endpoint of the pair. | |
52 | * | |
53 | * @return The second endpoint. | |
54 | */ | |
55 | public ProtocolEndpoint getSecondEndpoint() { | |
56 | return fEndpointB; | |
57 | } | |
58 | ||
59 | /** | |
60 | * Constructor of the class {@link ProtocolEndpointPair}. It constructs a | |
61 | * {@link ProtocolEndpointPair} object from two endpoints. | |
62 | * | |
63 | * @param endpointA | |
64 | * The first endpoint. | |
65 | * @param endpointB | |
66 | * The second endpoint. | |
67 | */ | |
68 | public ProtocolEndpointPair(ProtocolEndpoint endpointA, ProtocolEndpoint endpointB) { | |
69 | fEndpointA = endpointA; | |
70 | fEndpointB = endpointB; | |
71 | } | |
72 | ||
73 | @Override | |
74 | public int hashCode() { | |
75 | final int prime = 31; | |
76 | int result = 1; | |
77 | result = prime * result + fEndpointA.hashCode() * fEndpointB.hashCode(); | |
78 | return result; | |
79 | } | |
80 | ||
81 | @Override | |
82 | public boolean equals(@Nullable Object obj) { | |
83 | ||
84 | if (this == obj) { | |
85 | return true; | |
86 | } | |
87 | if (!(obj instanceof ProtocolEndpointPair)) { | |
88 | return false; | |
89 | } | |
90 | ProtocolEndpointPair other = (ProtocolEndpointPair) obj; | |
91 | ||
92 | return (this.fEndpointA.equals(other.fEndpointA) && this.fEndpointB.equals(other.fEndpointB)) || | |
93 | (this.fEndpointA.equals(other.fEndpointB) && this.fEndpointB.equals(other.fEndpointA)); | |
94 | } | |
95 | ||
96 | } |