package Exo3.refuge;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

public class Refuge {
	private  List<IAnimal> animaux = new ArrayList<IAnimal>();
	private  TreeMap<String, Integer> capacites = new TreeMap<String,Integer>();
	
	public Refuge(TreeMap<String, Integer> capacites) {
		super();
		this.capacites = capacites;
	}
	
	public void ajouter(IAnimal a) {
		if(ajoutPossible(a.getEspece())) {
			animaux.add(a);
		}
	}
	
	public int compter(String espece) {
		int compteur = 0;
		for(IAnimal a:animaux) {
			if(a.getEspece().equals(espece)) {
				compteur++;
			}
		}
		return compteur;
	}
	
	public boolean ajoutPossible(String espece) {
		return compter(espece) <= (int) capacites.get(espece);
	}
	
	public String nourrirLesAnimaux() {
		StringBuilder sb = new StringBuilder();
		
		for(IAnimal a:animaux) {
			sb.append(a.getNom() + " mange " + a.getNourriture());
			sb.append(System.getProperty("line:separator"));
		}
		
		return sb.toString();
	}
	
	public String lesAnimauxCrient() {
		StringBuilder sb = new StringBuilder();
		
		for(IAnimal a:animaux) {
			sb.append(a.getNom() + " crie : " + a.getCri());
			sb.append(System.getProperty("line:separator"));
		}
		
		return sb.toString();
	}
}
