<commit_before>package tk.allele.inventory;

import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.Arrays;
import java.util.HashMap;

/**
 * Implements an abstraction to double chests.
 */
public class DoubleChestInventory implements Inventory {
    Inventory inventoryA, inventoryB;

    public DoubleChestInventory(Inventory inventoryA, Inventory inventoryB) {
        this.inventoryA = inventoryA;
        this.inventoryB = inventoryB;
    }

    public DoubleChestInventory(Chest chestA, Chest chestB) {
        this(chestA.getInventory(), chestB.getInventory());
    }

    @Override
    public int getSize() {
        return (inventoryA.getSize() + inventoryB.getSize());
    }

    @Override
    public String getName() {
        return (inventoryA.getName() + "+" + inventoryB.getName());
    }

    @Override
    public ItemStack getItem(int i) {
        if(i < inventoryA.getSize()) {
            return inventoryA.getItem(i);
        } else {
            return inventoryB.getItem(i - inventoryA.getSize());
        }
    }

    @Override
    public void setItem(int i, ItemStack itemStack) {
        if(i < inventoryA.getSize()) {
            inventoryA.setItem(i, itemStack);
        } else {
            inventoryB.setItem(i, itemStack);
        }
    }

    @Override
    public HashMap<Integer, ItemStack> addItem(ItemStack... itemStacks) {
        HashMap<Integer, ItemStack> leftoverMap = inventoryA.addItem(itemStacks);
        if(leftoverMap.isEmpty()) {
            return leftoverMap;
        } else {
            ItemStack[] leftover = leftoverMap.values().toArray(new ItemStack[itemStacks.length]);
            return inventoryB.addItem(leftover);
        }
    }

    @Override
    public HashMap<Integer, ItemStack> removeItem(ItemStack... itemStacks) {
        HashMap<Integer, ItemStack> leftoverMap = inventoryA.removeItem(itemStacks);
        if(leftoverMap.isEmpty()) {
            return leftoverMap;
        } else {
            ItemStack[] leftover = leftoverMap.values().toArray(new ItemStack[itemStacks.length]);
            return inventoryB.removeItem(leftover);
        }
    }

    @Override
    public ItemStack[] getContents() {<commit_msg>Fixed GH-6 (ArrayOutOfBounds exception when using double chest)<commit_after>package tk.allele.inventory;

import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.Arrays;
import java.util.HashMap;

/**
 * Implements an abstraction to double chests.
 */
public class DoubleChestInventory implements Inventory {
    Inventory inventoryA, inventoryB;

    public DoubleChestInventory(Inventory inventoryA, Inventory inventoryB) {
        this.inventoryA = inventoryA;
        this.inventoryB = inventoryB;
    }

    public DoubleChestInventory(Chest chestA, Chest chestB) {
        this(chestA.getInventory(), chestB.getInventory());
    }

    @Override
    public int getSize() {
        return (inventoryA.getSize() + inventoryB.getSize());
    }

    @Override
    public String getName() {
        return (inventoryA.getName() + "+" + inventoryB.getName());
    }

    @Override
    public ItemStack getItem(int i) {
        if(i < inventoryA.getSize()) {
            return inventoryA.getItem(i);
        } else {
            return inventoryB.getItem(i - inventoryA.getSize());
        }
    }

    @Override
    public void setItem(int i, ItemStack itemStack) {
        if(i < inventoryA.getSize()) {
            inventoryA.setItem(i, itemStack);
        } else {
            inventoryB.setItem(i - inventoryA.getSize(), itemStack);
        }
    }

    @Override
    public HashMap<Integer, ItemStack> addItem(ItemStack... itemStacks) {
        HashMap<Integer, ItemStack> leftoverMap = inventoryA.addItem(itemStacks);
        if(leftoverMap.isEmpty()) {
            return leftoverMap;
        } else {
            ItemStack[] leftover = leftoverMap.values().toArray(new ItemStack[itemStacks.length]);
            return inventoryB.addItem(leftover);
        }
    }

    @Override
    public HashMap<Integer, ItemStack> removeItem(ItemStack... itemStacks) {
        HashMap<Integer, ItemStack> leftoverMap = inventoryA.removeItem(itemStacks);
        if(leftoverMap.isEmpty()) {
            return leftoverMap;
        } else {
            ItemStack[] leftover = leftoverMap.values().toArray(new ItemStack[itemStacks.length]);
            return inventoryB.removeItem(leftover);
        }
    }

    @Override
    public ItemStack[] getContents() {
{'fraction_non_alphanumeric': 0.10842854063375727, 'fraction_numerical': 0.0002155636990730761, 'mean_word_length': 2.7149719775820658, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '2401899', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1343, 'n_words': 266}