Class RandomList<T>

  • Type Parameters:
    T -
    All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, RandomElementIfc, ObservableIfc, StreamOptionIfc, GetNameIfc, IdentityIfc, GetRandomNumberStreamIfc, RNStreamControlIfc, SetRandomNumberStreamIfc, RElementIfc<T>, RListIfc<T>

    public abstract class RandomList<T>
    extends ModelElement
    implements RListIfc<T>, RandomElementIfc
    Allows for random selection from a list of objects as supplied by the RList<T> The list is created empty unless a List<T> is supplied upon construction. Thus, if the user does not supply an initial list then there will not be any elements to select from during the replication. By default the list is cleared prior to each replication. If a List<T> is supplied to initialize the list at the beginning of each replication, then it will be used to set up the elements in the list Note: The underlying streams for the random selection process are controlled by the replication, see RandomVariable Note: If the user calls setRandomList() or calls any mutator methods on the list, during the replication the list will be changed; however, the supplied initial list will not have been changed and will be used to reinitialize the list at the beginning of each replication. If the user does not want this behavior, then overwrite the initialize() method or turn off automatic initialization via the ModelElement interface, setInitializationOption(false). Warning: If the user uses ANY mutator methods (e.g. add() etc) prior to the start of a replication, then the list will be CLEARED prior to the the replication (or set to the supplied initialization list). If the user does not want the list cleared or initialize use setInitializationOption(false). Warning: If the user changes the supplied initial list during or between replications, then each replication may not start under the same conditions. Warning: There may not be elements in the list, thus a call to getRandomElement() may return null The default RList is DUniformList, equally likely selection over the elements in the list
    • Field Detail

      • myRList

        protected RList<T> myRList
      • myInitialList

        protected java.util.List<T> myInitialList
    • Constructor Detail

      • RandomList

        public RandomList​(ModelElement parent)
        Creates an empty list. Elements must be added to it for random selection to be possible.
        Parameters:
        parent -
      • RandomList

        public RandomList​(ModelElement parent,
                          java.util.List<T> initialList)
        The initial list is used to initialize the list prior to each replication. The supplied list is copied.
        Parameters:
        parent -
      • RandomList

        public RandomList​(ModelElement parent,
                          java.util.List<T> initialList,
                          java.lang.String name)
        The initial list is used to initialize the list prior to each replication. The supplied list is copied.
        Parameters:
        parent -
        initialList -
        name -
    • Method Detail

      • initializeList

        protected void initializeList​(java.util.List<T> list)
      • initialize

        protected void initialize()
        Description copied from class: ModelElement
        This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called
        Overrides:
        initialize in class ModelElement
      • removedFromModel

        protected void removedFromModel()
        Description copied from class: ModelElement
        This method should be overridden by subclasses that need actions performed when a model element is removed from a model
        Overrides:
        removedFromModel in class ModelElement
      • beforeExperiment

        protected void beforeExperiment()
        before any replications reset the underlying random number generator to the starting stream
        Overrides:
        beforeExperiment in class ModelElement
      • afterReplication

        protected void afterReplication()
        after each replication reset the underlying random number generator to the next sub-stream
        Overrides:
        afterReplication in class ModelElement
      • setRandomList

        public void setRandomList​(RList<T> list)
        Allows the user to change the random list after it has been initialized by the initial list. The supplied list will be used directly instead of the current list
        Parameters:
        list -
      • setInitialList

        public void setInitialList​(java.util.List<T> list)
        Sets the initial list to be used to initialize the list at the beginning of each replication
        Parameters:
        list -
      • setResetStartStreamOption

        public final void setResetStartStreamOption​(boolean b)
        Description copied from interface: StreamOptionIfc
        Sets the reset start stream option, true means that it will be reset to the starting stream
        Specified by:
        setResetStartStreamOption in interface StreamOptionIfc
        Parameters:
        b - true means reset
      • getResetNextSubStreamOption

        public final boolean getResetNextSubStreamOption()
        Description copied from interface: StreamOptionIfc
        Gets the current reset next sub-stream option true means, that it is set to jump to the next sub-stream after each replication
        Specified by:
        getResetNextSubStreamOption in interface StreamOptionIfc
        Returns:
        the option
      • setResetNextSubStreamOption

        public final void setResetNextSubStreamOption​(boolean b)
        Description copied from interface: StreamOptionIfc
        Sets the current reset next sub-stream option true means, that it is set to jump to the next sub-stream after each replication
        Specified by:
        setResetNextSubStreamOption in interface StreamOptionIfc
        Parameters:
        b - true means reset
      • add

        public void add​(int index,
                        T element)
        Specified by:
        add in interface java.util.List<T>
      • add

        public boolean add​(T obj)
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.List<T>
      • addAll

        public boolean addAll​(java.util.Collection<? extends T> c)
        Specified by:
        addAll in interface java.util.Collection<T>
        Specified by:
        addAll in interface java.util.List<T>
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends T> c)
        Specified by:
        addAll in interface java.util.List<T>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<T>
        Specified by:
        clear in interface java.util.List<T>
      • contains

        public boolean contains​(java.lang.Object arg0)
        Specified by:
        contains in interface java.util.Collection<T>
        Specified by:
        contains in interface java.util.List<T>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> arg0)
        Specified by:
        containsAll in interface java.util.Collection<T>
        Specified by:
        containsAll in interface java.util.List<T>
      • get

        public T get​(int index)
        Specified by:
        get in interface java.util.List<T>
      • getList

        public java.util.List<T> getList()
        Returns:
        See Also:
        RList.getList()
      • getRandomElement

        public T getRandomElement()
        Description copied from interface: RElementIfc
        Returns an element randomly selected from the list
        Specified by:
        getRandomElement in interface RElementIfc<T>
        Returns:
        a randomly selected element from the list
      • indexOf

        public int indexOf​(java.lang.Object arg0)
        Specified by:
        indexOf in interface java.util.List<T>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<T>
        Specified by:
        isEmpty in interface java.util.List<T>
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in interface java.util.List<T>
      • lastIndexOf

        public int lastIndexOf​(java.lang.Object o)
        Specified by:
        lastIndexOf in interface java.util.List<T>
      • listIterator

        public java.util.ListIterator<T> listIterator()
        Specified by:
        listIterator in interface java.util.List<T>
      • listIterator

        public java.util.ListIterator<T> listIterator​(int index)
        Specified by:
        listIterator in interface java.util.List<T>
      • remove

        public T remove​(int index)
        Specified by:
        remove in interface java.util.List<T>
      • remove

        public boolean remove​(java.lang.Object obj)
        Specified by:
        remove in interface java.util.Collection<T>
        Specified by:
        remove in interface java.util.List<T>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<T>
        Specified by:
        removeAll in interface java.util.List<T>
      • resetStartStream

        public void resetStartStream()
        Description copied from interface: RNStreamControlIfc
        The resetStartStream method will position the RNG at the beginning of its stream. This is the same location in the stream as assigned when the RNG was created and initialized.
        Specified by:
        resetStartStream in interface RNStreamControlIfc
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<T>
        Specified by:
        retainAll in interface java.util.List<T>
      • set

        public T set​(int index,
                     T element)
        Specified by:
        set in interface java.util.List<T>
      • setAntitheticOption

        public void setAntitheticOption​(boolean flag)
        Description copied from interface: RNStreamControlIfc
        Tells the stream to start producing antithetic variates
        Specified by:
        setAntitheticOption in interface RNStreamControlIfc
        Parameters:
        flag - true means that it produces antithetic variates.
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in interface java.util.List<T>
      • subList

        public java.util.List<T> subList​(int fromIndex,
                                         int toIndex)
        Specified by:
        subList in interface java.util.List<T>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.List<T>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.List<T>