- Timestamp:
- 10/12/11 22:26:16 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/IncompleteMemory.java
r106 r253 1 1 package de.ugoe.cs.eventbench.models; 2 2 3 import java.security.InvalidParameterException; 3 4 import java.util.LinkedList; 4 5 import java.util.List; … … 40 41 * @param length 41 42 * number of recent events that are remembered 43 * @throws InvalidParameterException 44 * This exception is thrown if the length is smaller than 1 42 45 */ 43 46 public IncompleteMemory(int length) { 47 if (length < 1) { 48 throw new InvalidParameterException( 49 "Length of IncompleteMemory must be at least 1."); 50 } 44 51 this.length = length; 45 52 history = new LinkedList<T>(); … … 66 73 @Override 67 74 public List<T> getLast(int num) { 68 return new LinkedList<T>(history); // defensive copy 75 if( num<1 ) { 76 return new LinkedList<T>(); 77 } else { 78 return new LinkedList<T>(history.subList( 79 Math.max(0, history.size() - num), 80 history.size())); // defensive copy 81 } 69 82 } 70 83
Note: See TracChangeset
for help on using the changeset viewer.