forked from MattWoelk/DirectedDiffusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDReceive.java
108 lines (87 loc) · 2.2 KB
/
EDReceive.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
import java.util.ArrayList;
import java.util.Calendar.*;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
public class EDReceive
{
List<Sender> senders;
public EDReceive()
{
senders = new ArrayList<Sender>();
}
private Sender senderExist( long senderID )
{
Sender sender = null;
Iterator<Sender> it = senders.iterator();
while( it.hasNext() && (null == sender ) )
{
Sender s = it.next();
if( s.getID() == senderID )
sender = s;
}
return sender;
}
public long getSeqNum( long senderID )
{
long sequenceNumber = Sender.INVALID;
Sender s = senderExist( senderID );
if( null != s )
sequenceNumber = s.getSequenceNumber();
return sequenceNumber;
}
public boolean updateSeqNum( long senderID, long sequenceNumber )
{
Sender s = senderExist( senderID );
if( null != s )
{
s.setSequenceNum( sequenceNumber );
return true;
}
return false;
}
public boolean addSender( long senderID )
{
Sender s = new Sender( senderID );
senders.add( s );
return true;
}
public class Sender
{
private long senderID;
private long sequenceNumber;
private Date timestamp;
public static final long INVALID = -1;
public Sender( long senderID, long sequenceNumber, Date timestamp )
{
this.senderID = senderID;
this.sequenceNumber = sequenceNumber;
this.timestamp = timestamp;
}
public Sender( long senderID )
{
// this( senderID, Sender.INVALID, Calendar.getInstance().getTime() ); // TODO: fix this and then uncomment it.
//commented because of error:
//
//EDReceive.java:80: cannot find symbol
//symbol : variable Calendar
//location: class EDReceive.Sender
// this( senderID, Sender.INVALID, Calendar.getInstance().getTime() );
}
public long getID()
{
return senderID;
}
public long getSequenceNumber()
{
return sequenceNumber;
}
public void setSequenceNum( long sequenceNumber )
{
this.sequenceNumber = sequenceNumber;
}
}
public void run()
{
}
}