Local communication working
[iotcloud.git] / version2 / src / java / iotcloud / SlotIndexer.java
1 package iotcloud;
2
3 /**
4  * Slot indexer allows slots in both the slot buffer and the new
5  * server response to looked up in a consistent fashion.
6  * @author Brian Demsky
7  * @version 1.0
8  */
9
10 class SlotIndexer {
11         private Slot[] updates;
12         private SlotBuffer buffer;
13         private long firstslotseqnum;
14
15         SlotIndexer(Slot[] _updates, SlotBuffer _buffer) {
16                 buffer = _buffer;
17                 updates = _updates;
18                 firstslotseqnum = updates[0].getSequenceNumber();
19         }
20
21         Slot getSlot(long seqnum) {
22                 if (seqnum >= firstslotseqnum) {
23                         int offset = (int) (seqnum - firstslotseqnum);
24                         if (offset >= updates.length)
25                                 throw new Error("Invalid Slot Sequence Number Reference");
26                         else
27                                 return updates[offset];
28                 } else
29                         return buffer.getSlot(seqnum);
30         }
31 }