Documentation of 'jsat.utils.ListUtils' Java class
ListUtils
jsat.utils

Class ListUtils



  • public class ListUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static void addRange(java.util.Collection<java.lang.Integer> c, int start, int to, int step)
      Adds values into the given collection using integer in the specified range and step size.
      static <T> java.util.List<T> collectFutures(java.util.Collection<java.util.concurrent.Future<T>> futures)
      Collects all future values in a collection into a list, and returns said list.
      static <T> java.util.List<T> mergedView(java.util.List<T> left, java.util.List<T> right)
      Returns a new unmodifiable view that is the merging of two lists
      static <T> void randomSample(java.util.Collection<T> source, java.util.Collection<T> dest, int samples, java.util.Random rand)
      Obtains a random sample without replacement from a source collection and places it in the destination collection.
      static <T> void randomSample(java.util.List<T> source, java.util.List<T> dest, int samples)
      Obtains a random sample without replacement from a source list and places it in the destination list.
      static <T> void randomSample(java.util.List<T> source, java.util.List<T> dest, int samples, java.util.Random rand)
      Obtains a random sample without replacement from a source list and places it in the destination list.
      static IntList range(int start, int to)
      Returns a list of integers with values in the given range
      static IntList range(int start, int to, int step)
      Returns a list of integers with values in the given range
      static <T> java.util.List<java.util.List<T>> splitList(java.util.List<T> source, int count)
      This method takes a list and breaks it into count lists backed by the original list, with elements being equally spaced among the lists.
      static void swap(java.util.List list, int i, int j)
      Swaps the values in the list at the given positions
      • Methods inherited from class java.lang.Object

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

      • splitList

        public static <T> java.util.List<java.util.List<T>> splitList(java.util.List<T> source,
                                                                      int count)
        This method takes a list and breaks it into count lists backed by the original list, with elements being equally spaced among the lists. The lists will be returned in order of the consecutive values they represent in the source list.

        NOTE: Because the implementation uses List.subList(int, int), changes to the returned lists will be reflected in the source list.
        Type Parameters:
        T - the type contained in the list
        Parameters:
        source - the source list that will be used to back the count lists
        count - the number of lists to partition the source into.
        Returns:
        a lists of lists, each of with the same size with at most a difference of 1.
      • mergedView

        public static <T> java.util.List<T> mergedView(java.util.List<T> left,
                                                       java.util.List<T> right)
        Returns a new unmodifiable view that is the merging of two lists
        Type Parameters:
        T - the type the lists hold
        Parameters:
        left - the left portion of the merged view
        right - the right portion of the merged view
        Returns:
        a list view that contains bot the left and right lists
      • swap

        public static void swap(java.util.List list,
                                int i,
                                int j)
        Swaps the values in the list at the given positions
        Parameters:
        list - the list to perform the swap in
        i - the first position to swap
        j - the second position to swap
      • collectFutures

        public static <T> java.util.List<T> collectFutures(java.util.Collection<java.util.concurrent.Future<T>> futures)
                                                    throws java.util.concurrent.ExecutionException,
                                                           java.lang.InterruptedException
        Collects all future values in a collection into a list, and returns said list. This method will block until all future objects are collected.
        Type Parameters:
        T - the type of future object
        Parameters:
        futures - the collection of future objects
        Returns:
        a list containing the object from the future.
        Throws:
        java.util.concurrent.ExecutionException
        java.lang.InterruptedException
      • addRange

        public static void addRange(java.util.Collection<java.lang.Integer> c,
                                    int start,
                                    int to,
                                    int step)
        Adds values into the given collection using integer in the specified range and step size. If the start value is greater or equal to the to value, nothing will be added to the collection.
        Parameters:
        c - the collection to add to
        start - the first value to add, inclusive
        to - the last value to add, exclusive
        step - the step size.
        Throws:
        java.lang.RuntimeException - if the step size is zero or negative.
      • range

        public static IntList range(int start,
                                    int to)
        Returns a list of integers with values in the given range
        Parameters:
        start - the starting integer value (inclusive)
        to - the ending integer value (exclusive)
        Returns:
        a list of integers containing the specified range of integers
      • range

        public static IntList range(int start,
                                    int to,
                                    int step)
        Returns a list of integers with values in the given range
        Parameters:
        start - the starting integer value (inclusive)
        to - the ending integer value (exclusive)
        step - the step size between values
        Returns:
        a list of integers containing the specified range of integers
      • randomSample

        public static <T> void randomSample(java.util.List<T> source,
                                            java.util.List<T> dest,
                                            int samples,
                                            java.util.Random rand)
        Obtains a random sample without replacement from a source list and places it in the destination list. This is done without modifying the source list.
        Type Parameters:
        T - the list content type involved
        Parameters:
        source - the source of values to randomly sample from
        dest - the list to store the random samples in. The list does not need to be empty for the sampling to work correctly
        samples - the number of samples to select from the source
        rand - the source of randomness for the sampling
        Throws:
        java.lang.IllegalArgumentException - if the sample size is not positive or l arger than the source population.
      • randomSample

        public static <T> void randomSample(java.util.Collection<T> source,
                                            java.util.Collection<T> dest,
                                            int samples,
                                            java.util.Random rand)
        Obtains a random sample without replacement from a source collection and places it in the destination collection. This is done without modifying the source collection.
        This random sampling is oblivious to failures to add to a collection that may occur, such as if the collection is a Set
        Type Parameters:
        T - the list content type involved
        Parameters:
        source - the source of values to randomly sample from
        dest - the collection to store the random samples in. It does not need to be empty for the sampling to work correctly
        samples - the number of samples to select from the source
        rand - the source of randomness for the sampling
        Throws:
        java.lang.IllegalArgumentException - if the sample size is not positive or l arger than the source population.
      • randomSample

        public static <T> void randomSample(java.util.List<T> source,
                                            java.util.List<T> dest,
                                            int samples)
        Obtains a random sample without replacement from a source list and places it in the destination list. This is done without modifying the source list.
        Type Parameters:
        T - the list content type involved
        Parameters:
        source - the source of values to randomly sample from
        dest - the list to store the random samples in. The list does not need to be empty for the sampling to work correctly
        samples - the number of samples to select from the source
        Throws:
        java.lang.IllegalArgumentException - if the sample size is not positive or l arger than the source population.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.