Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/java/net/imglib2/util/Partition.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;

/**
* TODO
Expand Down Expand Up @@ -685,6 +686,10 @@ else if ( j == i )
*/
public static < T > void partitionSubList( final ListIterator< T > i, final ListIterator< T > j, final Comparator< ? super T > compare )
{
if ( !i.hasNext() || !j.hasPrevious() )
{
throw new NoSuchElementException( "Invalid iterators for partitioning a sublist." );
}
final int pivotIndex = j.previousIndex();
final T pivot = j.previous();

Expand All @@ -693,6 +698,10 @@ public static < T > void partitionSubList( final ListIterator< T > i, final List
// move i forward while < pivot (and not at j)
while ( i.nextIndex() - 1 <= j.previousIndex() )
{
if( !i.hasNext() )
{
throw new NoSuchElementException( "Invalid iterator for partitioning a sublist. ");
}
final T ti = i.next();
if ( compare.compare( ti, pivot ) >= 0 )
{
Expand Down Expand Up @@ -760,6 +769,10 @@ else if ( j.previousIndex() == i.nextIndex() - 1 )
*/
public static < T extends Comparable< T > > void partitionSubList( final ListIterator< T > i, final ListIterator< T > j )
{
if ( !i.hasNext() || !j.hasPrevious() )
{
throw new NoSuchElementException( "Invalid iterators for partitioning a sublist." );
}
final int pivotIndex = j.previousIndex();
final T pivot = j.previous();

Expand All @@ -768,6 +781,10 @@ public static < T extends Comparable< T > > void partitionSubList( final ListIte
// move i forward while < pivot (and not at j)
while ( i.nextIndex() - 1 <= j.previousIndex() )
{
if( !i.hasNext() )
{
throw new NoSuchElementException( "Invalid iterator for partitioning a sublist. ");
}
final T ti = i.next();
if ( ti.compareTo( pivot ) >= 0 )
{
Expand Down Expand Up @@ -1028,6 +1045,10 @@ else if ( j == i )
*/
public static < T > void partitionSubList( final ListIterator< T > i, final ListIterator< T > j, final int[] permutation, final Comparator< ? super T > compare )
{
if ( !i.hasNext() || !j.hasPrevious() )
{
throw new NoSuchElementException( "Invalid iterators for partitioning a sublist." );
}
final int pivotIndex = j.previousIndex();
final int permutationPivot = permutation[ pivotIndex ];
final T pivot = j.previous();
Expand All @@ -1037,6 +1058,10 @@ public static < T > void partitionSubList( final ListIterator< T > i, final List
// move i forward while < pivot (and not at j)
while ( i.nextIndex() - 1 <= j.previousIndex() )
{
if( !i.hasNext() )
{
throw new NoSuchElementException( "Invalid iterator for partitioning a sublist. ");
}
final T ti = i.next();
if ( compare.compare( ti, pivot ) >= 0 )
{
Expand Down Expand Up @@ -1124,6 +1149,10 @@ public static < T extends Comparable< T > > void partitionSubList( final ListIte
// move i forward while < pivot (and not at j)
while ( i.nextIndex() - 1 <= j.previousIndex() )
{
if( !i.hasNext() )
{
throw new NoSuchElementException( "Invalid iterator for partitioning a sublist. ");
}
final T ti = i.next();
if ( ti.compareTo( pivot ) >= 0 )
{
Expand Down