Remove object inside another Java List object

0

I have a list in java, that within each object, it has an attribute that is an object of the same list. I'm trying to remove the object that is inside object 1 for example. There is recursion that I mounted to get to the element infinitely.

    RequestContext context = RequestContext.getCurrentInstance();

    try {

        Integer id = this.idParaDeletar;

        if (this.listaBancoPasta != null || !this.listaBancoPasta.isEmpty()) {

            for (BancoPastas pasta : this.listaBancoPasta) {

                Integer idLista = pasta.getIdBancoPasta();

                if (idLista == id) {

                    this.listaBancoPasta.remove(pasta);

                } else if (pasta.getSubPasta() != null) {

                    this.recursaoExcluirRegistro(pasta.getSubPasta());

                }

            }

        }

        context.execute("PF('modalDelete').hide();");

    } catch (Exception e) {
        System.out.println("Error deleteRegistro : " + e.getMessage());
    }

}

public void recursaoExcluirRegistro(BancoPastas pasta) {

    try {

        Integer idPasta = pasta.getIdBancoPasta();

        if (idPasta == this.idParaDeletar) {

            this.listaBancoPasta.remove(pasta);

        } else if (pasta.getSubPasta() != null) {

            this.recursaoExcluirRegistro(pasta.getSubPasta());
        }

    } catch (Exception e) {
        System.out.println("Error recursaoExcluirRegistro : " + e.getMessage());
    }

}

But my problem is this. In the recursion method DeleteRegistration if the object is inside another when trying to remove it does not remove from the list.

    this.listaBancoPasta.remove(pasta);

For that moment it is already in the recursion, with this I pass folder as object the list will not find it because it is inside another object of the list. how would I remove it correctly?

This is my model BancoPastas that has an attribute of the same class

private Integer idBancoPasta;
private int idPai;
private String nomePasta;
private String tipoPasta;
private Integer criadoPor;
private Date criadoEm;
private Integer atualizadoPor;
private Date atualizadoEm;
private BancoPastas subPasta;
    
asked by anonymous 13.04.2018 / 15:36

0 answers