<commit_before>// WinFieldViewer.java

package de.htwg.battleship.aview.tui.impl;

import de.htwg.battleship.aview.tui.Viewer;
import de.htwg.battleship.controller.IMasterController;
import de.htwg.battleship.model.IBoard;
import de.htwg.battleship.model.IShip;
import static de.htwg.battleship.util.StatCollection.FIELD_IS_HIT;
import static de.htwg.battleship.util.StatCollection.FIELD_NON_HIT;
import static de.htwg.battleship.util.StatCollection.HEIGTH_LENGTH;
import static de.htwg.battleship.util.StatCollection.SHIP_IS_HIT;
import static de.htwg.battleship.util.StatCollection.SHIP_NON_HIT;
import static de.htwg.battleship.util.StatCollection.createBorder;
import static de.htwg.battleship.util.StatCollection.createMap;
import static de.htwg.battleship.util.StatCollection.fillMap;
import java.util.Map;
import java.util.Set;

/**
 * WinFieldViewer
 * @author <NAME> (<EMAIL>)
 * @version 1.00
 * @since 2014-12-23
 */
public class WinFieldViewer implements Viewer {

    private final IMasterController master;
    private Object player1;
    public WinFieldViewer(final IMasterController master) {
        this.master = master;
    }

    /**
     * Method to get the Field presented as a String.
     * Shows the own Ships on the field. The field which is owned by the
     * Player at the turn is always at the left side.
     * @return String presentation of the Field
     */
    @Override
    public final String getString() {
        StringBuilder sb = new StringBuilder();
        sb.append("\n ");
        Map<Integer, Set<Integer>> mapPlayer1 = createMap();
        Map<Integer, Set<Integer>> mapPlayer2 = createMap();
        IBoard boardPlayer1 = master.getPlayer1().getOwnBoard();
        IShip[] listPlayer1 = master.getPlayer1().getOwnBoard().getShipList();
        fillMap(listPlayer1, mapPlayer1,
                master.getPlayer1().getOwnBoard().getShips());
        IBoard boardPlayer2 = master.getPlayer2().getOwnBoard();
        IShip[] listPlayer2 = master.getPlayer2().getOwnBoard().getShipList();
        fillMap(listPlayer2, mapPlayer2,
                master.getPlayer2().getOwnBoard().getShips());
        sb.append(master.getPlayer1().getName()).append("\t\t");
        sb.append(master.getPlayer2().getName()).append("\n");
        createBorder(sb);
        sb.append("\t  ");
        createBorder(sb);
        sb.append("\n");
        for (int y = 0; y < HEIGTH_LENGTH; y++) {
            sb.append(y);
            for (int x = 0; x < HEIGTH_LENGTH; x++) {
                boolean isShip = false;
                for (Integer value : mapPlayer1.get(y)) {
                    if (value == x) {
                        if (boardPlayer1.isHit(x, y)) {
                            sb.append(SHIP_IS_HIT);
                        } else {
                            sb.append(SHIP_NON_HIT);
                        }
                        isShip = true;
                    }
                }
                if (isShip) {
                    continue;
                }
                if (boardPlayer1.isHit(x, y)) {
                    sb.append(FIELD_IS_HIT);
                } else {
                    sb.append(FIELD_NON_HIT);<commit_msg>removed unused object, added some comments<commit_after>// WinFieldViewer.java

package de.htwg.battleship.aview.tui.impl;

import de.htwg.battleship.aview.tui.Viewer;
import de.htwg.battleship.controller.IMasterController;
import de.htwg.battleship.model.IBoard;
import de.htwg.battleship.model.IShip;
import static de.htwg.battleship.util.StatCollection.FIELD_IS_HIT;
import static de.htwg.battleship.util.StatCollection.FIELD_NON_HIT;
import static de.htwg.battleship.util.StatCollection.HEIGTH_LENGTH;
import static de.htwg.battleship.util.StatCollection.SHIP_IS_HIT;
import static de.htwg.battleship.util.StatCollection.SHIP_NON_HIT;
import static de.htwg.battleship.util.StatCollection.createBorder;
import static de.htwg.battleship.util.StatCollection.createMap;
import static de.htwg.battleship.util.StatCollection.fillMap;
import java.util.Map;
import java.util.Set;

/**
 * WinFieldViewer presents a view of the entire field that means it
 * shows the ships of both players.
 * implements viewer
 * @author <NAME> (<EMAIL>)
 * @version 1.00
 * @since 2014-12-23
 */
public class WinFieldViewer implements Viewer {

    /**
     * Saves the MasterController.
     */
    private final IMasterController master;

    /**
     * Public Constructor.
     * @param master the MasterController for the entire game
     */
    public WinFieldViewer(final IMasterController master) {
        this.master = master;
    }

    /**
     * Method to get the Field presented as a String.
     * Shows the own Ships on the field. The field which is owned by the
     * Player at the turn is always at the left side.
     * @return String presentation of the Field
     */
    @Override
    public final String getString() {
        StringBuilder sb = new StringBuilder();
        sb.append("\n  ");
        Map<Integer, Set<Integer>> mapPlayer1 = createMap();
        Map<Integer, Set<Integer>> mapPlayer2 = createMap();
        IBoard boardPlayer1 = master.getPlayer1().getOwnBoard();
        IShip[] listPlayer1 = master.getPlayer1().getOwnBoard().getShipList();
        fillMap(listPlayer1, mapPlayer1,
                master.getPlayer1().getOwnBoard().getShips());
        IBoard boardPlayer2 = master.getPlayer2().getOwnBoard();
        IShip[] listPlayer2 = master.getPlayer2().getOwnBoard().getShipList();
        fillMap(listPlayer2, mapPlayer2,
                master.getPlayer2().getOwnBoard().getShips());
        sb.append(master.getPlayer1().getName()).append("\t\t");
        sb.append(master.getPlayer2().getName()).append("\n");
        createBorder(sb);
        sb.append("\t ");
        createBorder(sb);
        sb.append("\n");
        for (int y = 0; y < HEIGTH_LENGTH; y++) {
            sb.append(y);
            for (int x = 0; x < HEIGTH_LENGTH; x++) {
                boolean isShip = false;
                for (Integer value : mapPlayer1.get(y)) {
                    if (value == x) {
                        if (boardPlayer1.isHit(x, y)) {
                            sb.append(SHIP_IS_HIT);
                        } else {
                            sb.append(SHIP_NON_HIT);
                        }
                        isShip = true;
                    }
                }
                if (isShip) {
                    continue;
                }
                if (boardPlayer1.isHit(x, y)) {
                    sb.append(FIELD_IS_HIT);
                } else {
                    sb.append(FIELD_NON_HIT);
{'fraction_non_alphanumeric': 0.11348907309721176, 'fraction_numerical': 0.01039939713639789, 'mean_word_length': 2.230769230769231, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6205524', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1978, 'n_words': 410}