Source:
public BakingActionResult checkActionIsApplicableInState(State state, String[] params) { BakingActionResult superResult = super.checkActionIsApplicableInState(state, params); if (!superResult.getIsSuccess()) { return superResult; } String agentName = params[0]; ObjectInstance agent = state.getObject(agentName); if (AgentFactory.isRobot(agent)) { return BakingActionResult.failure(agentName + " cannot perform this action"); } String pouringContainerName = params[1]; ObjectInstance pouringContainer = state.getObject(params[1]); String receivingContainerName = params[2]; ObjectInstance receivingContainer = state.getObject(params[2]); String pouringContainerSpace = ContainerFactory.getSpaceName(pouringContainer); String receivingContainerSpace = ContainerFactory.getSpaceName(receivingContainer); if (ContainerFactory.isEmptyContainer(pouringContainer)) { return BakingActionResult.failure(pouringContainerName + " is empty"); } if (!ContainerFactory.isReceivingContainer(receivingContainer)) { return BakingActionResult.failure(receivingContainerName + " cannot be poured into"); } if (pouringContainerSpace == null || receivingContainerSpace == null) { throw new RuntimeException("One of the pouring containers is not in any space"); } if (!pouringContainerSpace.equalsIgnoreCase(receivingContainerSpace)) { return BakingActionResult.failure(receivingContainerName + " cannot be poured into"); } ObjectInstance pouringContainerSpaceObject = state.getObject(pouringContainerSpace); String agentOfSpace = SpaceFactory.getAgent(pouringContainerSpaceObject).iterator().next(); if (!agentOfSpace.equalsIgnoreCase(agentName)) { return BakingActionResult.failure(agentName + " cannot work in " + pouringContainerSpace); } if (!SpaceFactory.isWorking(pouringContainerSpaceObject)) { return BakingActionResult.failure("Pouring cannot be performed in the " + pouringContainerSpaceObject); } return BakingActionResult.success(); }

Target:
public BakingActionResult checkActionIsApplicableInState(State state, String[] params) { BakingActionResult superResult = super.checkActionIsApplicableInState(state, params); if (!superResult.getIsSuccess()) { return superResult; } String agentName = params[0]; ObjectInstance agent = state.getObject(agentName); if (AgentFactory.isRobot(agent)) { return BakingActionResult.failure(agentName + " cannot perform this action"); } String pouringContainerName = params[1]; ObjectInstance pouringContainer = state.getObject(params[1]); String receivingContainerName = params[2]; ObjectInstance receivingContainer = state.getObject(params[2]); String pouringContainerSpace = ContainerFactory.getSpaceName(pouringContainer); String receivingContainerSpace = ContainerFactory.getSpaceName(receivingContainer); if (ContainerFactory.isEmptyContainer(pouringContainer)) { return BakingActionResult.failure(pouringContainerName + " is empty"); } if (!ContainerFactory.isReceivingContainer(receivingContainer)) { return BakingActionResult.failure(receivingContainerName + " cannot be poured into"); } if (pouringContainerSpace == null || receivingContainerSpace == null) { throw new RuntimeException("One of the pouring containers is not in any space"); } if (!pouringContainerSpace.equalsIgnoreCase(receivingContainerSpace)) { return BakingActionResult.failure(pouringContainerName + " is not in the same space as the " + receivingContainerName); } ObjectInstance pouringContainerSpaceObject = state.getObject(pouringContainerSpace); String agentOfSpace = SpaceFactory.getAgent(pouringContainerSpaceObject).iterator().next(); if (!agentOfSpace.equalsIgnoreCase(agentName)) { return BakingActionResult.failure(agentName + " cannot work in " + pouringContainerSpace); } if (!SpaceFactory.isWorking(pouringContainerSpaceObject)) { return BakingActionResult.failure("Pouring cannot be performed in the " + pouringContainerSpaceObject); } return BakingActionResult.success(); }