@Test(expected = NullPointerException.class) public void testToPGNNull() { toPGN(null); }
public static String toPGN(final Game pPartie) { if (pPartie == null) { throw new NullPointerException("Missing game description"); } final StringBuilder sb = new StringBuilder(); sb.append("[Event \"" + APPLICATION_NAME + " v" + APPLICATION_VERSION + " chess game\"]\n"); String site = "?"; try { final InetAddress lh = InetAddress.getLocalHost(); site = lh.getHostName(); } catch (final UnknownHostException e) { } sb.append("[Site \"").append(site).append("\"]\n"); sb.append("[Date \"").append(formatPGNDate(new Date())).append("\"]\n"); sb.append("[Round \"-\"]\n"); Player joueur = pPartie.getPlayer(true); String nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[White \"").append(nom).append("\"]\n"); joueur = pPartie.getPlayer(false); nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[Black \"").append(nom).append("\"]\n"); final String resultat; switch (pPartie.getState()) { case BLACK_MATES : resultat = "0-1"; break; case DRAWN_BY_50_MOVE_RULE : case DRAWN_BY_TRIPLE_REPETITION : case STALEMATE : resultat = "1/2-1/2"; break; case WHITE_MATES : resultat = "1-0"; break; case IN_PROGRESS : resultat = "*"; break; default : resultat = "*"; assert false; } sb.append("[Result \"").append(resultat).append("\"]\n"); final String depart = pPartie.getStartingPosition(); if (!depart.equals(STANDART_STARTING_FEN)) { sb.append("[SetUp \"1\"]\n"); sb.append("[FEN \"" + depart + "\"]\n"); } sb.append('\n'); int col = 0; for (final String san : pPartie.getSANStrings()) { String pgn = san.replace("0-0-0", "O-O-O"); pgn = pgn.replace("0-0", "O-O"); pgn = pgn.replace("++", "#"); final int l = pgn.length(); col += l; if (col >= 80) { sb.append('\n'); col = l; } sb.append(pgn); } col += resultat.length(); if (col >= 80) { sb.append('\n'); } sb.append(resultat).append('\n'); return sb.toString(); }
PGNUtils { public static String toPGN(final Game pPartie) { if (pPartie == null) { throw new NullPointerException("Missing game description"); } final StringBuilder sb = new StringBuilder(); sb.append("[Event \"" + APPLICATION_NAME + " v" + APPLICATION_VERSION + " chess game\"]\n"); String site = "?"; try { final InetAddress lh = InetAddress.getLocalHost(); site = lh.getHostName(); } catch (final UnknownHostException e) { } sb.append("[Site \"").append(site).append("\"]\n"); sb.append("[Date \"").append(formatPGNDate(new Date())).append("\"]\n"); sb.append("[Round \"-\"]\n"); Player joueur = pPartie.getPlayer(true); String nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[White \"").append(nom).append("\"]\n"); joueur = pPartie.getPlayer(false); nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[Black \"").append(nom).append("\"]\n"); final String resultat; switch (pPartie.getState()) { case BLACK_MATES : resultat = "0-1"; break; case DRAWN_BY_50_MOVE_RULE : case DRAWN_BY_TRIPLE_REPETITION : case STALEMATE : resultat = "1/2-1/2"; break; case WHITE_MATES : resultat = "1-0"; break; case IN_PROGRESS : resultat = "*"; break; default : resultat = "*"; assert false; } sb.append("[Result \"").append(resultat).append("\"]\n"); final String depart = pPartie.getStartingPosition(); if (!depart.equals(STANDART_STARTING_FEN)) { sb.append("[SetUp \"1\"]\n"); sb.append("[FEN \"" + depart + "\"]\n"); } sb.append('\n'); int col = 0; for (final String san : pPartie.getSANStrings()) { String pgn = san.replace("0-0-0", "O-O-O"); pgn = pgn.replace("0-0", "O-O"); pgn = pgn.replace("++", "#"); final int l = pgn.length(); col += l; if (col >= 80) { sb.append('\n'); col = l; } sb.append(pgn); } col += resultat.length(); if (col >= 80) { sb.append('\n'); } sb.append(resultat).append('\n'); return sb.toString(); } }
PGNUtils { public static String toPGN(final Game pPartie) { if (pPartie == null) { throw new NullPointerException("Missing game description"); } final StringBuilder sb = new StringBuilder(); sb.append("[Event \"" + APPLICATION_NAME + " v" + APPLICATION_VERSION + " chess game\"]\n"); String site = "?"; try { final InetAddress lh = InetAddress.getLocalHost(); site = lh.getHostName(); } catch (final UnknownHostException e) { } sb.append("[Site \"").append(site).append("\"]\n"); sb.append("[Date \"").append(formatPGNDate(new Date())).append("\"]\n"); sb.append("[Round \"-\"]\n"); Player joueur = pPartie.getPlayer(true); String nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[White \"").append(nom).append("\"]\n"); joueur = pPartie.getPlayer(false); nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[Black \"").append(nom).append("\"]\n"); final String resultat; switch (pPartie.getState()) { case BLACK_MATES : resultat = "0-1"; break; case DRAWN_BY_50_MOVE_RULE : case DRAWN_BY_TRIPLE_REPETITION : case STALEMATE : resultat = "1/2-1/2"; break; case WHITE_MATES : resultat = "1-0"; break; case IN_PROGRESS : resultat = "*"; break; default : resultat = "*"; assert false; } sb.append("[Result \"").append(resultat).append("\"]\n"); final String depart = pPartie.getStartingPosition(); if (!depart.equals(STANDART_STARTING_FEN)) { sb.append("[SetUp \"1\"]\n"); sb.append("[FEN \"" + depart + "\"]\n"); } sb.append('\n'); int col = 0; for (final String san : pPartie.getSANStrings()) { String pgn = san.replace("0-0-0", "O-O-O"); pgn = pgn.replace("0-0", "O-O"); pgn = pgn.replace("++", "#"); final int l = pgn.length(); col += l; if (col >= 80) { sb.append('\n'); col = l; } sb.append(pgn); } col += resultat.length(); if (col >= 80) { sb.append('\n'); } sb.append(resultat).append('\n'); return sb.toString(); } private  PGNUtils(); }
PGNUtils { public static String toPGN(final Game pPartie) { if (pPartie == null) { throw new NullPointerException("Missing game description"); } final StringBuilder sb = new StringBuilder(); sb.append("[Event \"" + APPLICATION_NAME + " v" + APPLICATION_VERSION + " chess game\"]\n"); String site = "?"; try { final InetAddress lh = InetAddress.getLocalHost(); site = lh.getHostName(); } catch (final UnknownHostException e) { } sb.append("[Site \"").append(site).append("\"]\n"); sb.append("[Date \"").append(formatPGNDate(new Date())).append("\"]\n"); sb.append("[Round \"-\"]\n"); Player joueur = pPartie.getPlayer(true); String nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[White \"").append(nom).append("\"]\n"); joueur = pPartie.getPlayer(false); nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[Black \"").append(nom).append("\"]\n"); final String resultat; switch (pPartie.getState()) { case BLACK_MATES : resultat = "0-1"; break; case DRAWN_BY_50_MOVE_RULE : case DRAWN_BY_TRIPLE_REPETITION : case STALEMATE : resultat = "1/2-1/2"; break; case WHITE_MATES : resultat = "1-0"; break; case IN_PROGRESS : resultat = "*"; break; default : resultat = "*"; assert false; } sb.append("[Result \"").append(resultat).append("\"]\n"); final String depart = pPartie.getStartingPosition(); if (!depart.equals(STANDART_STARTING_FEN)) { sb.append("[SetUp \"1\"]\n"); sb.append("[FEN \"" + depart + "\"]\n"); } sb.append('\n'); int col = 0; for (final String san : pPartie.getSANStrings()) { String pgn = san.replace("0-0-0", "O-O-O"); pgn = pgn.replace("0-0", "O-O"); pgn = pgn.replace("++", "#"); final int l = pgn.length(); col += l; if (col >= 80) { sb.append('\n'); col = l; } sb.append(pgn); } col += resultat.length(); if (col >= 80) { sb.append('\n'); } sb.append(resultat).append('\n'); return sb.toString(); } private  PGNUtils(); static Game toGame(final BufferedReader pFlux); static String toNormalizedSAN(final String pChaine); static String toPGN(final Game pPartie); }
PGNUtils { public static String toPGN(final Game pPartie) { if (pPartie == null) { throw new NullPointerException("Missing game description"); } final StringBuilder sb = new StringBuilder(); sb.append("[Event \"" + APPLICATION_NAME + " v" + APPLICATION_VERSION + " chess game\"]\n"); String site = "?"; try { final InetAddress lh = InetAddress.getLocalHost(); site = lh.getHostName(); } catch (final UnknownHostException e) { } sb.append("[Site \"").append(site).append("\"]\n"); sb.append("[Date \"").append(formatPGNDate(new Date())).append("\"]\n"); sb.append("[Round \"-\"]\n"); Player joueur = pPartie.getPlayer(true); String nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[White \"").append(nom).append("\"]\n"); joueur = pPartie.getPlayer(false); nom = joueur.getName(); if (joueur.getEngine() != null) { nom = APPLICATION_NAME + '.' + nom; } sb.append("[Black \"").append(nom).append("\"]\n"); final String resultat; switch (pPartie.getState()) { case BLACK_MATES : resultat = "0-1"; break; case DRAWN_BY_50_MOVE_RULE : case DRAWN_BY_TRIPLE_REPETITION : case STALEMATE : resultat = "1/2-1/2"; break; case WHITE_MATES : resultat = "1-0"; break; case IN_PROGRESS : resultat = "*"; break; default : resultat = "*"; assert false; } sb.append("[Result \"").append(resultat).append("\"]\n"); final String depart = pPartie.getStartingPosition(); if (!depart.equals(STANDART_STARTING_FEN)) { sb.append("[SetUp \"1\"]\n"); sb.append("[FEN \"" + depart + "\"]\n"); } sb.append('\n'); int col = 0; for (final String san : pPartie.getSANStrings()) { String pgn = san.replace("0-0-0", "O-O-O"); pgn = pgn.replace("0-0", "O-O"); pgn = pgn.replace("++", "#"); final int l = pgn.length(); col += l; if (col >= 80) { sb.append('\n'); col = l; } sb.append(pgn); } col += resultat.length(); if (col >= 80) { sb.append('\n'); } sb.append(resultat).append('\n'); return sb.toString(); } private  PGNUtils(); static Game toGame(final BufferedReader pFlux); static String toNormalizedSAN(final String pChaine); static String toPGN(final Game pPartie);  }