96 lines
2.3 KiB
Java
96 lines
2.3 KiB
Java
package Logica;
|
|
|
|
import java.time.Month;
|
|
import java.util.ArrayList;
|
|
|
|
public class Meses {
|
|
private ArrayList<Mes> meses;
|
|
private int mesActual=0;
|
|
|
|
public Meses() {
|
|
this.meses = new ArrayList<Mes>();
|
|
}
|
|
|
|
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<Gestion> gestiones=new ArrayList<Gestion>();
|
|
gestiones.add(new Gestion(nombre));
|
|
this.meses.add(new Mes(gestiones,anio,mes));
|
|
return;
|
|
}
|
|
ArrayList<Gestion> gestiones=new ArrayList<Gestion>();
|
|
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<Gestion>(),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<Gestion> getGestionesActuales(){
|
|
return this.meses.get(this.mesActual).getGestiones();
|
|
}
|
|
|
|
}
|
|
|
|
class Mes{
|
|
private int anio;
|
|
private Month mes;
|
|
int total;
|
|
ArrayList<Gestion> gestiones;
|
|
Mes(ArrayList<Gestion> 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<Gestion> getGestiones(){
|
|
return this.gestiones;
|
|
}
|
|
|
|
}
|