01: package src;
02:
03: /**
04: * @invariants self.log <> null and self.log.length = self.logFileSize and self.logFileSize = 20 and self.currentRecord >= 0 and self.currentRecord < self.logFileSize and (self.currentRecord + 1).mod(self.logFileSize) >= 0 and (self.currentRecord + 1).mod(self.logFileSize) < self.logFileSize
05: */
06: public class LogFile {
07: private final static int logFileSize = 20;
08: private int currentRecord;
09: private LogRecord[] log = new LogRecord[logFileSize];
10:
11: public LogFile() {
12: for (int i = 0; i < log.length; i++)
13: log[i] = new LogRecord();
14: currentRecord = -1;
15: }
16:
17: public void addRecord(int balance, SaleDate date, int transactionId) {
18: currentRecord++;
19: if (currentRecord == logFileSize)
20: currentRecord = 0;
21: int posToInsert = currentRecord;
22: if (log[posToInsert] == null)
23: log[posToInsert] = new LogRecord();
24: log[posToInsert].setRecord(balance, date, transactionId);
25: }
26:
27: }
|