source: trunk/EventBenchCore/src/de/ugoe/cs/eventbench/markov/IncompleteMemory.java @ 1

Last change on this file since 1 was 1, checked in by sherbold, 13 years ago
File size: 620 bytes
Line 
1package de.ugoe.cs.eventbench.markov;
2
3import java.util.LinkedList;
4import java.util.List;
5
6public 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.