- Timestamp:
- 07/05/11 15:18:56 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/IncompleteMemory.java
r19 r106 4 4 import java.util.List; 5 5 6 /** 7 * <p> 8 * Implements a round-trip buffered memory of a specified length that can be 9 * used to remember the recent history. Every event that happend longer ago than 10 * the length of the memory is forgotten, hence the memory is incomplete. 11 * </p> 12 * 13 * @author Steffen Herbold 14 * @version 1.0 15 * 16 * @param <T> 17 * Type which is memorized. 18 */ 6 19 public class IncompleteMemory<T> implements IMemory<T> { 7 20 21 /** 22 * <p> 23 * Maximum length of the memory. 24 * </p> 25 */ 8 26 private int length; 9 27 28 /** 29 * <p> 30 * Internal storage of the history. 31 * </p> 32 */ 10 33 private List<T> history; 11 34 35 /** 36 * <p> 37 * Constructor. Creates a new IncompleteMemory. 38 * </p> 39 * 40 * @param length 41 * number of recent events that are remembered 42 */ 12 43 public IncompleteMemory(int length) { 13 44 this.length = length; 14 45 history = new LinkedList<T>(); 15 46 } 16 47 48 /* 49 * (non-Javadoc) 50 * 51 * @see de.ugoe.cs.eventbench.models.IMemory#add(java.lang.Object) 52 */ 17 53 @Override 18 54 public void add(T state) { 19 if ( history.size()==length) {55 if (history.size() == length) { 20 56 history.remove(0); 21 57 } … … 23 59 } 24 60 61 /* 62 * (non-Javadoc) 63 * 64 * @see de.ugoe.cs.eventbench.models.IMemory#getLast(int) 65 */ 25 66 @Override 26 67 public List<T> getLast(int num) { … … 28 69 } 29 70 71 /** 72 * <p> 73 * Returns the current length of the memory. This can be less than 74 * {@link #length}, if the overall history is less than {@link #length}. 75 * </p> 76 * 77 * @return length of the current memory 78 */ 30 79 public int getLength() { 31 80 return history.size();
Note: See TracChangeset
for help on using the changeset viewer.