Top Description Inners Fields Constructors Methods
io.github.kusoroadeolu.clique.components

public Class IterableProgressBar<T>

extends Object
implements Iterable<T>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Annotations
@Stable
since:3.2.1
Type Parameters
<T>
the type of elements in the collection
Imports
io.github.kusoroadeolu.clique.configuration.ProgressBarConfiguration, io.github.kusoroadeolu.clique.internal.documentation.Stable, java.io.PrintStream, java.util.Collection, .Iterator, .Objects

A single-use Iterable wrapper around a Collection that advances a ProgressBar on each element consumed.

Each call to Iterator#next() on the iterator returned by iterator() delegates to the underlying collection iterator and immediately invokes ProgressBar#tick() on the internal progress bar, re-rendering it in place.

This iterable may only be traversed once. A second call to iterator() throws IllegalStateException. The progress bar total is fixed to the collection size at construction time.

This class is not thread-safe.

Since
3.2.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

Modifier and TypeField and Description
private boolean
private final Iterator<T>
pack-priv final ProgressBar
private PrintStream

Constructor Summary

AccessConstructor and Description
public
IterableProgressBar(Collection<T>
the collection to iterate over; must not be null
collection
,
ProgressBarConfiguration
the progress bar configuration to use; must not be null
configuration
)

Constructs an IterableProgressBar over the given collection with a custom configuration.

public
IterableProgressBar(Collection<T>
the collection to iterate over; must not be null
collection
)

Constructs an IterableProgressBar over the given collection using ProgressBarConfiguration#DEFAULT.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if the progress bar is complete; false otherwise
isDone
()

Returns whether the underlying progress bar has reached its total.

public Iterator<T>

Returns:

an iterator over the elements of the underlying collection
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator that advances the internal progress bar on each element consumed.

public IterableProgressBar<T>
printStream(PrintStream
the stream to print to; must not be null
stream
)

Prints the progress bar component to the given PrintStream, followed by a newline.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

consumedback to summary
private boolean consumed
iteratorback to summary
private final Iterator<T> iterator
progressBarback to summary
pack-priv final ProgressBar progressBar
streamback to summary
private PrintStream stream
Annotations
@SuppressWarnings:java:S106

Constructor Detail

IterableProgressBarback to summary
public IterableProgressBar(Collection<T> collection, ProgressBarConfiguration configuration)

Constructs an IterableProgressBar over the given collection with a custom configuration.

The progress bar total is set to collection.size() at construction time and does not reflect subsequent changes to the collection.

Parameters
collection:Collection<T>

the collection to iterate over; must not be null

configuration:ProgressBarConfiguration

the progress bar configuration to use; must not be null

Exceptions
NullPointerException:
if collection or configuration is null
IterableProgressBarback to summary
public IterableProgressBar(Collection<T> collection)

Constructs an IterableProgressBar over the given collection using ProgressBarConfiguration#DEFAULT.

Parameters
collection:Collection<T>

the collection to iterate over; must not be null

Exceptions
NullPointerException:
if collection is null

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
isDoneback to summary
public boolean isDone()

Returns whether the underlying progress bar has reached its total.

This returns true only after all elements have been consumed via Iterator#next(), since the bar is ticked per element.

Returns:boolean

true if the progress bar is complete; false otherwise

iteratorback to summary
public Iterator<T> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator that advances the internal progress bar on each element consumed.

This method may only be called once. The returned iterator is not reusable and reflects the state of the collection iterator captured at construction time.

Returns:Iterator<T>

an iterator over the elements of the underlying collection

Annotations
@Override
Exceptions
IllegalStateException:
if this iterable has already been iterated
printStreamback to summary
public IterableProgressBar<T> printStream(PrintStream stream)

Prints the progress bar component to the given PrintStream, followed by a newline.

Parameters
stream:PrintStream

the stream to print to; must not be null

Exceptions
NullPointerException:
if stream is null
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
io.github.kusoroadeolu.clique.components back to summary

private final Record IterableProgressBar.ProgressBarIterator<T>

extends Record
implements Iterator<T>
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Record Components
iterableProgressBar:IterableProgressBar<T> 

Field Summary

Modifier and TypeField and Description
private final IterableProgressBar<T>
iterableProgressBar

Record Component accessed by iterableProgressBar().

Constructor Summary

AccessConstructor and Description
private
ProgressBarIterator(IterableProgressBar<T> iterableProgressBar)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public IterableProgressBar<T>
iterableProgressBar()

Record Component getter of iterableProgressBar.

public T
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

iterableProgressBarback to summary
private final IterableProgressBar<T> iterableProgressBar

Record Component accessed by iterableProgressBar().

Constructor Detail

ProgressBarIteratorback to summary
private ProgressBarIterator(IterableProgressBar<T> iterableProgressBar)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Annotations
@Override
iterableProgressBarback to summary
public IterableProgressBar<T> iterableProgressBar()

Record Component getter of iterableProgressBar.

nextback to summary
public T next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Annotations
@Override
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.