package Logica; import java.time.Month; import java.util.ArrayList; public class Meses { private ArrayList meses; private int mesActual=0; public Meses() { this.meses = new ArrayList(); } public void aniadirGestion(String nombre, int anio, Month mes) { try { for(Mes mesSelect:this.meses) { if(mesSelect.getMes().equals(mes) && mesSelect.getAnio() == anio){ mesSelect.getGestiones().add(new Gestion(nombre)); return; } } }catch (NullPointerException e) { ArrayList gestiones=new ArrayList(); gestiones.add(new Gestion(nombre)); this.meses.add(new Mes(gestiones,anio,mes)); return; } ArrayList gestiones=new ArrayList(); gestiones.add(new Gestion(nombre)); this.meses.add(new Mes(gestiones,anio,mes)); } public void aniadirTransaccion(Transaccion transaccion, String nombre) { for(Mes mes:this.meses) { if(transaccion.getDia().getMonth().equals(mes.getMes()) && transaccion.getDia().getYear() == mes.getAnio()){ mes.aniadirTransaccion(transaccion, nombre); return; } } this.meses.add(new Mes(new ArrayList(),transaccion.getDia().getYear(), transaccion.getDia().getMonth())); this.meses.get(this.meses.size()-1).aniadirTransaccion(transaccion, nombre); } public void elegirMes(int anio, Month mes) { for(int i = 0; i < this.meses.size(); i++) { if(this.meses.get(i).getAnio()==anio && this.meses.get(i).getMes().equals(mes)) { this.mesActual = 0; } } } public ArrayList getGestionesActuales(){ return this.meses.get(this.mesActual).getGestiones(); } } class Mes{ private int anio; private Month mes; int total; ArrayList gestiones; Mes(ArrayList gestiones, int anio, Month mes){ this.gestiones = gestiones; this.anio=anio; this.mes=mes; } void aniadirTransaccion(Transaccion transaccion, String nombre) { for(Gestion gestion:this.gestiones) { if(gestion.getNombre().equals(nombre)) { gestion.aniadirGasto(transaccion); return; } } gestiones.add(new Gestion(nombre)); gestiones.get(this.gestiones.size()-1).aniadirGasto(transaccion); return; } Month getMes() { return this.mes; } int getAnio() { return this.anio; } ArrayList getGestiones(){ return this.gestiones; } }