<commit_before>/*
Copyright 2015 <NAME>, <NAME>, <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plumbing.balancesheets

import akka.actor.{Actor, ActorLogging}
import environment.tradables.{GoodLike, TradableLike}
import plumbing.contracts.PromiseLike
import plumbing.{DeleteTradable, PutTradable}

import scala.collection.mutable


/** Class representing a balance sheet.
  *
  * @note A [[BalanceSheetActor]] should be a child of some [[actor.EconomicActor]].
  */
abstract class BalanceSheetActor extends Actor
  with ActorLogging {

  /** Unordered collection of tradable objects. */
  def tradables: mutable.Set[TradableLike]

  /** Unordered collection of tradable object that are assets. */
  def assets: mutable.Set[TradableLike] = {
    tradables.filter {
      case tradable: GoodLike => true
      case tradable: PromiseLike if tradable.promisee == context.parent => true
      case _ => false
    }
  }

  /** Unordered collection of tradable object that are liabilities. */
  def liabilities: mutable.Set[TradableLike] = {
    tradables.filter {
      case tradable: PromiseLike if tradable.promisor == context.parent => true
      case _ => false
    }
  }

  def receive: Receive = {
    case PutTradable(tradable) =>
      tradables.add(tradable)
    case DeleteTradable(tradable) =>
      tradables.remove(tradable)

  }
}<commit_msg>Refactor BalanceSheetActor<commit_after>/*
Copyright 2015 <NAME>, <NAME>, <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plumbing.balancesheets

import akka.actor.{ActorRef, Actor, ActorLogging}

import scala.collection.mutable


/** Class representing a balance sheet.
  * @note A [[BalanceSheetActor]] should be a child of some [[actor.EconomicActor]].
  */
abstract class BalanceSheetActor extends Actor
  with ActorLogging {

  /** Unordered collection of tradable objects that are assets. */
  def assets: mutable.Set[ActorRef]

  /** Unordered collection of tradable objects that are liabilities. */
  def liabilities: mutable.Set[ActorRef]

  def receive: Receive = {
    case AddAsset(asset) =>
      assets.add(asset)
    case RemoveAsset(asset) =>
      assets.remove(asset)
    case AddLiability(liability) =>
      liabilities.add(liability)
    case RemoveLiability(liability) =>
      liabilities.remove(liability)

  }
}
{'fraction_non_alphanumeric': 0.0856269113149847, 'fraction_numerical': 0.004892966360856269, 'mean_word_length': 4.040061633281972, 'pattern_counts': {'":': 0, '<': 9, '<?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': '16236', 'n_tokens_mistral': 946, 'n_tokens_neox': 901, 'n_words': 336}