Class ImmutableSortedBagImpl<T>

    • Field Detail

      • elements

        private final T[] elements
      • occurrences

        private final int[] occurrences
      • comparator

        private final java.util.Comparator<? super T> comparator
      • size

        private final int size
    • Constructor Detail

      • ImmutableSortedBagImpl

        ImmutableSortedBagImpl​(SortedBag<T> sortedBag)
      • ImmutableSortedBagImpl

        private ImmutableSortedBagImpl​(T[] elements,
                                       int[] occurrences,
                                       java.util.Comparator<? super T> comparator)
    • Method Detail

      • comparator

        public java.util.Comparator<? super T> comparator()
        Description copied from interface: SortedBag
        Returns the comparator used to order the elements in this bag, or null if this bag uses the natural ordering of its elements.
        Specified by:
        comparator in interface SortedBag<T>
        Specified by:
        comparator in interface SortedIterable<T>
      • min

        public T min​(java.util.Comparator<? super T> comparator)
        Description copied from interface: RichIterable
        Returns the minimum element out of this container based on the comparator.
        Specified by:
        min in interface RichIterable<T>
        Overrides:
        min in class AbstractRichIterable<T>
      • minBy

        public <V extends java.lang.Comparable<? super V>> T minBy​(Function<? super T,​? extends V> function)
        Description copied from interface: RichIterable
        Returns the minimum elements out of this container based on the natural order of the attribute returned by Function.
        Specified by:
        minBy in interface RichIterable<T>
        Overrides:
        minBy in class AbstractRichIterable<T>
      • max

        public T max​(java.util.Comparator<? super T> comparator)
        Description copied from interface: RichIterable
        Returns the maximum element out of this container based on the comparator.
        Specified by:
        max in interface RichIterable<T>
        Overrides:
        max in class AbstractRichIterable<T>
      • maxBy

        public <V extends java.lang.Comparable<? super V>> T maxBy​(Function<? super T,​? extends V> function)
        Description copied from interface: RichIterable
        Returns the maximum elements out of this container based on the natural order of the attribute returned by Function.
        Specified by:
        maxBy in interface RichIterable<T>
        Overrides:
        maxBy in class AbstractRichIterable<T>
      • detectIndex

        public int detectIndex​(Predicate<? super T> predicate)
        Description copied from interface: OrderedIterable
        Returns the index of the first element of the OrderedIterable for which the predicate evaluates to true. Returns -1 if no element evaluates true for the predicate.
        Specified by:
        detectIndex in interface OrderedIterable<T>
      • detectNotIndex

        private int detectNotIndex​(Predicate<? super T> predicate)
      • forEachWithOccurrences

        public void forEachWithOccurrences​(ObjectIntProcedure<? super T> procedure)
        Description copied from interface: Bag
        For each distinct item, with the number of occurrences, execute the specified procedure.
        Specified by:
        forEachWithOccurrences in interface Bag<T>
      • anySatisfyWithOccurrences

        public boolean anySatisfyWithOccurrences​(ObjectIntPredicate<? super T> predicate)
        Description copied from interface: Bag
        Returns true if the predicate evaluates to true for any element of the Bag. Returns false if the Bag is empty or if no element returns true for the predicate.
        Specified by:
        anySatisfyWithOccurrences in interface Bag<T>
      • allSatisfyWithOccurrences

        public boolean allSatisfyWithOccurrences​(ObjectIntPredicate<? super T> predicate)
        Description copied from interface: Bag
        Returns true if the predicate evaluates to true for all elements of the Bag. Returns false if the Bag is empty or if not all elements return true for the predicate.
        Specified by:
        allSatisfyWithOccurrences in interface Bag<T>
      • noneSatisfyWithOccurrences

        public boolean noneSatisfyWithOccurrences​(ObjectIntPredicate<? super T> predicate)
        Description copied from interface: Bag
        Returns true if the Bag is empty or if the predicate evaluates to false for all elements of the Bag. Returns false if the predicate evaluates to true for at least one element of the Bag.
        Specified by:
        noneSatisfyWithOccurrences in interface Bag<T>
      • detectWithOccurrences

        public T detectWithOccurrences​(ObjectIntPredicate<? super T> predicate)
        Description copied from interface: Bag
        Returns an element of the Bag that satisfies the predicate or null if such an element does not exist
        Specified by:
        detectWithOccurrences in interface Bag<T>
      • sizeDistinct

        public int sizeDistinct()
        Description copied from interface: Bag
        The size of the Bag when counting only distinct elements.
        Specified by:
        sizeDistinct in interface Bag<T>
      • size

        public int size()
        Description copied from interface: RichIterable
        Returns the number of items in this iterable.
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in interface RichIterable<T>
      • indexOf

        public int indexOf​(java.lang.Object object)
        Description copied from interface: OrderedIterable
        Returns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.
        Specified by:
        indexOf in interface OrderedIterable<T>
        See Also:
        List.indexOf(Object)
      • getFirst

        public T getFirst()
        Description copied from interface: RichIterable
        Returns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.

        The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.

        Specified by:
        getFirst in interface OrderedIterable<T>
        Specified by:
        getFirst in interface RichIterable<T>
      • getLast

        public T getLast()
        Description copied from interface: RichIterable
        Returns the last element of an iterable. In the case of a List it is the element at the last index. In the case of any other Collection, it is the last element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.

        The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the last element could be any element from the Set.

        Specified by:
        getLast in interface OrderedIterable<T>
        Specified by:
        getLast in interface RichIterable<T>
      • forEach

        public void forEach​(int fromIndex,
                            int toIndex,
                            Procedure<? super T> procedure)
        Description copied from interface: OrderedIterable
        Iterates over the section of the iterable covered by the specified inclusive indexes. The indexes are both inclusive.
        e.g.
         OrderedIterable<People> people = FastList.newListWith(ted, mary, bob, sally)
         people.forEach(0, 1, new Procedure<Person>()
         {
             public void value(Person person)
             {
                  LOGGER.info(person.getName());
             }
         });
         

        This code would output ted and mary's names.

        Specified by:
        forEach in interface OrderedIterable<T>
      • each

        public void each​(Procedure<? super T> procedure)
        Description copied from interface: RichIterable
        The procedure is executed for each element in the iterable.

        Example using a Java 8 lambda expression:

         people.each(person -> LOGGER.info(person.getName()));
         

        Example using an anonymous inner class:

         people.each(new Procedure<Person>()
         {
             public void value(Person person)
             {
                 LOGGER.info(person.getName());
             }
         });
         
        This method is a variant of InternalIterable.forEach(Procedure) that has a signature conflict with Iterable.forEach(java.util.function.Consumer).
        Specified by:
        each in interface RichIterable<T>
        See Also:
        InternalIterable.forEach(Procedure), Iterable.forEach(java.util.function.Consumer)
      • forEachWithIndex

        public void forEachWithIndex​(ObjectIntProcedure<? super T> objectIntProcedure)
        Description copied from interface: InternalIterable
        Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

        Example using a Java 8 lambda:

         people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
         

        Example using an anonymous inner class:

         people.forEachWithIndex(new ObjectIntProcedure<Person>()
         {
             public void value(Person person, int index)
             {
                 LOGGER.info("Index: " + index + " person: " + person.getName());
             }
         });
         
        Specified by:
        forEachWithIndex in interface InternalIterable<T>
        Specified by:
        forEachWithIndex in interface OrderedIterable<T>
        Overrides:
        forEachWithIndex in class AbstractRichIterable<T>
      • collectWithIndex

        public <V,​R extends java.util.Collection<V>> R collectWithIndex​(ObjectIntToObjectFunction<? super T,​? extends V> function,
                                                                              R target)
        Description copied from interface: OrderedIterable
        Adds elements to the target Collection using results obtained by applying the specified function to each element and its corresponding index.
        Specified by:
        collectWithIndex in interface OrderedIterable<T>
        Since:
        9.1.
      • forEachWithIndex

        public void forEachWithIndex​(int fromIndex,
                                     int toIndex,
                                     ObjectIntProcedure<? super T> objectIntProcedure)
        Description copied from interface: OrderedIterable
        Iterates over the section of the iterable covered by the specified inclusive indexes. The indexes are both inclusive.
        e.g.
         OrderedIterable<People> people = FastList.newListWith(ted, mary, bob, sally)
         people.forEachWithIndex(0, 1, new ObjectIntProcedure<Person>()
         {
             public void value(Person person, int index)
             {
                  LOGGER.info(person.getName());
             }
         });
         

        This code would output ted and mary's names.

        Specified by:
        forEachWithIndex in interface OrderedIterable<T>
      • occurrencesOf

        public int occurrencesOf​(java.lang.Object item)
        Description copied from interface: Bag
        The occurrences of a distinct item in the bag.
        Specified by:
        occurrencesOf in interface Bag<T>
      • corresponds

        public <S> boolean corresponds​(OrderedIterable<S> other,
                                       Predicate2<? super T,​? super S> predicate)
        Description copied from interface: OrderedIterable
        Returns true if both OrderedIterables have the same length and predicate returns true for all corresponding elements e1 of this OrderedIterable and e2 of other. The predicate is evaluated for each element at the same position of each OrderedIterable in a forward iteration order. This is a short circuit pattern.
        Specified by:
        corresponds in interface OrderedIterable<T>
      • toSortedList

        public MutableList<T> toSortedList()
        Description copied from interface: RichIterable
        Converts the collection to a MutableList implementation and sorts it using the natural order of the elements.
        Specified by:
        toSortedList in interface RichIterable<T>
      • toArray

        public java.lang.Object[] toArray()
        Description copied from interface: RichIterable
        Converts this iterable to an array.
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface RichIterable<T>
        Overrides:
        toArray in class AbstractRichIterable<T>
        See Also:
        Collection.toArray()
      • toArray

        public <E> E[] toArray​(E[] array)
        Description copied from interface: RichIterable
        Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface RichIterable<T>
        Overrides:
        toArray in class AbstractRichIterable<T>
        See Also:
        Collection.toArray(Object[])
      • compareTo

        public int compareTo​(SortedBag<T> otherBag)
        Specified by:
        compareTo in interface java.lang.Comparable<T>
      • anySatisfy

        public boolean anySatisfy​(Predicate<? super T> predicate)
        Description copied from interface: RichIterable
        Returns true if the predicate evaluates to true for any element of the iterable. Returns false if the iterable is empty, or if no element returned true when evaluating the predicate.
        Specified by:
        anySatisfy in interface RichIterable<T>
        Overrides:
        anySatisfy in class AbstractRichIterable<T>
      • anySatisfyWith

        public <P> boolean anySatisfyWith​(Predicate2<? super T,​? super P> predicate,
                                          P parameter)
        Description copied from interface: RichIterable
        Returns true if the predicate evaluates to true for any element of the collection, or return false. Returns false if the collection is empty.
        Specified by:
        anySatisfyWith in interface RichIterable<T>
        Overrides:
        anySatisfyWith in class AbstractRichIterable<T>
      • noneSatisfyWith

        public <P> boolean noneSatisfyWith​(Predicate2<? super T,​? super P> predicate,
                                           P parameter)
        Description copied from interface: RichIterable
        Returns true if the predicate evaluates to false for every element of the collection, or return false. Returns true if the collection is empty.
        Specified by:
        noneSatisfyWith in interface RichIterable<T>
        Overrides:
        noneSatisfyWith in class AbstractRichIterable<T>
      • detect

        public T detect​(Predicate<? super T> predicate)
        Description copied from interface: RichIterable
        Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true. This method is commonly called find.

        Example using a Java 8 lambda expression:

         Person person =
             people.detect(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
         

        Example using an anonymous inner class:

         Person person =
             people.detect(new Predicate<Person>()
             {
                 public boolean accept(Person person)
                 {
                     return person.getFirstName().equals("John") && person.getLastName().equals("Smith");
                 }
             });
         
        Specified by:
        detect in interface RichIterable<T>
        Overrides:
        detect in class AbstractRichIterable<T>
      • detectOptional

        public java.util.Optional<T> detectOptional​(Predicate<? super T> predicate)
        Description copied from interface: RichIterable
        Returns the first element of the iterable for which the predicate evaluates to true as an Optional. This method is commonly called find.

        Example using a Java 8 lambda expression:

         Person person =
             people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
         

        Specified by:
        detectOptional in interface RichIterable<T>
        Overrides:
        detectOptional in class AbstractRichIterable<T>
      • contains

        public boolean contains​(java.lang.Object object)
        Description copied from interface: RichIterable
        Returns true if the iterable has an element which responds true to element.equals(object).
        Specified by:
        contains in interface java.util.Collection<T>
        Specified by:
        contains in interface RichIterable<T>
        Overrides:
        contains in class AbstractRichIterable<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>
      • equals

        public boolean equals​(java.lang.Object other)
        Description copied from interface: Bag
        Two bags b1 and b2 are equal if m1.toMapOfItemToCount().equals(m2.toMapOfItemToCount()).
        Specified by:
        equals in interface Bag<T>
        Specified by:
        equals in interface java.util.Collection<T>
        Overrides:
        equals in class java.lang.Object
        See Also:
        Map.equals(Object)
      • hashCode

        public int hashCode()
        Description copied from interface: Bag
        Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount().hashCode().
        Specified by:
        hashCode in interface Bag<T>
        Specified by:
        hashCode in interface java.util.Collection<T>
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Map.hashCode()
      • distinctView

        public RichIterable<T> distinctView()
        Description copied from interface: Bag
        Returns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.
        Specified by:
        distinctView in interface Bag<T>
        Returns:
        an unmodifiable view on the distinct elements of the Bag.