<commit_before>
package com.funnyhatsoftware.spacedock.data;

import android.text.TextUtils;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;

public class EquippedShip extends EquippedShipBase {

    private static final String TAG = "EquippedShip";

    public EquippedShip() {
        super();
    }

    public EquippedShip(Ship inShip, boolean establishPlaceholders) {
        super();
        mShip = inShip;
        if (establishPlaceholders) {
            establishPlaceholders();
        }
    }

    public EquippedShip(Ship inShip) {
        super();
        mShip = inShip;
    }

    public boolean isResourceSideboard() {
        return false;
    }

    public String getShipExternalId() {
        if (mShip == null) {
            return "[sideboard]";
        }
        return mShip.getExternalId();
    }

    public EquippedUpgrade addUpgrade(Upgrade upgrade) {
        return addUpgrade(upgrade, null, true);
    }

    public EquippedUpgrade addUpgrade(Upgrade upgrade,
            EquippedUpgrade maybeReplace, boolean establishPlaceholders) {
        EquippedUpgrade eu = new EquippedUpgrade();
        if (upgrade == null) {
            return eu;
        }
        String upType = upgrade.getUpType();
        eu.setUpgrade(upgrade);
        if (!upgrade.isPlaceholder()) {
            EquippedUpgrade ph = findPlaceholder(upType);
            if (ph != null) {
                removeUpgrade(ph);
            }
        }
        int limit = upgrade.limitForShip(this);
        int current = equipped(upType);
        if (current == limit) {
            if (maybeReplace == null) {
                maybeReplace = firstUpgrade(upType);
            }

            removeUpgrade(maybeReplace, false);
        }

        mUpgrades.add(eu);
        eu.setEquippedShip(this);

        if (establishPlaceholders) {
            establishPlaceholders();
        }
        return eu;
    }

    private EquippedUpgrade firstUpgrade(String upType) {

        for (EquippedUpgrade eu : mUpgrades) {
            if (upType.equals(eu.getUpgrade().getUpType())) {
                return eu;
            }
        }

        return null;
    }

    private EquippedUpgrade findPlaceholder(String upType) {

        for (EquippedUpgrade eu : mUpgrades) {
            if (eu.isPlaceholder()
                    && upType.equals(eu.getUpgrade().getUpType())) {
                return eu;
            }
        }

        return null;
    }

    public void removeUpgrade(EquippedUpgrade eu) {
        removeUpgrade(eu, true);
    }

    private void removeUpgrade(EquippedUpgrade eu, boolean establishPlaceholders) {
        if (eu != null) {
            mUpgrades.remove(eu);
            eu.setEquippedShip(null);
            if (establishPlaceholders) {
                establishPlaceholders();
            }
        }
    }

    public int calculateCost() {
        int cost = 0;
        if (mShip != null) {
            cost = mShip.getCost();
        }

        for (EquippedUpgrade eu : mUpgrades) {
            cost += eu.calculateCost();
        }

        if (getFlagship() != null) {
            cost += 10;
        }<commit_msg>Adding code to include fleet captain cost.<commit_after>
package com.funnyhatsoftware.spacedock.data;

import android.text.TextUtils;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;

public class EquippedShip extends EquippedShipBase {

    private static final String TAG = "EquippedShip";

    public EquippedShip() {
        super();
    }

    public EquippedShip(Ship inShip, boolean establishPlaceholders) {
        super();
        mShip = inShip;
        if (establishPlaceholders) {
            establishPlaceholders();
        }
    }

    public EquippedShip(Ship inShip) {
        super();
        mShip = inShip;
    }

    public boolean isResourceSideboard() {
        return false;
    }

    public String getShipExternalId() {
        if (mShip == null) {
            return "[sideboard]";
        }
        return mShip.getExternalId();
    }

    public EquippedUpgrade addUpgrade(Upgrade upgrade) {
        return addUpgrade(upgrade, null, true);
    }

    public EquippedUpgrade addUpgrade(Upgrade upgrade,
            EquippedUpgrade maybeReplace, boolean establishPlaceholders) {
        EquippedUpgrade eu = new EquippedUpgrade();
        if (upgrade == null) {
            return eu;
        }
        String upType = upgrade.getUpType();
        eu.setUpgrade(upgrade);
        if (!upgrade.isPlaceholder()) {
            EquippedUpgrade ph = findPlaceholder(upType);
            if (ph != null) {
                removeUpgrade(ph);
            }
        }
        int limit = upgrade.limitForShip(this);
        int current = equipped(upType);
        if (current == limit) {
            if (maybeReplace == null) {
                maybeReplace = firstUpgrade(upType);
            }

            removeUpgrade(maybeReplace, false);
        }

        mUpgrades.add(eu);
        eu.setEquippedShip(this);

        if (establishPlaceholders) {
            establishPlaceholders();
        }
        return eu;
    }

    private EquippedUpgrade firstUpgrade(String upType) {

        for (EquippedUpgrade eu : mUpgrades) {
            if (upType.equals(eu.getUpgrade().getUpType())) {
                return eu;
            }
        }

        return null;
    }

    private EquippedUpgrade findPlaceholder(String upType) {

        for (EquippedUpgrade eu : mUpgrades) {
            if (eu.isPlaceholder()
                    && upType.equals(eu.getUpgrade().getUpType())) {
                return eu;
            }
        }

        return null;
    }

    public void removeUpgrade(EquippedUpgrade eu) {
        removeUpgrade(eu, true);
    }

    private void removeUpgrade(EquippedUpgrade eu, boolean establishPlaceholders) {
        if (eu != null) {
            mUpgrades.remove(eu);
            eu.setEquippedShip(null);
            if (establishPlaceholders) {
                establishPlaceholders();
            }
        }
    }

    public int calculateCost() {
        int cost = 0;
        if (mShip != null) {
            cost = mShip.getCost();
        }

        for (EquippedUpgrade eu : mUpgrades) {
            cost += eu.calculateCost();
        }

        if (getFlagship() != null) {
            cost += 10;
        }
        FleetCaptain fleetCaptain = getFleetCaptain();
        if (null != fleetCaptain){
            cost += fleetCaptain.getCost();
        }

{'fraction_non_alphanumeric': 0.09700616378045201, 'fraction_numerical': 0.0008805400645729381, 'mean_word_length': 1.870682392586352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5398995', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1895, 'n_words': 412}