<commit_before>/*
 * Copyright (C) 2014 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.dungeon.entity.items;

import org.dungeon.entity.items.Item.Tag;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * The base inventory class.
 * <p/>
 * Created by <NAME> on 15/11/14.
 */
public abstract class BaseInventory implements Serializable {

  final List<Item> items;

  BaseInventory() {
    items = new ArrayList<Item>();
  }

  public List<Item> getItems() {
    return items;
  }

  /**
   * Convenience method that returns the number of items in the inventory.
   *
   * @return the number of items in the inventory.
   */
  public int getItemCount() {
    return items.size();
  }

  /**
   * Checks if an item is already in the inventory.
   */
  public boolean hasItem(Item itemObject) {
    return items.contains(itemObject);
  }

  /**
   * Removes an item from the Inventory.
   *
   * @param item the Item to be removed
   */
  protected abstract void removeItem(Item item);

  /**
   * Iterates through the inventory, removing items that shouldn't exist anymore.
   */
  public void refreshItems() {
    for (Item item : items) {
      if (item.hasTag(Tag.DECOMPOSES) && item.getAge() > item.getDecompositionPeriod()) {
        removeItem(item);
      }
    }
  }

}<commit_msg>Fixes a bug in BaseInventory.refreshItems().<commit_after>/*
 * Copyright (C) 2014 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.dungeon.entity.items;

import org.dungeon.entity.items.Item.Tag;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * The base inventory class.
 * <p/>
 * Created by <NAME> on 15/11/14.
 */
public abstract class BaseInventory implements Serializable {

  final List<Item> items;

  BaseInventory() {
    items = new ArrayList<Item>();
  }

  private static boolean isDecomposed(Item item) {
    return (item.hasTag(Tag.DECOMPOSES) && item.getAge() >= item.getDecompositionPeriod());
  }

  public List<Item> getItems() {
    return items;
  }

  /**
   * Convenience method that returns the number of items in the inventory.
   *
   * @return the number of items in the inventory.
   */
  public int getItemCount() {
    return items.size();
  }

  /**
   * Checks if an item is already in the inventory.
   */
  public boolean hasItem(Item itemObject) {
    return items.contains(itemObject);
  }

  /**
   * Removes an item from the Inventory.
   *
   * @param item the Item to be removed
   */
  protected abstract void removeItem(Item item);

  /**
   * Iterates through the inventory, removing items that shouldn't exist anymore.
   */
  public void refreshItems() {
    for (Iterator<Item> iterator = items.iterator(); iterator.hasNext(); ) {
      Item item = iterator.next();
      if (isDecomposed(item)) {
        iterator.remove(); // The Item will disappear from the game. No need to set its inventory to null.
      }
    }
  }

}
{'fraction_non_alphanumeric': 0.0994540707334441, 'fraction_numerical': 0.005221932114882507, 'mean_word_length': 3.1517241379310343, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5709753', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1189, 'n_words': 474}