Skip to content

Commit

Permalink
Simplify RealLocalizableSpliterator interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tpietzsch committed Oct 23, 2023
1 parent 51742fa commit 6f1c445
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,6 @@ public boolean tryAdvance( final Consumer< ? super T > action )
return false;
}

@Override
public boolean tryAdvance()
{
if ( index.get() < fence - 1 )
{
fwd();
return true;
}
return false;
}

private void fwd()
{
index.inc();
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/net/imglib2/img/array/ArraySpliterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ public boolean tryAdvance( final Consumer< ? super T > action )
return false;
}

@Override
public boolean tryAdvance()
{
if ( index.get() < fence - 1 )
{
index.inc();
return true;
}
return false;
}

@Override
public void forEachRemaining( final Consumer< ? super T > action )
{
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/net/imglib2/img/cell/CellSpliterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,34 +119,24 @@ private void cellUpdated()
type.updateContainer( currentCell );
}


@Override
public boolean tryAdvance( final Consumer< ? super T > action )
{
if ( action == null )
throw new NullPointerException();

if ( tryAdvance() )
{
action.accept( type );
return true;
}
return false;
}

@Override
public boolean tryAdvance()
{
if ( index.get() < lastIndexInCurrentCell )
{
index.inc();
action.accept( type );
return true;
}
else if ( currentCell.index() < lastCell )
{
currentCell.fwd();
cellUpdated();
index.set( 0 );
action.accept( type );
return true;
}
else
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/net/imglib2/img/planar/PlanarSpliterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,6 @@ public boolean tryAdvance( final Consumer< ? super T > action )
if ( action == null )
throw new NullPointerException();

if ( tryAdvance() )
{
action.accept( type );
return true;
}
return false;
}

@Override
public boolean tryAdvance()
{
if ( slice >= lastSlice && index.get() >= lastIndexInLastSlice )
return false;

Expand All @@ -138,6 +127,7 @@ public boolean tryAdvance()
type.updateContainer( this );
}

action.accept( type );
return true;
}

Expand Down
12 changes: 0 additions & 12 deletions src/main/java/net/imglib2/stream/CursorSpliterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,6 @@ public boolean tryAdvance( final Consumer< ? super T > action )
return false;
}

@Override
public boolean tryAdvance()
{
if ( index >= 0 && index < fence )
{
++index;
cursor.fwd();
return true;
}
return false;
}

@Override
public CursorSpliterator< T > trySplit()
{
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/net/imglib2/stream/LocalizableSamplerWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ public LocalizableSamplerWrapper< T > copy()
@Override
public void forEachRemaining( final Consumer< ? super LocalizableSampler< T > > action )
{
delegate.forEachRemaining( () -> action.accept( this ) );
delegate.forEachRemaining( t -> action.accept( this ) );
}

@Override
public boolean tryAdvance( final Consumer< ? super LocalizableSampler< T > > action )
{
if ( delegate.tryAdvance() )
{
action.accept( this );
return true;
}
else
return false;
return delegate.tryAdvance( t -> action.accept( this ) );
}

@Override
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/net/imglib2/stream/RealCursorSpliterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ public boolean tryAdvance( final Consumer< ? super T > action )
return false;
}

@Override
public boolean tryAdvance()
{
if ( index >= 0 && index < fence )
{
++index;
cursor.fwd();
return true;
}
return false;
}

@Override
public RealCursorSpliterator< T > trySplit()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,13 @@ public RealLocalizableSamplerWrapper< T > copy()
@Override
public void forEachRemaining( final Consumer< ? super RealLocalizableSampler< T > > action )
{
delegate.forEachRemaining( () -> action.accept( this ) );
delegate.forEachRemaining( t -> action.accept( this ) );
}

@Override
public boolean tryAdvance( final Consumer< ? super RealLocalizableSampler< T > > action )
{
if ( delegate.tryAdvance() )
{
action.accept( this );
return true;
}
else
return false;
return delegate.tryAdvance( t -> action.accept( this ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

public interface RealLocalizableSpliterator< T > extends Spliterator< T >, RealLocalizable, Sampler< T >
{
boolean tryAdvance();

default void forEachRemaining( final Runnable action )
{
forEachRemaining( t -> action.run() );
}

@Override
RealLocalizableSpliterator< T > trySplit();

Expand Down

0 comments on commit 6f1c445

Please sign in to comment.