Source code: hsr/ipm/storing/Hop.java
1 package hsr.ipm.storing;
2
3
4 import java.util.Enumeration;
5 import java.util.Vector;
6
7
8 /*
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24
25 /**
26 * Represents a Hop in a traceroute
27 *
28 * @author Christian Niklaus
29 * @author Daniel Kamm
30 * @version 1.0
31 */
32 public class Hop {
33
34 private long id;
35 private Host responseHost;
36 private Vector rtts;
37
38 public Hop() {
39 rtts = new Vector();
40 responseHost = new Host();
41 }
42
43
44 /**
45 * Sets the the ResponseHostattribute
46 */
47 public void setResponseHost(Host aHost) {
48 responseHost = aHost;
49 }
50
51 /**
52 * Gets the ResponseHostattribute
53 */
54 public Host getResponseHost() {
55 return responseHost;
56 }
57
58 /**
59 * Adds a Rtt to a Hop
60 */
61 public void addRtt(Float aRtt) {
62 rtts.addElement(aRtt);
63 }
64
65 public String toString() {
66 StringBuffer hop = new StringBuffer();
67 Enumeration enum = rtts.elements();
68 Float rtt = null;
69
70 hop.append(responseHost.toString() + " ");
71 while (enum.hasMoreElements()) {
72 rtt = (Float) enum.nextElement();
73 hop.append(rtt + "ms ");
74 }
75 return hop.toString();
76 }
77
78 /**
79 * Returns all Rtts from a Hop
80 */
81 public Vector getRTTS() {
82 return rtts;
83 }
84
85
86 /**
87 * Gets the Id
88 */
89 public long getId() {
90 return id;
91 }
92
93 /**
94 * Sets the Id
95 */
96 public void setId(long id) {
97 this.id = id;
98 }
99
100
101 public static void main(String[] args) {
102 Hop hop1 = new Hop();
103 hop1.addRtt(new Float(0.222));
104 hop1.addRtt(new Float(0.333));
105 hop1.addRtt(new Float(0.444));
106 System.out.println(hop1.toString());
107 }
108 }