public static Optional<String> validateCanal(final Territory territory,final Route route,final Collection<Unit> units,final PlayerID player,final GameData data){
  Optional<String> failureMessage=Optional.empty();
  final Set<CanalAttachment> canalAttachments=CanalAttachment.get(territory);
  for (  final CanalAttachment canalAttachment : canalAttachments) {
    if (!isCanalOnRoute(canalAttachment,route,data)) {
      continue;
    }
    failureMessage=canPassThroughCanal(canalAttachment,units,player,data);
    final boolean canPass=!failureMessage.isPresent();
    if ((!Properties.getControlAllCanalsBetweenTerritoriesToPass(data) && canPass) || (Properties.getControlAllCanalsBetweenTerritoriesToPass(data) && !canPass)) {
      break;
    }
  }
  return failureMessage;
}

public static Optional < String > validateCanal ( final Territory territory , final Route route , final Collection < Unit > units , final PlayerID player , final GameData data ) { Optional < String > failureMessage = Optional . empty ( ) ; final Set < CanalAttachment > canalAttachments = CanalAttachment . get ( territory ) ; for ( final CanalAttachment canalAttachment : canalAttachments ) { if ( ! isCanalOnRoute ( canalAttachment , route , data ) ) { continue ; } failureMessage = canPassThroughCanal ( canalAttachment , units , player , data ) ; final boolean canPass = ! failureMessage . isPresent ( ) ; if ( ( ! Properties . getControlAllCanalsBetweenTerritoriesToPass ( data ) && canPass ) || ( Properties . getControlAllCanalsBetweenTerritoriesToPass ( data ) && ! canPass ) ) { break ; } } return failureMessage ; }
used for testing a single territory , either as part of a route , or just by itself . returns optional . empty if it can be passed through otherwise returns a failure message indicating why the canal can ' t be passed through .
