27package umontreal.ssj.simevents;
29import java.util.Collection;
31import java.util.Iterator;
32import java.util.ListIterator;
33import java.util.NoSuchElementException;
34import umontreal.ssj.stat.Tally;
35import umontreal.ssj.util.TransformingList;
36import umontreal.ssj.util.PrintfFormat;
51 private boolean stats;
52 private double initTime;
54 private Tally blockSojourn;
78 if (inSim ==
null || nodeList ==
null)
79 throw new NullPointerException();
106 this(inSim, nodeList);
134 this(inSim, nodeList);
164 this(inSim, nodeList);
169 public E convertFromInnerType(Node<E> node) {
170 return node.getElement();
173 public Node<E> convertToInnerType(E element) {
174 return new Node<E>(element, sim.
time());
194 throw new NullPointerException();
196 if (blockSize !=
null)
197 blockSize.setSimulator(sim);
201 public void clear() {
208 public void add(
int index, E obj) {
209 super.add(index, obj);
215 public E
remove(
int index) {
216 Node<E> node = getInnerList().get(index);
218 blockSojourn.
add(sim.
time() - node.getInsertionTime());
219 E e = super.remove(index);
226 public Iterator<E> iterator() {
227 return new IteratorWithStat(getInnerList().iterator());
231 public ListIterator<E> listIterator() {
232 return new ListIteratorWithStat(getInnerList().listIterator());
236 public ListIterator<E> listIterator(
int index) {
237 return new ListIteratorWithStat(getInnerList().listIterator(index));
241 public E
set(
int index, E element) {
242 Node<E> oldNode = getInnerList().get(index);
245 if (oldElement ==
null || element ==
null)
246 equal = oldElement == element;
248 equal = oldElement.equals(element);
250 getInnerList().set(index,
new Node<E>(element, oldNode.getInsertionTime()));
254 blockSojourn.add(sim.time() - oldNode.getInsertionTime());
255 getInnerList().set(index,
new Node<E>(element, sim.time()));
260 private class IteratorWithStat
implements Iterator<E> {
261 private Iterator<Node<E>> itr;
262 private Node<E> lastRet;
264 public IteratorWithStat(Iterator<Node<E>> itr) {
268 public boolean hasNext() {
269 return itr.hasNext();
273 lastRet = itr.next();
274 return lastRet.getElement();
277 public void remove() {
281 blockSojourn.
add(sim.
time() - lastRet.getInsertionTime());
287 private class ListIteratorWithStat
implements ListIterator<E> {
288 private ListIterator<Node<E>> itr;
289 private Node<E> lastRet;
291 public ListIteratorWithStat(ListIterator<Node<E>> itr) {
295 public void add(E o) {
296 itr.add(
new Node<E>(o, sim.
time()));
302 public boolean hasNext() {
303 return itr.hasNext();
306 public boolean hasPrevious() {
307 return itr.hasPrevious();
311 lastRet = itr.next();
312 return lastRet.getElement();
315 public int nextIndex() {
316 return itr.nextIndex();
319 public E previous() {
320 lastRet = itr.previous();
321 return lastRet.getElement();
324 public int previousIndex() {
325 return itr.previousIndex();
328 public void remove() {
332 blockSojourn.
add(sim.
time() - lastRet.getInsertionTime());
337 public void set(E element) {
339 throw new NoSuchElementException();
340 Node<E> oldNode = lastRet;
341 E oldElement = oldNode.getElement();
343 if (oldElement ==
null || element ==
null)
344 equal = oldElement == element;
346 equal = oldElement.equals(element);
348 lastRet =
new Node<E>(element, oldNode.getInsertionTime());
352 blockSojourn.
add(sim.
time() - oldNode.getInsertionTime());
353 lastRet =
new Node<E>(element, sim.
time());
392 if (blockSize ==
null)
393 blockSize =
new Accumulate(sim,
"List Size " + name);
394 if (blockSojourn ==
null)
395 blockSojourn =
new Tally(
"List Sojourn " + name);
396 blockSize.update(size());
412 throw new IllegalStateException(
"initStat for a list that did not call setStatCollecting (true).");
415 blockSize.update(size());
416 initTime = sim.time();
464 if (blockSojourn ==
null || blockSize ==
null)
465 throw new IllegalStateException(
"Calling report when no statistics were collected");
471 str.
append(
" min max average ");
472 str.
append(
"standard dev. nb. Obs");
475 str.
append(9, (
int) (blockSize.min() + 0.5));
476 str.
append(11, (
int) (blockSize.max() + 0.5));
482 str.
append(10, 3, 2, blockSojourn.average()).
append(
" ");
483 str.
append(10, 3, 2, blockSojourn.standardDeviation()).
append(
" ");
511 private double insertionTime;
524 public Node(E element,
double insertionTime) {
525 this.element = element;
526 this.insertionTime = insertionTime;
544 return insertionTime;
547 public String toString() {
548 String str = element ==
null ?
"null" : element.toString();
549 str +=
" (inserted at time " + insertionTime +
")";
A subclass of umontreal.ssj.stat.StatProbe, for collecting statistics on a variable that evolves in s...
void update()
Updates the accumulator using the last value passed to update(double).
Represents a node that can be part of a list with statistical collecting.
Node(E element, double insertionTime)
Constructs a new node containing element element inserted into the list at time insertionTime.
E getElement()
Returns the element stored into this node.
double getInsertionTime()
Returns the insertion time of the element in this node.
void setStatCollecting(boolean b)
Starts or stops collecting statistics on this list.
Simulator simulator()
Returns the simulator associated with this list.
ListWithStat(Simulator inSim, List< Node< E > > nodeList)
Constructs a new list with internal data structure implemented by nodeList.
ListWithStat(List< Node< E > > nodeList, String name)
Constructs a new list with name name, internal list nodeList, and using the default simulator.
String report()
Returns a string containing a statistical report on the list, provided that setStatCollecting(true) h...
double getInitTime()
Returns the last simulation time initStat was called.
boolean getStatCollecting()
Returns true if the list collects statistics about its size and sojourn times of elements,...
ListWithStat(List< Node< E > > nodeList, Collection<? extends E > c)
Constructs a list containing the elements of the specified collection, whose elements are stored into...
ListWithStat(List< Node< E > > nodeList, Collection<? extends E > c, String name)
Constructs a new list containing the elements of the specified collection c, with name name,...
String getName()
Returns the name associated to this list, or null if no name was assigned.
ListWithStat(Simulator inSim, List< Node< E > > nodeList, String name)
Constructs a new list with name name, and internal list nodeList.
Tally statSojourn()
Returns the statistical probe on the sojourn times of the objects in the list.
void initStat()
Reinitializes the two statistical probes created by setStatCollecting(true) and makes an update for t...
ListWithStat(Simulator inSim, List< Node< E > > nodeList, Collection<? extends E > c)
Constructs a list containing the elements of the specified collection, whose elements are stored into...
ListWithStat(List< Node< E > > nodeList)
Constructs a new list with internal data structure using the default simulator and implemented by nod...
ListWithStat(Simulator inSim, List< Node< E > > nodeList, Collection<? extends E > c, String name)
Constructs a new list containing the elements of the specified collection c, with name name,...
Accumulate statSize()
Returns the statistical probe on the evolution of the size of the list as a function of the simulatio...
void setSimulator(Simulator sim)
Sets the simulator associated with this list.
Represents the executive of a discrete-event simulator.
static Simulator getDefaultSimulator()
Returns the default simulator instance used by the deprecated class.
double time()
Returns the current value of the simulation clock.
void add(double x)
Gives a new observation x to the statistical collector.