Skip to content

Commit

Permalink
Address PMD import warnings.
Browse files Browse the repository at this point in the history
Removing unnecessary fully qualified names.
Specify parameter for static import check to allow up to 10 static imports per file.
  • Loading branch information
apcj committed Sep 12, 2013
1 parent f3daa52 commit 888d4fe
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 53 deletions.
11 changes: 10 additions & 1 deletion code-analysis/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@
</rule>
<rule ref="rulesets/java/empty.xml"/>
<rule ref="rulesets/java/finalizers.xml"/>
<rule ref="rulesets/java/imports.xml"/>
<rule ref="rulesets/java/imports.xml/DuplicateImports"/>
<rule ref="rulesets/java/imports.xml/DontImportJavaLang"/>
<rule ref="rulesets/java/imports.xml/UnusedImports"/>
<rule ref="rulesets/java/imports.xml/ImportFromSamePackage"/>
<rule ref="rulesets/java/imports.xml/TooManyStaticImports">
<properties>
<property name="maximumStaticImports" value="10"/>
</properties>
</rule>
<rule ref="rulesets/java/imports.xml/UnnecessaryFullyQualifiedName"/>
<rule ref="rulesets/java/naming.xml">
<exclude name="ShortVariable"/>
<exclude name="LongVariable"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import java.util.Iterator;
import java.util.NoSuchElementException;

import org.neo4j.graphdb.*;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.ResourceIterable;
import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.graphdb.Transaction;

/**
* An {@link Iterator} with additional {@link #size()} and {@link #close()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
*/
package org.neo4j.graphdb.traversal;

import static java.util.Arrays.asList;
import static org.neo4j.graphdb.traversal.Evaluation.INCLUDE_AND_CONTINUE;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -31,6 +27,10 @@
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;

import static java.util.Arrays.asList;

import static org.neo4j.graphdb.traversal.Evaluation.INCLUDE_AND_CONTINUE;

/**
* Common {@link Evaluator}s useful during common traversals.
*
Expand Down Expand Up @@ -365,7 +365,7 @@ public Evaluation evaluate( Path path, BranchState state )
}
else
{
final Set<Node> fullSet = new HashSet<Node>( Arrays.asList( nodes ) );
final Set<Node> fullSet = new HashSet<Node>( asList( nodes ) );
return new PathEvaluator.Adapter()
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import static java.nio.ByteBuffer.wrap;

/**
* Helper class for storing a failure message that happens during an OutOfDisk situation in
* a pre-allocated file
Expand Down Expand Up @@ -64,18 +62,13 @@ public FailureStorage( FolderLayout folderLayout )
public synchronized void reserveForIndex( long indexId ) throws IOException
{
File failureFile = failureFile( indexId );
RandomAccessFile rwFile = new RandomAccessFile( failureFile, "rw" );
try
try ( RandomAccessFile rwFile = new RandomAccessFile( failureFile, "rw" ) )
{
FileChannel channel = rwFile.getChannel();
channel.write( wrap( new byte[ MAX_FAILURE_SIZE ] ) );
channel.write( ByteBuffer.wrap( new byte[MAX_FAILURE_SIZE] ) );
channel.force( true );
channel.close();
}
finally
{
rwFile.close();
}
}

/**
Expand Down Expand Up @@ -118,46 +111,35 @@ public synchronized String loadIndexFailure( long indexId )
public synchronized void storeIndexFailure( long indexId, String failure ) throws IOException
{
File failureFile = failureFile( indexId );
RandomAccessFile rwFile = new RandomAccessFile( failureFile, "rw" );
try
try ( RandomAccessFile rwFile = new RandomAccessFile( failureFile, "rw" ) )
{
FileChannel channel = rwFile.getChannel();
byte[] data = failure.getBytes( "utf-8" );
channel.write( wrap( data, 0, Math.min( data.length, MAX_FAILURE_SIZE ) ) );
channel.write( ByteBuffer.wrap( data, 0, Math.min( data.length, MAX_FAILURE_SIZE ) ) );

channel.force( true );
channel.close();
}
finally
{
rwFile.close();
}
}

private File failureFile( long indexId )
{
File folder = folderLayout.getFolder( indexId );
folder.mkdirs();
File failureFile = new File( folder, failureFileName );
return failureFile;
return new File( folder, failureFileName );
}


private String readFailure( File failureFile ) throws IOException
{
RandomAccessFile rwFile = new RandomAccessFile( failureFile, "r" );
try
try ( RandomAccessFile rwFile = new RandomAccessFile( failureFile, "r" ) )
{
FileChannel channel = rwFile.getChannel();
byte[] data = new byte[ (int) channel.size() ];
int readData = channel.read( wrap( data ) );
byte[] data = new byte[(int) channel.size()];
int readData = channel.read( ByteBuffer.wrap( data ) );
channel.close();

return readData <= 0 ? "" : new String( withoutZeros( data) , "utf-8" );
}
finally
{
rwFile.close();
return readData <= 0 ? "" : new String( withoutZeros( data ), "utf-8" );
}
}

Expand All @@ -182,19 +164,14 @@ private int lengthOf( byte[] data )

private boolean isFailed( File failureFile ) throws IOException
{
RandomAccessFile rFile = new RandomAccessFile( failureFile, "r" );
try
try ( RandomAccessFile rFile = new RandomAccessFile( failureFile, "r" ) )
{
FileChannel channel = rFile.getChannel();
byte[] data = new byte[ (int) channel.size() ];
byte[] data = new byte[(int) channel.size()];
channel.read( ByteBuffer.wrap( data ) );
channel.close();
return !allZero( data );
}
finally
{
rFile.close();
}
}

private boolean allZero( byte[] data )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class StatementTokenNameLookup implements TokenNameLookup
{
private final ReadOperations statement;

public StatementTokenNameLookup( org.neo4j.kernel.api.ReadOperations statement )
public StatementTokenNameLookup( ReadOperations statement )
{
this.statement = statement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ protected IndexConnectionBroker( TransactionManager transactionManager )

public T acquireResourceConnection()
{
T con = null;
Transaction tx = this.getCurrentTransaction();
if ( tx == null )
{
throw new NotInTransactionException();
}
con = txConnectionMap.get( tx );
T con = txConnectionMap.get( tx );
if ( con == null )
{
try
{
con = (T) newConnection();
con = newConnection();
if ( !con.enlistResource( tx ) )
{
throw new RuntimeException( "Unable to enlist '"
Expand All @@ -68,7 +67,7 @@ public T acquireResourceConnection()
String msg = "The transaction is marked for rollback only.";
throw new RuntimeException( msg, re );
}
catch ( javax.transaction.SystemException se )
catch ( SystemException se )
{
String msg = "TM encountered an unexpected error condition.";
throw new RuntimeException( msg, se );
Expand Down Expand Up @@ -109,12 +108,7 @@ void delistResourcesForTransaction() throws NotInTransactionException
{
con.delistResource(tx, XAResource.TMSUCCESS);
}
catch ( IllegalStateException e )
{
throw new RuntimeException(
"Unable to delist lucene resource from tx", e );
}
catch ( SystemException e )
catch ( IllegalStateException | SystemException e )
{
throw new RuntimeException(
"Unable to delist lucene resource from tx", e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public int size()
@Override
public void force()
{
((java.nio.MappedByteBuffer) buffer.getBuffer()).force();
((MappedByteBuffer) buffer.getBuffer()).force();
}

@Override
Expand Down

0 comments on commit 888d4fe

Please sign in to comment.