Line | |
---|
1 | package de.ugoe.cs.eventbench.models;
|
---|
2 |
|
---|
3 | import java.util.LinkedList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | public class IncompleteMemory<T> implements IMemory<T> {
|
---|
7 |
|
---|
8 | private int length;
|
---|
9 |
|
---|
10 | private List<T> history;
|
---|
11 |
|
---|
12 | public IncompleteMemory(int length) {
|
---|
13 | this.length = length;
|
---|
14 | history = new LinkedList<T>();
|
---|
15 | }
|
---|
16 |
|
---|
17 | @Override
|
---|
18 | public void add(T state) {
|
---|
19 | if( history.size()==length ) {
|
---|
20 | history.remove(0);
|
---|
21 | }
|
---|
22 | history.add(state);
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | public List<T> getLast(int num) {
|
---|
27 | return new LinkedList<T>(history); // defensive copy
|
---|
28 | }
|
---|
29 |
|
---|
30 | public int getLength() {
|
---|
31 | return history.size();
|
---|
32 | }
|
---|
33 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.