All Downloads are FREE. Search and download functionalities are using the official Maven repository.

umontreal.iro.lecuyer.simevents.LinkedListStat Maven / Gradle / Ivy

Go to download

SSJ is a Java library for stochastic simulation, developed under the direction of Pierre L'Ecuyer, in the Département d'Informatique et de Recherche Opérationnelle (DIRO), at the Université de Montréal. It provides facilities for generating uniform and nonuniform random variates, computing different measures related to probability distributions, performing goodness-of-fit tests, applying quasi-Monte Carlo methods, collecting (elementary) statistics, and programming discrete-event simulations with both events and processes.

The newest version!


/*
 * Class:        LinkedListStat
 * Description:  
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Université de Montréal
 * Organization: DIRO, Université de Montréal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   GPL licence site.
 */

package umontreal.iro.lecuyer.simevents;

import java.util.Collection;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import umontreal.iro.lecuyer.util.PrintfFormat;


/**
 * This class extends {@link ListWithStat}, and
 * uses a linked list as the internal data structure.
 * 
 */
public class LinkedListStat extends ListWithStat {


   /**
    * Constructs a new list, initially empty.
    * 
    */
   public LinkedListStat() {
      super (Simulator.getDefaultSimulator(), new LinkedList>());
   } 


   /**
    * Constructs a new list, initially empty, and using the default simulator.
    * 
    * @param inSim Simulator associate to the current variable.
    * 
    * 
    */
   public LinkedListStat(Simulator inSim) {
      super (inSim, new LinkedList>());
   } 


   /**
    * Constructs a list containing the elements of the specified
    *    collection, using the default simulator.
    * 
    * @param c collection containing elements to fill in this list with
    * 
    * 
    */
   public LinkedListStat (Collection c) {
      super (Simulator.getDefaultSimulator(), new LinkedList>(), c);
   }


   /**
    * Constructs a list containing the elements of the specified
    *    collection.
    * 
    * @param inSim Simulator associate to the current variable.
    * 
    *    @param c collection containing elements to fill in this list with
    * 
    * 
    */
   public LinkedListStat (Simulator inSim, Collection c) {
      super (inSim, new LinkedList>(), c);
   }


   /**
    * Constructs a new list with name name, using the default simulator.
    *    This name can be used to identify the list in traces and reports.
    * 
    * @param name name for the list object
    * 
    * 
    */
   public LinkedListStat (String name) {
      super (Simulator.getDefaultSimulator(), new LinkedList>(), name);
   }


   /**
    * Constructs a new list with name name.
    *    This name can be used to identify the list in traces and reports.
    * 
    * @param inSim Simulator associate to the current variable.
    * 
    *    @param name name for the list object
    * 
    * 
    */
   public LinkedListStat (Simulator inSim, String name) {
      super (inSim, new LinkedList>(), name);
   }


   /**
    * Constructs a new list containing the elements of the
    *    specified collection c and with name name, using the default simulator.
    *    This name can be used to identify the list in traces and reports.
    * 
    *     @param c collection containing elements to fill in this list with
    * 
    *    @param name name for the list object
    * 
    * 
    */
   public LinkedListStat (Collection c, String name) {
      super (Simulator.getDefaultSimulator(), new LinkedList>(), c, name);
   }


   /**
    * Constructs a new list containing the elements of the
    *    specified collection c and with name name.
    *    This name can be used to identify the list in traces and reports.
    * 
    * @param inSim Simulator associate to the current variable.
    * 
    *    @param c collection containing elements to fill in this list with
    * 
    *    @param name name for the list object
    * 
    */
   public LinkedListStat (Simulator inSim, Collection c,
                          String name) {
      super (inSim, new LinkedList>(), c, name);
   }


   public void addFirst (E obj) {
      add (0, obj);
   }


   public void addLast (E obj) {
      add (size(), obj);
   }


   public E getFirst() {
      if (isEmpty())
         throw new NoSuchElementException();
      return get (0);
    }


   public E getLast() {
      if (isEmpty())
         throw new NoSuchElementException();
      return get (size() - 1);
   }


   public E removeFirst() {
      if (isEmpty())
         throw new NoSuchElementException();
      return remove (0);
   }


   public E removeLast()  {
      if (isEmpty())
         throw new NoSuchElementException();
      return remove (size() - 1);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy