-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.java
130 lines (108 loc) · 3.29 KB
/
Node.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* This file is part of lanSimulation.
*
* lanSimulation is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* lanSimulation is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with lanSimulation; if not, write to the Free Software
* Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Copyright original Java version: 2004 Bart Du Bois, Serge Demeyer
* Copyright C++ version: 2006 Matthias Rieger, Bart Van Rompaey
*/
package lanSimulation;
/**
* A <em>Node</em> represents a single Node in a Local Area Network (LAN).
* Several types of Nodes exist.
*/
public class Node {
// enumeration constants specifying all legal node types
/**
* A node with type NODE has only basic functionality.
*/
public static final byte NODE = 0;
/**
* A node with type WORKSTATION may initiate requests on the LAN.
*/
public static final byte WORKSTATION = 1;
/**
* A node with type PRINTER may accept packages to be printed.
*/
public static final byte PRINTER = 2;
/**
* Holds the type of the Node.
*/
public byte type_;
/**
* Holds the name of the Node.
*/
public String name_;
/**
* Holds the next Node in the token ring architecture.
*
* @see lanSimulation.Node
*/
public Node nextNode_;
/**
* Construct a <em>Node</em> with given #type and #name.
* <p>
* <strong>Precondition:</strong> (type >= NODE) & (type <= PRINTER);
* </p>
*/
public Node(byte type, String name) {
assert (type >= NODE) & (type <= PRINTER);
type_ = type;
name_ = name;
nextNode_ = null;
}
public Node( String name) {
name_ = name;
nextNode_ = null;
}
/**
* Construct a <em>Node</em> with given #type and #name, and which is
* linked to #nextNode.
* <p>
* <strong>Precondition:</strong> (type >= NODE) & (type <= PRINTER);
* </p>
*/
public Node(byte type, String name, Node nextNode) {
assert (type >= NODE) & (type <= PRINTER);
type_ = type;
name_ = name;
nextNode_ = nextNode;
}
public void receivePacket(Packet p){
// this will receive packet or simply
// display packet is receive
return;
}
public void sendPacket(Packet p){
// this will send packet or simply
// display packet is sent
return;
}
public boolean equals(String name){
return this.name_.equals(name);
}
public boolean equalsType(Class type){
return type.equals(Node.class);
}
public void printOn(StringBuffer buf){
buf.append("Node ");
buf.append(this.name_);
buf.append(" [Node]");
}
public void printXmlOn(StringBuffer buf){
buf.append("<node>");
buf.append(this.name_);
buf.append("</node>");
}
}