<commit_before>package city.bank;

import java.util.Hashtable;
import java.util.List;
import java.util.concurrent.Semaphore;

import agent.Role;
import city.PersonAgent;
import city.bank.gui.BankTellerRoleGui;
import city.bank.interfaces.BankTeller;

public class BankTellerRole extends Role implements BankTeller {
	
	//Data
	List<MyCustomer> myCustomers;
	BankHostRole host;
	boolean occupied;
	String name;
	private int tellerNum;
	static AccountDatabase database;
	
	enum Command{None, Leave};
	Command command;
	Semaphore tellerSem = new Semaphore(0,true);
	
	PersonAgent person;
	
	BankTellerRoleGui gui;
	Bank bank;
	 
	public BankTellerRole(PersonAgent person, Bank bank){
		super(person);
		this.bank = bank;
		command = Command.None;
	}
	
	private static class AccountDatabase{
	      Hashtable<Integer, Double> funds;
	      Hashtable<Integer, Double> amountOwed;
	//given Account Number, gets funds or amount owed
	}
	private class MyCustomer{
		  MyCustomer(BankCustomerRole c){
			  this.customer = c;
			  customerState = CustomerState.None;
			  accountNumber = -1;
		  }
		  
	      BankCustomerRole customer;
	      int accountNumber;
	      String request;
	      int amount;
	      
	      CustomerState customerState;
	}
	
	enum CustomerState { None, Arrived, GivingRequest, GivenRequest};
	
	//Messages
	public void msgIAmHere(BankCustomerRole c){
		  MyCustomer m = new MyCustomer(c);
		  m.customerState = CustomerState.Arrived;
		  myCustomers.add(m);
		  stateChanged();
	}
	public void msgHereIsMyRequest(BankCustomerRole c, String request, int amount){
		  for(MyCustomer m: myCustomers){
			if(m.customer == c){
		  	m.customerState = CustomerState.GivenRequest;
		  	m.request = request;
		  	m.amount = amount; //
		  	stateChanged();
		  	return;
			}
		  }
	}
	public void msgLeavingBank(BankCustomerRole c){
		  for(MyCustomer m: myCustomers){
			if(m.customer == c){
				m.customerState = CustomerState.None;
				myCustomers.remove(m);
				stateChanged();
				return;
			}
		  }
	}
	
	//Scheduler
	public boolean pickAndExecuteAnAction(){
		for(MyCustomer m: myCustomers){
			if(m.customerState == CustomerState.Arrived){
				actAskForARequest(m);
				return true;
			}
		}
		for(MyCustomer m: myCustomers){
			if(m.customerState == CustomerState.GivenRequest){
				actProcessRequest(m);
				return true;
			}
		}
		
		if(myCustomers.isEmpty() && command == Command.Leave && host.isWaitingCustomersEmpty()){
			actLeaveBank();
		}
		return false;
	}<commit_msg>Adding integration of banks to businesses<commit_after>package city.bank;

import java.util.Hashtable;
import java.util.List;
import java.util.concurrent.Semaphore;

import agent.Role;
import city.PersonAgent;
import city.Place;
import city.bank.gui.BankTellerRoleGui;
import city.bank.interfaces.BankTeller;

public class BankTellerRole extends Role implements BankTeller {
	
	//Data
	List<MyCustomer> myCustomers;
	List<MyBusinessCustomer> myBusinessCustomers;
	BankHostRole host;
	boolean occupied;
	String name;
	private int tellerNum;
	static AccountDatabase database;
	
	enum Command{None, Leave};
	Command command;
	Semaphore tellerSem = new Semaphore(0,true);
	
	PersonAgent person;
	
	BankTellerRoleGui gui;
	Bank bank;
	 
	public BankTellerRole(PersonAgent person, Bank bank){
		super(person);
		this.bank = bank;
		command = Command.None;
	}
	
	private static class AccountDatabase{
	      Hashtable<Integer, Double> funds;
	      Hashtable<Integer, Double> amountOwed;
	//given Account Number, gets funds or amount owed
	}
	private class MyCustomer{
		  MyCustomer(BankCustomerRole c){
			  this.customer = c;
			  customerState = CustomerState.None;
			  accountNumber = -1;
		  }
		  
	      BankCustomerRole customer;
	      int accountNumber;
	      String request;
	      int amount;
	      
	      CustomerState customerState;
	}
	
	private class MyBusinessCustomer{
		Place place;
		int accountNumber;
		double amount;
		
		MyBusinessCustomer(Place place, int accountNumber, double amount){
			this.place = place;
			this.accountNumber = accountNumber;
			this.amount = amount;
		}
	}
	
	enum CustomerState { None, Arrived, GivingRequest, GivenRequest};
	
	//Messages
	public void msgIAmHere(BankCustomerRole c){
		  MyCustomer m = new MyCustomer(c);
		  m.customerState = CustomerState.Arrived;
		  myCustomers.add(m);
		  stateChanged();
	}
	public void msgHereIsMyRequest(BankCustomerRole c, String request, int amount){
		  for(MyCustomer m: myCustomers){
			if(m.customer == c){
		  	m.customerState = CustomerState.GivenRequest;
		  	m.request = request;
		  	m.amount = amount; //
		  	stateChanged();
		  	return;
			}
		  }
	}
	public void msgLeavingBank(BankCustomerRole c){
		  for(MyCustomer m: myCustomers){
			if(m.customer == c){
				m.customerState = CustomerState.None;
				myCustomers.remove(m);
				stateChanged();
				return;
			}
		  }
	}
	
	//FOR CASHIERS OF RESTAURANTS AND CASHIERS OF MARKETS
	public void msgDeposit(Place place, int accountNumber, double amount){
		int newAccntNum;
		if(accountNumber == -1){  //means it doesn't exist yet
			   newAccntNum = (int)(Math.random()*20000) + 10000; //open account from 20k to 10k for businesses
			   while(database.funds.containsKey(newAccntNum)){
				   newAccntNum = (int)(Math.random()*20000) + 10000;
			   }
		} else{
				newAccntNum = accountNumber;		//existing account
		}
		
		database.funds.put(newAccntNum, 0.0);
		database.amountOwed.put(newAccntNum, 0.0);
		MyBusinessCustomer businessCustomer = new MyBusinessCustomer(place, newAccntNum, amount);
		myBusinessCustomers.add(businessCustomer);
		stateChanged();
	}
	
	//Scheduler
	public boolean pickAndExecuteAnAction(){
		for(MyBusinessCustomer mb: myBusinessCustomers){
			
		}
		for(MyCustomer m: myCustomers){
			if(m.customerState == CustomerState.Arrived){
				actAskForARequest(m);
				return true;
			}
		}
		for(MyCustomer m: myCustomers){
			if(m.customerState == CustomerState.GivenRequest){
				actProcessRequest(m);
				return true;
			}
		}
		
		if(myCustomers.isEmpty() && command == Command.Leave && host.isWaitingCustomersEmpty()){
			actLeaveBank();
		}
		return false;
	}
{'fraction_non_alphanumeric': 0.0993485342019544, 'fraction_numerical': 0.005374592833876222, 'mean_word_length': 3.6522727272727273, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '5378761', 'n_tokens_mistral': 2255, 'n_tokens_neox': 1910, 'n_words': 456}