Skip to content

Commit

Permalink
Various little fixes of code smells and bugs found by sonarQube
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaPeukert committed Feb 15, 2018
1 parent 6e33ef6 commit a43399f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 56 deletions.
Expand Up @@ -90,12 +90,13 @@ private Collection<String> exportIndexes()
{
throw new IllegalStateException( "Indexes should have at least one property key" );
}
String key = quote( propertyKeys.next() );
String id = propertyKeys.next();
if ( propertyKeys.hasNext() )
{
throw new RuntimeException( "Exporting compound indexes is not implemented yet" );
}

String key = quote( id );
String label = quote( index.getLabel().name() );
result.add( "create index on :" + label + "(" + key + ")" );
}
Expand All @@ -106,8 +107,21 @@ private Collection<String> exportIndexes()

private Collection<String> exportConstraints()
{
final List<String> result = new ArrayList<>();
for ( ConstraintDefinition constraint : graph.getConstraints() )
Iterable<ConstraintDefinition> constraints = graph.getConstraints();
int count = 0;
if ( constraints instanceof Collection )
{
count = ((Collection<ConstraintDefinition>) constraints).size();
}
else
{
for ( ConstraintDefinition ignored : constraints )
{
count++;
}
}
final List<String> result = new ArrayList<>( count );
for ( ConstraintDefinition constraint : constraints )
{
if ( !constraint.isConstraintType( ConstraintType.UNIQUENESS ) )
{
Expand All @@ -119,20 +133,21 @@ private Collection<String> exportConstraints()
{
throw new IllegalStateException( "Constraints should have at least one property key" );
}
String key = quote( propertyKeys.next() );
String id = propertyKeys.next();
if ( propertyKeys.hasNext() )
{
throw new RuntimeException( "Exporting compound constraints is not implemented yet" );
}

String key = quote( id );
String label = quote( constraint.getLabel().name() );
result.add( "create constraint on (n:" + label + ") assert n." + key + " is unique" );
}
Collections.sort( result );
return result;
}

private String quote( String id )
private static String quote( String id )
{
return "`" + id + "`";
}
Expand All @@ -149,7 +164,7 @@ private String labelString( Node node )
while ( labels.hasNext() )
{
Label next = labels.next();
result.append( ":" ).append( quote( next.name() ) );
result.append( ':' ).append( quote( next.name() ) );
}
return result.toString();
}
Expand Down Expand Up @@ -249,7 +264,7 @@ private String formatProperties( PropertyContainer pc )
{
result.append( ", " );
}
result.append( quote( prop ) ).append( ":" );
result.append( quote( prop ) ).append( ':' );
Object value = pc.getProperty( prop );
result.append( toString( value ) );
}
Expand Down Expand Up @@ -286,7 +301,7 @@ private String arrayToString( Object value )
return "[" + result + "]";
}

private String escapeString( String value )
private static String escapeString( String value )
{
return "\"" + value.replaceAll( "\\\\", "\\\\\\\\" ).replaceAll( "\"", "\\\\\"" ) + "\"";
}
Expand Down
Expand Up @@ -765,7 +765,8 @@ public Object next()
{
throw new NoSuchElementException();
}
return Array.get( array, position++ );
int offset = position++;
return Array.get( array, offset );
}
}
}
Expand Up @@ -83,58 +83,57 @@ private void writeValue( Object value )
}

@Override
public void writeNodeReference( long nodeId ) throws RuntimeException
public void writeNodeReference( long nodeId )
{
writeValue( new NodeIdWrapperImpl( nodeId ) );
}

@Override
public void writeNode( long nodeId, TextArray ignore, MapValue properties ) throws RuntimeException
public void writeNode( long nodeId, TextArray ignore, MapValue properties )
{
writeValue( new NodeIdWrapperImpl( nodeId ) );
}

@Override
public void writeRelationshipReference( long relId ) throws RuntimeException
public void writeRelationshipReference( long relId )
{
writeValue( new RelationshipIdWrapperImpl( relId ) );
}

@Override
public void writeRelationship( long relId, long startNodeId, long endNodeId, TextValue type, MapValue properties )
throws RuntimeException
{
writeValue( new RelationshipIdWrapperImpl( relId ) );
}

@Override
public void beginMap( int size ) throws RuntimeException
public void beginMap( int size )
{
stack.push( new MapWriter( size ) );
}

@Override
public void endMap() throws RuntimeException
public void endMap()
{
assert !stack.isEmpty();
writeValue( stack.pop().value() );
}

@Override
public void beginList( int size ) throws RuntimeException
public void beginList( int size )
{
stack.push( new ListWriter( size ) );
}

@Override
public void endList() throws RuntimeException
public void endList()
{
assert !stack.isEmpty();
writeValue( stack.pop().value() );
}

@Override
public void writePath( NodeValue[] nodes, RelationshipValue[] relationships ) throws RuntimeException
public void writePath( NodeValue[] nodes, RelationshipValue[] relationships )
{
assert nodes != null;
assert nodes.length > 0;
Expand Down Expand Up @@ -274,128 +273,128 @@ public void remove()
}

@Override
public void writeNull() throws RuntimeException
public void writeNull()
{
writeValue( null );
}

@Override
public void writeBoolean( boolean value ) throws RuntimeException
public void writeBoolean( boolean value )
{
writeValue( value );
}

@Override
public void writeInteger( byte value ) throws RuntimeException
public void writeInteger( byte value )
{
writeValue( (long) value );
}

@Override
public void writeInteger( short value ) throws RuntimeException
public void writeInteger( short value )
{
writeValue( (long) value );
}

@Override
public void writeInteger( int value ) throws RuntimeException
public void writeInteger( int value )
{
writeValue( (long) value );
}

@Override
public void writeInteger( long value ) throws RuntimeException
public void writeInteger( long value )
{
writeValue( value );
}

@Override
public void writeFloatingPoint( float value ) throws RuntimeException
public void writeFloatingPoint( float value )
{
writeValue( (double) value );
}

@Override
public void writeFloatingPoint( double value ) throws RuntimeException
public void writeFloatingPoint( double value )
{
writeValue( value );
}

@Override
public void writeString( String value ) throws RuntimeException
public void writeString( String value )
{
writeValue( value );
}

@Override
public void writeString( char value ) throws RuntimeException
public void writeString( char value )
{
writeValue( value );
}

@Override
public void beginArray( int size, ArrayType arrayType ) throws RuntimeException
public void beginArray( int size, ArrayType arrayType )
{
stack.push( new ArrayWriter( size, arrayType ) );
}

@Override
public void endArray() throws RuntimeException
public void endArray()
{
assert !stack.isEmpty();
writeValue( stack.pop().value() );
}

@Override
public void writeByteArray( byte[] value ) throws RuntimeException
public void writeByteArray( byte[] value )
{
writeValue( value );
}

@Override
public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) throws RuntimeException
public void writePoint( CoordinateReferenceSystem crs, double[] coordinate )
{
writeValue( Values.pointValue( crs, coordinate ) );
}

@Override
public void writeDuration( long months, long days, long seconds, int nanos ) throws RuntimeException
public void writeDuration( long months, long days, long seconds, int nanos )
{
writeValue( DurationValue.duration( months, days, seconds, nanos ) );
}

@Override
public void writeDate( long epochDay ) throws RuntimeException
public void writeDate( long epochDay )
{
writeValue( LocalDate.ofEpochDay( epochDay ) );
}

@Override
public void writeLocalTime( long nanoOfDay ) throws RuntimeException
public void writeLocalTime( long nanoOfDay )
{
writeValue( LocalTime.ofNanoOfDay( nanoOfDay ) );
}

@Override
public void writeTime( long nanosOfDayUTC, int offsetSeconds ) throws RuntimeException
public void writeTime( long nanosOfDayUTC, int offsetSeconds )
{
writeValue( OffsetTime.of( LocalTime.ofNanoOfDay( nanosOfDayUTC ), ZoneOffset.ofTotalSeconds( offsetSeconds ) ) );
}

@Override
public void writeLocalDateTime( long epochSecond, int nano ) throws RuntimeException
public void writeLocalDateTime( long epochSecond, int nano )
{
writeValue( LocalDateTime.ofInstant( Instant.ofEpochSecond(epochSecond, nano), UTC ) );
}

@Override
public void writeDateTime( long epochSecondUTC, int nano, int offsetSeconds ) throws RuntimeException
public void writeDateTime( long epochSecondUTC, int nano, int offsetSeconds )
{
writeValue( ZonedDateTime.ofInstant( Instant.ofEpochSecond(epochSecondUTC, nano), ZoneOffset.ofTotalSeconds( offsetSeconds ) ) );
}

@Override
public void writeDateTime( long epochSecondUTC, int nano, String zoneId ) throws RuntimeException
public void writeDateTime( long epochSecondUTC, int nano, String zoneId )
{
writeValue( ZonedDateTime.ofInstant( Instant.ofEpochSecond(epochSecondUTC, nano), ZoneId.of( zoneId ) ) );
}
Expand Down Expand Up @@ -501,7 +500,8 @@ private static class ArrayWriter implements Writer
@Override
public void write( Object value )
{
Array.set( array, index++, value );
Array.set( array, index, value );
index++;
}

@Override
Expand Down
Expand Up @@ -117,27 +117,27 @@ final Clock clock()

private static class Query extends Event implements QueryEvent, QueryCompilationEvent
{
private final String query;
private final String queryString;
private final EventListener listener;
private final List<Phase> phases = new ArrayList<>();

Query( Clock clock, String query, EventListener listener )
{
super( clock );
this.query = query;
this.queryString = query;
this.listener = listener;
}

@Override
public String toString()
{
return getClass().getSimpleName() + "[" + query + "]";
return getClass().getSimpleName() + "[" + queryString + "]";
}

@Override
public CompilationPhaseEvent beginPhase( CompilationPhase phase )
{
Phase event = new Phase( clock(), phase );
Phase event = new Phase( super.clock(), phase );
phases.add( event );
return event;
}
Expand All @@ -151,7 +151,7 @@ void done()
@Override
public String query()
{
return query;
return queryString;
}

@Override
Expand All @@ -163,24 +163,24 @@ public List<PhaseEvent> phases()

private static class Phase extends Event implements PhaseEvent, CompilationPhaseTracer.CompilationPhaseEvent
{
private final CompilationPhaseTracer.CompilationPhase phase;
private final CompilationPhaseTracer.CompilationPhase compilationPhase;

Phase( Clock clock, CompilationPhaseTracer.CompilationPhase phase )
{
super( clock );
this.phase = phase;
this.compilationPhase = phase;
}

@Override
public String toString()
{
return getClass().getSimpleName() + "[" + phase + "]";
return getClass().getSimpleName() + "[" + compilationPhase + "]";
}

@Override
public CompilationPhaseTracer.CompilationPhase phase()
{
return phase;
return compilationPhase;
}

@Override
Expand Down

0 comments on commit a43399f

Please sign in to comment.