<commit_before>package ca.ulaval.ticketmaster.web.DomaineAffaire;

import java.util.ArrayList;
import java.util.UUID;

import javax.servlet.http.HttpSession;

import org.springframework.ui.Model;

import ca.ulaval.ticketmaster.dao.util.DataManager;
import ca.ulaval.ticketmaster.model.Ticket;

public class DABasket {
	private DataManager datamanager;
	public DABasket() {
		datamanager = new DataManager();
	}
	
	@SuppressWarnings("unchecked")
	public String addToBasket(String eventId,String ticketId,Model model, HttpSession session){
		if (DAAuthentication.isLogged(session))
		{
			ArrayList<Ticket> list;
			if (session.getAttribute("basket") != null)
			{
				// a cause du cast d'un objet vers arraylist<Ticket> je n'ai pas trouv de solution pour enlever le warning
				list = (ArrayList<Ticket>)session.getAttribute("basket");
				model.addAttribute("msg", "old array");
			}else //le panier est vide
			{
				 list=  new ArrayList<Ticket>();
					model.addAttribute("msg", "New array");
			}
			list.add(datamanager.findTicket(UUID.fromString(eventId), UUID.fromString(ticketId)));
			session.setAttribute("basket", list);
		}else{
			model.addAttribute("msg", "Veuillez vous connecter pour acheter des billets");
			//TODO coder un message qui demande de se logger
		}
		return "redirect:/event/" + eventId;
		
	}
	
	@SuppressWarnings("unchecked")
	public String removeFromBasket(String eventId,String ticketId,Model model, HttpSession session){

		if (session.getAttribute("basket") != null)
		{
		
			ArrayList<Ticket> list = (ArrayList<Ticket>)session.getAttribute("basket");
			int i = 0;
			boolean isFound = false;
			while (i < list.size() && !isFound)
			{
				if (list.get(i).getId().toString() == ticketId)
				{
					isFound = true;
					while (!isFound && i < list.size()){		
						if(list.get(i).getId().toString() == eventId)
						{
							list.remove(i);
							session.setAttribute("basket", list);
							isFound = true;
						}
						++i;
					}
					
				}
				++i;
			}
			list.remove(datamanager.findTicket(UUID.fromString(eventId), UUID.fromString(ticketId)));
		}
			return "redirect:/Basket";		
	}
}<commit_msg>delete ticket dans basket work<commit_after>package ca.ulaval.ticketmaster.web.DomaineAffaire;

import java.util.ArrayList;
import java.util.UUID;

import javax.servlet.http.HttpSession;

import org.springframework.ui.Model;

import ca.ulaval.ticketmaster.dao.util.DataManager;
import ca.ulaval.ticketmaster.model.Ticket;

public class DABasket {
	private DataManager datamanager;

	public DABasket() {
		datamanager = new DataManager();
	}

	@SuppressWarnings("unchecked")
	public String addToBasket(String eventId, String ticketId, Model model, HttpSession session) {
		if (DAAuthentication.isLogged(session)) {
			ArrayList<Ticket> list;
			if (session.getAttribute("basket") != null) {
				// a cause du cast d'un objet vers arraylist<Ticket> je n'ai pas
				// trouv de solution pour enlever le warning
				list = (ArrayList<Ticket>) session.getAttribute("basket");
				model.addAttribute("msg", "old array");
			} else // le panier est vide
			{
				list = new ArrayList<Ticket>();
				model.addAttribute("msg", "New array");
			}
			list.add(datamanager.findTicket(UUID.fromString(eventId), UUID.fromString(ticketId)));
			session.setAttribute("basket", list);
		} else {
			model.addAttribute("msg", "Veuillez vous connecter pour acheter des billets");
			// TODO coder un message qui demande de se logger
		}
		return "redirect:/event/" + eventId;

	}

	@SuppressWarnings("unchecked")
	public String removeFromBasket(String eventId, String ticketId, Model model, HttpSession session) {

		// isFound = true;
		if (session.getAttribute("basket") != null) {
			ArrayList<Ticket> list = (ArrayList<Ticket>) session.getAttribute("basket");
			int i = 0;
			boolean isFound = false;
			while (i < list.size() && !isFound) {
				if (list.get(i).getId().toString().equals(ticketId)) {
					isFound = true;
					list.remove(i);
					session.setAttribute("basket", list);
				}
				++i;
			}

		}
		return "redirect:/Basket";
	}
}
{'fraction_non_alphanumeric': 0.13539367181751288, 'fraction_numerical': 0.0004905567819475104, 'mean_word_length': 3.9610705596107056, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 15, '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': '2773153', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1321, 'n_words': 294}