Skip to content

Commit

Permalink
Replace anonymous inner classes with lambdas
Browse files Browse the repository at this point in the history
This change also almost 100% mechanical, with a few manual fix-ups to fix
checkstyle and compilation issues.
  • Loading branch information
chrisvest committed May 30, 2017
1 parent e4d5b89 commit 12c69d5
Show file tree
Hide file tree
Showing 220 changed files with 1,783 additions and 3,803 deletions.
Expand Up @@ -48,17 +48,13 @@ public static byte[] chunk( int maxChunkSize, byte[][] messages ) throws IOExcep

Channel ch = mock( Channel.class );
when( ch.alloc() ).thenReturn( UnpooledByteBufAllocator.DEFAULT );
when( ch.writeAndFlush( any(), any( ChannelPromise.class ) ) ).then( new Answer<Object>()
when( ch.writeAndFlush( any(), any( ChannelPromise.class ) ) ).then( inv ->
{
@Override
public Object answer( InvocationOnMock inv ) throws Throwable
{
ByteBuf buf = (ByteBuf) inv.getArguments()[0];
outputBuffer.limit( outputBuffer.position() + buf.readableBytes() );
buf.readBytes( outputBuffer );
buf.release();
return null;
}
ByteBuf buf = (ByteBuf) inv.getArguments()[0];
outputBuffer.limit( outputBuffer.position() + buf.readableBytes() );
buf.readBytes( outputBuffer );
buf.release();
return null;
} );

ChunkedOutput out = new ChunkedOutput( ch, maxChunkSize + 2 /* for chunk header */ );
Expand Down
Expand Up @@ -25,12 +25,8 @@

interface WarningsHandler
{
WarningsHandler NO_WARNINGS_HANDLER = new WarningsHandler()
WarningsHandler NO_WARNINGS_HANDLER = diagnostics ->
{
@Override
public void handle( List<Diagnostic<? extends JavaFileObject>> diagnostics )
{
}
};

void handle( List<Diagnostic<? extends JavaFileObject>> diagnostics );
Expand Down
Expand Up @@ -34,12 +34,9 @@ public class ExceptionHandlingIterableTest
@Test( expected = IllegalStateException.class )
public void testHandleExceptionOnIteratorCreation()
{
Iterables.count( new ExceptionHandlingIterable( new Iterable()
Iterables.count( new ExceptionHandlingIterable( () ->
{
public Iterator iterator()
{
throw new RuntimeException( "exception on iterator" );
}
throw new RuntimeException( "exception on iterator" );
} )
{
protected Iterator exceptionOnIterator( Throwable t )
Expand All @@ -53,26 +50,20 @@ protected Iterator exceptionOnIterator( Throwable t )
@Test( expected = IllegalStateException.class )
public void testHandleExceptionOnNext()
{
Iterables.count( new ExceptionHandlingIterable( new Iterable()
Iterables.count( new ExceptionHandlingIterable( () -> new Iterator()
{
public Iterator iterator()
public boolean hasNext()
{
return new Iterator()
{
public boolean hasNext()
{
return true;
}
return true;
}

public Object next()
{
throw new RuntimeException( "exception on next" );
}
public Object next()
{
throw new RuntimeException( "exception on next" );
}

public void remove()
{
}
};
public void remove()
{
}
} )
{
Expand All @@ -88,26 +79,20 @@ protected Object exceptionOnNext( Throwable t )
@Test( expected = IllegalStateException.class )
public void testHandleExceptionOnHasNext()
{
Iterables.count( new ExceptionHandlingIterable( new Iterable()
Iterables.count( new ExceptionHandlingIterable( () -> new Iterator()
{
public Iterator iterator()
public boolean hasNext()
{
return new Iterator()
{
public boolean hasNext()
{
throw new RuntimeException( "exception on next" );
}
throw new RuntimeException( "exception on next" );
}

public Object next()
{
return null;
}
public Object next()
{
return null;
}

public void remove()
{
}
};
public void remove()
{
}
} )
{
Expand Down
6 changes: 1 addition & 5 deletions community/common/src/test/java/org/neo4j/test/Barrier.java
Expand Up @@ -34,12 +34,8 @@
*/
public interface Barrier
{
Barrier NONE = new Barrier()
Barrier NONE = () ->
{
@Override
public void reached()
{
}
};

void reached();
Expand Down
Expand Up @@ -41,30 +41,24 @@ public class NodeDynamicLabelOrphanChainStartCheck

private static final
ComparativeRecordChecker<DynamicRecord, NodeRecord, DynamicLabelConsistencyReport> VALID_NODE_RECORD =
new ComparativeRecordChecker<DynamicRecord, NodeRecord, DynamicLabelConsistencyReport>()
( record, nodeRecord, engine, records ) ->
{
@Override
public void checkReference( DynamicRecord record, NodeRecord nodeRecord,
CheckerEngine<DynamicRecord, DynamicLabelConsistencyReport> engine,
RecordAccess records )
if ( ! nodeRecord.inUse() )
{
if ( ! nodeRecord.inUse() )
{
// if this node record is not in use it is not a valid owner
engine.report().orphanDynamicLabelRecordDueToInvalidOwner( nodeRecord );
}
else
// if this node record is not in use it is not a valid owner
engine.report().orphanDynamicLabelRecordDueToInvalidOwner( nodeRecord );
}
else
{
// if this node record is in use but doesn't point to the dynamic label record
// that label record has an invalid owner
long recordId = record.getId();
if ( fieldPointsToDynamicRecordOfLabels( nodeRecord.getLabelField() ) )
{
// if this node record is in use but doesn't point to the dynamic label record
// that label record has an invalid owner
long recordId = record.getId();
if ( fieldPointsToDynamicRecordOfLabels( nodeRecord.getLabelField() ) )
long dynamicLabelRecordId = firstDynamicLabelRecordId( nodeRecord.getLabelField() );
if ( dynamicLabelRecordId != recordId )
{
long dynamicLabelRecordId = firstDynamicLabelRecordId( nodeRecord.getLabelField() );
if ( dynamicLabelRecordId != recordId )
{
engine.report().orphanDynamicLabelRecordDueToInvalidOwner( nodeRecord );
}
engine.report().orphanDynamicLabelRecordDueToInvalidOwner( nodeRecord );
}
}
}
Expand Down
Expand Up @@ -68,26 +68,20 @@ void wrongOwner( ConsistencyReport.PropertyConsistencyReport report )

private final ComparativeRecordChecker<PropertyRecord, PrimitiveRecord, ConsistencyReport.PropertyConsistencyReport>
OWNER_CHECK =
new ComparativeRecordChecker<PropertyRecord, PrimitiveRecord, ConsistencyReport.PropertyConsistencyReport>()
( record, owner, engine, records ) ->
{
@Override
public void checkReference( PropertyRecord record, PrimitiveRecord owner,
CheckerEngine<PropertyRecord, ConsistencyReport.PropertyConsistencyReport> engine,
RecordAccess records )
if ( !owner.inUse() && !record.inUse() )
{
if ( !owner.inUse() && !record.inUse() )
{
return;
}
if ( !owner.inUse() || Record.NO_NEXT_PROPERTY.is( owner.getNextProp() ) )
{
wrongOwner( engine.report() );
}
else if ( owner.getNextProp() != record.getId() )
{
engine.comparativeCheck( property( records, owner.getNextProp() ),
OwnerChain.this );
}
return;
}
if ( !owner.inUse() || Record.NO_NEXT_PROPERTY.is( owner.getNextProp() ) )
{
wrongOwner( engine.report() );
}
else if ( owner.getNextProp() != record.getId() )
{
engine.comparativeCheck( property( records, owner.getNextProp() ),
OwnerChain.this );
}
};

Expand Down
Expand Up @@ -34,30 +34,25 @@ public abstract class PrimitiveRecordCheck
{
private final RecordField<RECORD, REPORT>[] fields;
private final ComparativeRecordChecker<RECORD, PrimitiveRecord, REPORT> ownerCheck =
new ComparativeRecordChecker<RECORD, PrimitiveRecord, REPORT>()
( record, other, engine, records ) ->
{
@Override
public void checkReference( RECORD record, PrimitiveRecord other, CheckerEngine<RECORD, REPORT> engine,
RecordAccess records )
if ( record.getId() == other.getId() && record.getClass() == other.getClass() )
{
if ( record.getId() == other.getId() && record.getClass() == other.getClass() )
{
// Owner identities match. Things are as they should be.
return;
}
// Owner identities match. Things are as they should be.
return;
}

if ( other instanceof NodeRecord )
{
engine.report().multipleOwners( (NodeRecord) other );
}
else if ( other instanceof RelationshipRecord )
{
engine.report().multipleOwners( (RelationshipRecord) other );
}
else if ( other instanceof NeoStoreRecord )
{
engine.report().multipleOwners( (NeoStoreRecord) other );
}
if ( other instanceof NodeRecord )
{
engine.report().multipleOwners( (NodeRecord) other );
}
else if ( other instanceof RelationshipRecord )
{
engine.report().multipleOwners( (RelationshipRecord) other );
}
else if ( other instanceof NeoStoreRecord )
{
engine.report().multipleOwners( (NeoStoreRecord) other );
}
};

Expand Down
Expand Up @@ -269,50 +269,31 @@ private void checkForDuplicates( SchemaRule rule, DynamicRecord record,

private static final ComparativeRecordChecker<DynamicRecord,LabelTokenRecord,
ConsistencyReport.SchemaConsistencyReport> VALID_LABEL =
new ComparativeRecordChecker<DynamicRecord, LabelTokenRecord, ConsistencyReport.SchemaConsistencyReport>()
{
@Override
public void checkReference( DynamicRecord record, LabelTokenRecord labelTokenRecord,
CheckerEngine<DynamicRecord, ConsistencyReport.SchemaConsistencyReport> engine,
RecordAccess records )
{
if ( !labelTokenRecord.inUse() )
( record, labelTokenRecord, engine, records ) ->
{
engine.report().labelNotInUse( labelTokenRecord );
}
}
};
if ( !labelTokenRecord.inUse() )
{
engine.report().labelNotInUse( labelTokenRecord );
}
};

private static final ComparativeRecordChecker<DynamicRecord,RelationshipTypeTokenRecord,
ConsistencyReport.SchemaConsistencyReport> VALID_RELATIONSHIP_TYPE =
new ComparativeRecordChecker<DynamicRecord, RelationshipTypeTokenRecord,
ConsistencyReport.SchemaConsistencyReport>()
{
@Override
public void checkReference( DynamicRecord record, RelationshipTypeTokenRecord relTypeTokenRecord,
CheckerEngine<DynamicRecord, ConsistencyReport.SchemaConsistencyReport> engine,
RecordAccess records )
{
if ( !relTypeTokenRecord.inUse() )
( record, relTypeTokenRecord, engine, records ) ->
{
engine.report().relationshipTypeNotInUse( relTypeTokenRecord );
}
}
};
if ( !relTypeTokenRecord.inUse() )
{
engine.report().relationshipTypeNotInUse( relTypeTokenRecord );
}
};

private static final ComparativeRecordChecker<DynamicRecord, PropertyKeyTokenRecord,
ConsistencyReport.SchemaConsistencyReport> VALID_PROPERTY_KEY =
new ComparativeRecordChecker<DynamicRecord, PropertyKeyTokenRecord, ConsistencyReport.SchemaConsistencyReport>()
{
@Override
public void checkReference( DynamicRecord record, PropertyKeyTokenRecord propertyKeyTokenRecord,
CheckerEngine<DynamicRecord, ConsistencyReport.SchemaConsistencyReport> engine,
RecordAccess records )
{
if ( !propertyKeyTokenRecord.inUse() )
( record, propertyKeyTokenRecord, engine, records ) ->
{
engine.report().propertyKeyNotInUse( propertyKeyTokenRecord );
}
}
};
if ( !propertyKeyTokenRecord.inUse() )
{
engine.report().propertyKeyNotInUse( propertyKeyTokenRecord );
}
};
}
Expand Up @@ -40,16 +40,7 @@ abstract class DynamicOwner<RECORD extends AbstractBaseRecord> implements Owner
{
static final ComparativeRecordChecker<DynamicRecord, AbstractBaseRecord, ConsistencyReport.DynamicConsistencyReport>
ORPHAN_CHECK =
new ComparativeRecordChecker<DynamicRecord, AbstractBaseRecord, ConsistencyReport.DynamicConsistencyReport>()
{
@Override
public void checkReference( DynamicRecord record, AbstractBaseRecord ignored,
CheckerEngine<DynamicRecord, ConsistencyReport.DynamicConsistencyReport> engine,
RecordAccess records )
{
engine.report().orphanDynamicRecord();
}
};
( record, ignored, engine, records ) -> engine.report().orphanDynamicRecord();

abstract RecordReference<RECORD> record( RecordAccess records );

Expand Down

0 comments on commit 12c69d5

Please sign in to comment.