Class Draw


  • public final class Draw
    extends java.lang.Object
    Utility to draw from a collection.

    Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See OpenTrafficSim License.

    Version:
    $Revision$, $LastChangedDate$, by $Author$, initial version 23 aug. 2018
    Author:
    Alexander Verbraeck, Peter Knoppers, Wouter Schakel
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <E> E draw​(java.util.Collection<E> collection, StreamInterface stream)
      Returns a randomly drawn element using uniform weights.
      static <E> E drawWeighted​(java.util.Map<E,​? extends java.lang.Double> map, StreamInterface stream)
      Returns a randomly drawn element using draw weights.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • drawWeighted

        public static <E> E drawWeighted​(java.util.Map<E,​? extends java.lang.Double> map,
                                         StreamInterface stream)
        Returns a randomly drawn element using draw weights.
        Type Parameters:
        E - element type
        Parameters:
        map - Map<E, ? extends Double>; map of elements and respective weights
        stream - StreamInterface; random number stream
        Returns:
        E; randomly drawn element
      • draw

        public static <E> E draw​(java.util.Collection<E> collection,
                                 StreamInterface stream)
        Returns a randomly drawn element using uniform weights.
        Type Parameters:
        E - element type
        Parameters:
        collection - Collection<E>; collection of elements
        stream - StreamInterface; random number stream
        Returns:
        E; randomly drawn element