How do I transfer the array data (objects) into inherited for the array (reservations)?

0
package pkg2017ppfp09;

import ObjectManagement.ContainerOfObjects;


/**
*
* @author pf
*/
public class GestorDeReservas extends ContainerOfObjects{
private final int MAX_RESERVAS = 10;
private final Reserva[] Hist = new Reserva[10];
private Reserva[] reserva;

public GestorDeReservas(Reserva[] reserva) {
    super(reserva);
    this.reserva = new Reserva[MAX_RESERVAS];
}  

public GestorDeReservas(Reserva[] reserva,int maxsize) {
    super(reserva);
    this.reserva = new Reserva[maxsize];
}  

public boolean addObject(Reserva reserva) {
    boolean i=false;
    i=Verificar_reservas((Reserva) reserva);
    if(i==true){
        super.addObject(reserva); 
        //transferObj();
        return true;       
    }else{
         return false; //To change body of generated methods, choose Tools | Templates.
    }
}    

private Reserva[] transferObj(){     
        return (Reserva[])getAllObj();
}








private boolean Verificar_reservas(Reserva reserva){
   Reserva temp = new Reserva();

   temp = reserva;
   for (Reserva reserva1 : this.reserva) {
       if (reserva1 != null && reserva1.getAnimal().equals(temp.getAnimal()) && reserva1.getData().equals(temp.getData())) {
           return false;
       }
   }
   return true;
}

public boolean concluida(Reserva reserva){
    Reserva temp = new Reserva();
    temp = reserva;
    for (Reserva reserva1 : this.reserva) {
        if (reserva1.getAnimal().equals(temp.getAnimal()) && reserva1.getData().equals(temp.getData())) {
            reserva1.setConluida(true);
            return true;
        } 
    }
    return false;
}

public boolean Hist(Reserva[] hist){
    for(int i=0;i<this.reserva.length;i++){
       if(this.reserva[i].getConluida()==true){
           hist[i]= this.reserva[i];
       }
    }
    return true;
}

public void listNconcl(DATA data){ 

    for (Reserva reserva1 : this.reserva) {
        if (reserva1.getData() == data) {
            System.out.println(reserva1.getAnimal().getANIMAL_NOME());
        }
    }   
}

}

I would like to know how to step the array if possible into inherited for reservations.

    
asked by anonymous 15.04.2017 / 14:56

1 answer

0

To solve the problem I simply created two new methods one in the superclass to get an object and another to match this object to this.reserve [i].

Method created in superclass to fetch an object:

protected Object getObject(Object obj){
    Object temp = new Object[this.objects.length+1];
    for (Object object : this.objects) {
        if (obj.equals(object)) {
            temp = object;  
        }
    }
    return (Object) temp;
}

Method to match the object I was fetching to inherited to this.reserve [i]:

private void tranfer(Reserva reserva){
    for(int i=0;i<this.reserva.length+1;i++){
        if(this.reserva[i]==null ){
            this.reserva[i]=(Reserva) super.getObject(reserva);
            i = this.reserva.length+10;
        }
    }    
}

Result:

    
15.04.2017 / 16:37