Skip to content
  • 15 commits
  • 13 files changed
  • 0 commit comments
  • 1 contributor
View
55 .idea/inspectionProfiles/Full_inspection.xml
@@ -1,7 +1,7 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0" is_locked="false">
<option name="myName" value="Full inspection" />
- <option name="myLocal" value="true" />
+ <option name="myLocal" value="false" />
<inspection_tool class="AbsoluteAlignmentInUserInterface" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AbstractClassExtendsConcreteClass" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AbstractClassNeverImplemented" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -142,6 +142,7 @@
<value />
</option>
<option name="ignoreTestCases" value="false" />
+ <option name="ignoreLibraryOverrides" value="false" />
</inspection_tool>
<inspection_tool class="BadExceptionThrown" enabled="true" level="WARNING" enabled_by_default="true">
<option name="exceptionsString" value="" />
@@ -182,10 +183,6 @@
<inspection_tool class="CastToConcreteClass" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="CastToIncompatibleInterface" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ChainedEquality" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="ChainedMethodCall" enabled="true" level="WARNING" enabled_by_default="true">
- <option name="m_ignoreFieldInitializations" value="true" />
- <option name="m_ignoreThisSuperCalls" value="true" />
- </inspection_tool>
<inspection_tool class="ChannelResource" enabled="true" level="WARNING" enabled_by_default="true">
<option name="insideTryAllowed" value="false" />
</inspection_tool>
@@ -305,7 +302,6 @@
<inspection_tool class="CyclicClassDependency" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="CyclicPackageDependency" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="CyclomaticComplexity" enabled="true" level="WARNING" enabled_by_default="true">
- <option name="ignoreEqualsMethod" value="false" />
<option name="m_limit" value="10" />
</inspection_tool>
<inspection_tool class="DateToString" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -323,7 +319,6 @@
<option name="ignoreOnVolatileVariables" value="false" />
</inspection_tool>
<inspection_tool class="DoubleLiteralMayBeFloatLiteral" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="DoubleNegation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="DriverManagerGetConnection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="DuplicateBooleanBranch" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="DuplicateCondition" enabled="true" level="WARNING" enabled_by_default="true">
@@ -611,10 +606,7 @@
<option name="m_maxLength" value="20" />
</inspection_tool>
<inspection_tool class="LocalVariableOfConcreteClass" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="LogStatementGuardedByLogCondition" enabled="true" level="WARNING" enabled_by_default="true">
- <option name="loggerClassName" value="java.util.logging.Logger" />
- <option name="loggerMethodAndconditionMethodNames" value="fine,isLoggable(java.util.logging.Level.FINE),finer,isLoggable(java.util.logging.Level.FINER),finest,isLoggable(java.util.logging.Level.FINEST)" />
- </inspection_tool>
+ <inspection_tool class="LogStatementGuardedByLogCondition" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="true" level="WARNING" enabled_by_default="true">
<option name="loggerClassName" value="org.apache.log4j.Logger" />
<option name="loggerFactoryMethodName" value="getLogger" />
@@ -627,10 +619,7 @@
<inspection_tool class="LoopWithImplicitTerminationCondition" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="LossyEncoding" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="MagicCharacter" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="MagicNumber" enabled="true" level="WARNING" enabled_by_default="true">
- <option name="ignoreInHashCode" value="true" />
- <option name="ignoreInTestCode" value="false" />
- </inspection_tool>
+ <inspection_tool class="MagicNumber" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="MapReplaceableByEnumMap" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="MarkerInterface" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="MethodCanBeVariableArityMethod" enabled="true" level="WARNING" enabled_by_default="true">
@@ -703,6 +692,7 @@
</inspection_tool>
<inspection_tool class="NegatedIfElse" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_ignoreNegatedNullComparison" value="true" />
+ <option name="m_ignoreNegatedZeroComparison" value="false" />
</inspection_tool>
<inspection_tool class="NestedAssignment" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NestedConditionalExpression" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -798,6 +788,7 @@
<inspection_tool class="PackageVisibleField" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PackageVisibleInnerClass" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreEnums" value="false" />
+ <option name="ignoreInterfaces" value="false" />
</inspection_tool>
<inspection_tool class="PackageWithTooFewClasses" enabled="true" level="WARNING" enabled_by_default="true">
<option name="limit" value="3" />
@@ -823,9 +814,7 @@
</inspection_tool>
<inspection_tool class="ParameterOfConcreteClass" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ParameterizedParametersStaticCollection" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="ParametersPerConstructor" enabled="true" level="WARNING" enabled_by_default="true">
- <option name="m_limit" value="5" />
- </inspection_tool>
+ <inspection_tool class="ParametersPerConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ParametersPerMethod" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_limit" value="5" />
</inspection_tool>
@@ -834,6 +823,7 @@
<inspection_tool class="ProtectedField" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ProtectedInnerClass" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreEnums" value="false" />
+ <option name="ignoreInterfaces" value="false" />
</inspection_tool>
<inspection_tool class="ProtectedMemberInFinalClass" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PublicConstructorInNonPublicClass" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -846,6 +836,7 @@
<inspection_tool class="PublicFieldAccessedInSynchronizedContext" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PublicInnerClass" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreEnums" value="false" />
+ <option name="ignoreInterfaces" value="false" />
</inspection_tool>
<inspection_tool class="PublicMethodNotExposedInInterface" enabled="true" level="WARNING" enabled_by_default="true">
<option name="onlyWarnIfContainingClassImplementsAnInterface" value="false" />
@@ -862,10 +853,7 @@
<option name="nameString" value="aa,abc,bad,bar,bar2,baz,baz1,baz2,baz3,bb,blah,bogus,bool,cc,dd,defau1t,dummy,dummy2,ee,fa1se,ff,foo,foo1,foo2,foo3,foobar,four,fred,fred1,fred2,gg,hh,hello,hello1,hello2,hello3,ii,nu11,one,silly,silly2,string,two,that,then,three,whi1e,var" />
</inspection_tool>
<inspection_tool class="RandomDoubleForRandomInteger" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="RawUseOfParameterizedType" enabled="true" level="WARNING" enabled_by_default="true">
- <option name="ignoreObjectConstruction" value="true" />
- <option name="ignoreTypeCasts" value="false" />
- </inspection_tool>
+ <inspection_tool class="RawUseOfParameterizedType" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ReadObjectAndWriteObjectPrivate" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ReadObjectInitialization" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ReadResolveAndWriteReplaceProtected" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -985,6 +973,7 @@
<option name="ignoreThrowableArguments" value="false" />
<option name="ignoreConstantInitializers" value="false" />
<option name="ignoreInTestCode" value="false" />
+ <option name="ignoreInToString" value="false" />
</inspection_tool>
<inspection_tool class="StringConcatenationInFormatCall" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="StringConcatenationInLoops" enabled="true" level="WARNING" enabled_by_default="true">
@@ -1022,6 +1011,7 @@
<inspection_tool class="SynchronizeOnThis" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="SynchronizedMethod" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_includeNativeMethods" value="true" />
+ <option name="ignoreSynchronizedSuperMethods" value="true" />
</inspection_tool>
<inspection_tool class="SynchronizedOnLiteralObject" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="SystemExit" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -1059,6 +1049,7 @@
<inspection_tool class="ThreadYield" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ThreeNegationsPerMethod" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_ignoreInEquals" value="true" />
+ <option name="ignoreInAssert" value="false" />
</inspection_tool>
<inspection_tool class="ThrowCaughtLocally" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreRethrownExceptions" value="false" />
@@ -1070,18 +1061,12 @@
<inspection_tool class="ThrowsRuntimeException" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="TimeToString" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="TodoComment" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="TooBroadCatch" enabled="true" level="WARNING" enabled_by_default="true">
- <option name="onlyWarnOnRootExceptions" value="false" />
- <option name="ignoreInTestCode" value="false" />
- </inspection_tool>
+ <inspection_tool class="TooBroadCatch" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="TooBroadScope" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_allowConstructorAsInitializer" value="false" />
<option name="m_onlyLookAtBlocks" value="false" />
</inspection_tool>
- <inspection_tool class="TooBroadThrows" enabled="true" level="WARNING" enabled_by_default="true">
- <option name="onlyWarnOnRootExceptions" value="false" />
- <option name="ignoreInTestCode" value="false" />
- </inspection_tool>
+ <inspection_tool class="TooBroadThrows" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="TransientFieldInNonSerializableClass" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="TransientFieldNotInitialized" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="TrivialStringConcatenation" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -1137,6 +1122,7 @@
<inspection_tool class="UnnecessaryParentheses" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreClarifyingParentheses" value="true" />
<option name="ignoreParenthesesOnConditionals" value="false" />
+ <option name="ignoreParenthesesOnLambdaParameter" value="false" />
</inspection_tool>
<inspection_tool class="UnnecessaryQualifierForThis" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="UnnecessarySuperConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -1169,10 +1155,17 @@
<inspection_tool class="UseOfProcessBuilder" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="UseOfPropertiesAsHashtable" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="UseOfSunClasses" enabled="true" level="WARNING" enabled_by_default="true" />
- <inspection_tool class="UtilityClass" enabled="true" level="WARNING" enabled_by_default="true" />
+ <inspection_tool class="UtilityClass" enabled="true" level="WARNING" enabled_by_default="true">
+ <option name="ignorableAnnotations">
+ <value />
+ </option>
+ </inspection_tool>
<inspection_tool class="UtilityClassWithPublicConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="UtilityClassWithoutPrivateConstructor" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreClassesWithOnlyMain" value="false" />
+ <option name="ignorableAnnotations">
+ <value />
+ </option>
</inspection_tool>
<inspection_tool class="VariableNotUsedInsideIf" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="VolatileArrayField" enabled="true" level="WARNING" enabled_by_default="true" />
View
2 src/main/java/com/leokom/chess/gui/winboard/GoListener.java
@@ -8,6 +8,6 @@
* spontaneously generating moves for that side each time that side
* has to move again.
*/
-interface GoListener {
+interface GoListener extends NoParametersListener {
void execute();
}
View
9 src/main/java/com/leokom/chess/gui/winboard/IntParameterListener.java
@@ -0,0 +1,9 @@
+package com.leokom.chess.gui.winboard;
+
+/**
+ * Author: Leonid
+ * Date-time: 31.12.12 17:41
+ */
+public interface IntParameterListener {
+ void execute( int paramToPass );
+}
View
9 src/main/java/com/leokom/chess/gui/winboard/NoParametersListener.java
@@ -0,0 +1,9 @@
+package com.leokom.chess.gui.winboard;
+
+/**
+ * Ensure no-parameter winboard listeners share this common interface
+ * to simplify dispatching (inspired by Sonar's complexity measure of the dispatcher)
+ */
+interface NoParametersListener {
+ void execute();
+}
View
2 src/main/java/com/leokom/chess/gui/winboard/OfferDrawListener.java
@@ -5,6 +5,6 @@
* To accept the draw, send "offer draw".
* To decline, ignore the offer (that is, send nothing). If you're playing on ICS, it's possible for the draw offer to have been withdrawn by the time you accept it, so don't assume the game is over because you accept a draw offer. Continue playing until xboard tells you the game is over. See also "offer draw" below.
*/
-interface OfferDrawListener {
+interface OfferDrawListener extends NoParametersListener {
void execute();
}
View
2 src/main/java/com/leokom/chess/gui/winboard/ProtoverListener.java
@@ -13,6 +13,6 @@
* Author: Leonid
* Date-time: 13.11.12 21:37
*/
-interface ProtoverListener {
+interface ProtoverListener extends IntParameterListener {
void execute( int protocolVersion );
}
View
2 src/main/java/com/leokom/chess/gui/winboard/QuitListener.java
@@ -5,6 +5,6 @@
* Author: Leonid
* Date-time: 17.11.12 22:11
*/
-interface QuitListener {
+interface QuitListener extends NoParametersListener {
void execute();
}
View
8 src/main/java/com/leokom/chess/gui/winboard/StringParameterListener.java
@@ -0,0 +1,8 @@
+package com.leokom.chess.gui.winboard;
+
+/**
+ * Ensure int-parameters listeners share common interface (thus easy-to-use)
+ */
+interface StringParameterListener {
+ void execute( String stringParameterToPass );
+}
View
6 src/main/java/com/leokom/chess/gui/winboard/UserMoveListener.java
@@ -4,7 +4,7 @@
* <MOVE> means the move in coordinate notation (4 characters,
* or 5 when a promotion is involved).
*/
-interface UserMoveListener {
- //TODO: provide data about the actual user move
- void execute();
+interface UserMoveListener extends StringParameterListener {
+ //NOTE: move format is currently highly-coupled with Winboard...
+ void execute( String move );
}
View
64 src/main/java/com/leokom/chess/gui/winboard/WinboardCommanderImpl.java
@@ -20,12 +20,12 @@
*/
class WinboardCommanderImpl implements WinboardCommander {
private final Communicator communicator;
- private ProtoverListener protoverListener;
- private QuitListener quitListener;
- private GoListener goListener;
- private UserMoveListener userMoveListener;
- private OfferDrawListener offerDrawListener;
- private XBoardListener xboardListener;
+
+ //we could use adapters
+ //but now I directly force the listeners to extend the interface
+ private final Map<String, NoParametersListener> listenersWithoutParams = new HashMap<String, NoParametersListener>();
+ private final Map<String, StringParameterListener> stringParameterListeners = new HashMap<String, StringParameterListener>();
+ private final Map<String, IntParameterListener> intParameterListeners = new HashMap<String, IntParameterListener>();
/**
* Create the commander, with communicator injected
@@ -82,76 +82,54 @@ public void resign() {
@Override
public void onProtover( ProtoverListener protoverListener ) {
- this.protoverListener = protoverListener;
+ intParameterListeners.put( "protover", protoverListener );
}
@Override
public void onGo( GoListener listener ) {
- this.goListener = listener;
+ listenersWithoutParams.put( "go", listener );
}
@Override
public void onUserMove( UserMoveListener listener ) {
- this.userMoveListener = listener;
+ stringParameterListeners.put( "usermove", listener );
}
@Override
public void onOfferDraw( OfferDrawListener listener ) {
- this.offerDrawListener = listener;
+ listenersWithoutParams.put( "draw", listener );
}
@Override
public void onXBoard( XBoardListener listener ) {
- this.xboardListener = listener;
- }
-
-
- //TODO: either force all listener to implement this interface
- //or make an adapter... Now decided for adapter.
- private Map<String, NoParametersListener> listenersWithoutParams = new HashMap<String, NoParametersListener>();
- interface NoParametersListener {
- void execute();
+ listenersWithoutParams.put( "xboard", listener );
}
@Override
public void onQuit( final QuitListener listener ) {
- this.listenersWithoutParams.put( "quit", new NoParametersListener() {
- @Override
- public void execute() {
- listener.execute();
- }
- } );
- //this.quitListener = listener;
+ listenersWithoutParams.put( "quit", listener );
}
@Override
public void processInputFromServer() {
- String receivedCommand = communicator.receive();
- if ( receivedCommand.startsWith( "protover" ) && protoverListener != null ) {
- //TODO: validation??
- protoverListener.execute( Integer.parseInt(receivedCommand.split( " " )[ 1 ]) );
- }
+ final String receivedCommand = communicator.receive();
for ( String command : listenersWithoutParams.keySet() ) {
if ( receivedCommand.equals( command ) ) {
listenersWithoutParams.get( command ).execute();
}
}
- if ( receivedCommand.equals( "go" ) && goListener != null ) {
- goListener.execute();
- }
-
- if ( receivedCommand.startsWith( "usermove" ) && userMoveListener != null ) {
- userMoveListener.execute();
- }
-
- if ( receivedCommand.equals( "draw" ) && offerDrawListener != null ) {
- offerDrawListener.execute();
+ for ( String command : stringParameterListeners.keySet() ) {
+ if ( receivedCommand.startsWith( command ) ) {
+ stringParameterListeners.get( command ).execute( receivedCommand.split( " " )[ 1 ] );
+ }
}
- if ( receivedCommand.equals( "xboard" ) && xboardListener != null ) {
- xboardListener.execute();
+ for ( String command : intParameterListeners.keySet() ) {
+ if ( receivedCommand.startsWith( command ) ) {
+ intParameterListeners.get( command ).execute( Integer.parseInt( receivedCommand.split( " " )[ 1 ] ) );
+ }
}
}
}
View
5 src/main/java/com/leokom/chess/gui/winboard/WinboardPlayer.java
@@ -56,8 +56,9 @@ public void execute() {
commander.onUserMove( new UserMoveListener() {
@Override
- public void execute() {
- playerMovedListener.onPlayerMoved( null );
+ public void execute( String move ) {
+ //TODO: prove this parameter passing
+ playerMovedListener.onPlayerMoved( move );
}
} );
View
2 src/main/java/com/leokom/chess/gui/winboard/XBoardListener.java
@@ -5,6 +5,6 @@
* You can use it to put your engine into "xboard mode" if that is needed.
* If your engine prints a prompt to ask for user input, you must turn off the prompt and output a newline when the "xboard" command comes in.
*/
-interface XBoardListener {
+interface XBoardListener extends NoParametersListener {
void execute();
}
View
16 src/test/java/com/leokom/chess/gui/winboard/WinBoardCommanderReceiveTest.java
@@ -39,18 +39,28 @@ public void opponentOffersDraw() {
//TODO: I implement only simple test for usermove for 2 reasons:
//1. I want to check if pitest finds it
- //2. I need to check deeper what's the correct format
@Test
- public void userMove() {
+ public void userMove() {
Communicator communicator = getReceiveCommunicator( "usermove e2e4" );
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final UserMoveListener listener = mock( UserMoveListener.class );
commander.onUserMove( listener );
commander.processInputFromServer();
+ verify( listener ).execute( "e2e4" );
+ }
- verify( listener ).execute();
+ @Test
+ public void userMoveTriangulate() {
+ Communicator communicator = getReceiveCommunicator( "usermove e7e5" );
+ WinboardCommander commander = new WinboardCommanderImpl( communicator );
+
+ final UserMoveListener listener = mock( UserMoveListener.class );
+ commander.onUserMove( listener );
+
+ commander.processInputFromServer();
+ verify( listener ).execute( "e7e5" );
}
@Test

No commit comments for this range

Something went wrong with that request. Please try again.