tmf: Initial commit of Pcap Parser
[deliverable/tracecompass.git] / org.eclipse.linuxtools.pcap.core / src / org / eclipse / linuxtools / pcap / core / packet / PacketUniqueID.java
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
13 package org.eclipse.linuxtools.pcap.core.packet;
14
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.eclipse.linuxtools.pcap.core.packet.Packet;
17 import org.eclipse.linuxtools.pcap.core.protocol.Protocol;
18 import org.eclipse.linuxtools.pcap.core.protocol.pcap.PcapPacket;
19
20 /**
21 * Class that represents a Packet ID. Using the information contained in this
22 * class, it is possible to retrieve a packet. This allows to tremendously
23 * reduce memory usage of packet streams while keeping good performance.
24 *
25 * @author Vincent Perot
26 */
27 public class PacketUniqueID {
28
29 private final String fPath;
30 private final long fIndex;
31
32 /**
33 * Constructor. It builds the packet ID from a packet.
34 *
35 * @param packet
36 * The packet to build the ID from.
37 */
38 public PacketUniqueID(Packet packet) {
39 fPath = packet.getPcapFile().getPath();
40 PcapPacket pcapPacket = (PcapPacket) packet.getPacket(Protocol.PCAP);
41 fIndex = (pcapPacket == null ? -1 : pcapPacket.getIndex());
42 }
43
44 /**
45 * Getter method that returns the file path of the packet.
46 *
47 * @return The file path.
48 */
49 public String getPath() {
50 return fPath;
51 }
52
53 /**
54 * Getter method that returns the index within the file of the packet.
55 *
56 * @return The packet index.
57 */
58 public long getIndex() {
59 return fIndex;
60 }
61
62 @Override
63 public int hashCode() {
64 final int prime = 31;
65 int result = 1;
66 result = prime * result + (int) (fIndex ^ (fIndex >>> 32));
67 result = prime * result + fPath.hashCode();
68 return result;
69 }
70
71 @Override
72 public boolean equals(@Nullable Object obj) {
73 if (this == obj) {
74 return true;
75 }
76 if (obj == null) {
77 return false;
78 }
79 if (getClass() != obj.getClass()) {
80 return false;
81 }
82
83 PacketUniqueID other = (PacketUniqueID) obj;
84 if (fIndex != other.fIndex) {
85 return false;
86 }
87 if (fPath != other.fPath) {
88 return false;
89 }
90 return true;
91 }
92
93 }
This page took 0.033623 seconds and 5 git commands to generate.