Class Buckets

java.lang.Object
com.yetnt.utils.collection.buckets.Buckets

public abstract class Buckets extends Object
Utility class for dividing an ArrayList into multiple sub-lists, referred to as "buckets," based on various criteria.

From Jaiva!

Author:
Lehlogonolo Poole
See Also:
  • Constructor Details

    • Buckets

      public Buckets()
  • Method Details

    • of

      public static <T> ArrayList<ArrayList<T>> of(ArrayList<T> original, Class<?>... classes)
      Divides an ArrayList into multiple buckets based on the provided classes. Each bucket will contain elements from the original list that are instances of the corresponding class. The order of elements within each bucket is preserved from the original list.
      Parameters:
      original - The original ArrayList to be divided.
      classes - A variable number of Class objects, each representing a type for which a separate bucket will be created.
      Returns:
      An ArrayList of ArrayLists, where each inner ArrayList is a bucket containing elements of a specific type from the original list. The order of buckets in the returned list corresponds to the order of classes provided.
    • of

      public static <T> ArrayList<ArrayList<T>> of(ArrayList<T> original, Bucket... buckets)
      Divides an ArrayList into multiple buckets based on custom Bucket implementations. Each bucket will contain elements from the original list that satisfy the condition defined by the corresponding Bucket's shouldHold method. The order of elements within each bucket is preserved from the original list.
      Parameters:
      original - The original ArrayList to be divided.
      buckets - A variable number of Bucket objects, each defining a custom condition for elements to be placed into its respective bucket.
      Returns:
      An ArrayList of ArrayLists, where each inner ArrayList is a bucket containing elements that satisfy the condition of the corresponding Bucket. The order of buckets in the returned list corresponds to the order of buckets provided.
    • scoop

      public static <T> ArrayList<T> scoop(ArrayList<T> original, Bucket... buckets)