I have two classes ( ColunaDoGrafico
and ColunaDoRelatorio
) that extend from Coluna
.
My Column class has the following structure:
public class Coluna {
protected String tipoFiltro;
protected boolean exibeFiltro;
protected Relatorio relatorio;
// alguns outros atributos
//getters e setters
}
The Report class is basically composed of:
public class Relatorio {
private Set<ColunaDoRelatorio> colunasDoRelatorio;
private Set<ColunaDoGrafico> colunasDoGrafico;
// outros atributos
public Set<ColunaDoRelatorio> getColunasDoRelatorio() {
return colunasDoRelatorio;
}
public void setColunasDoRelatorio(Set<ColunaDoRelatorio> colunasDoRelatorio) {
this.colunasDoRelatorio = colunasDoRelatorio;
}
public Set<ColunaDoGrafico> getColunasDoGrafico() {
return colunasDoGrafico;
}
public void setColunasDoGrafico(Set<ColunaDoGrafico> colunasDoGrafico) {
this.colunasDoGrafico = colunasDoGrafico;
}
}
The GraphPad and RowData classes inherit from Column and have other attributes unique to each.
They are basically:
public class ColunaDoGrafico extends Coluna {
private String apresentacao;
private boolean eixoY;
private boolean eixoX;
private String operacao;
//getters and setters
}
e:
public class ColunaDoRelatorio extends Coluna{
private boolean exibeNoRelatorio;
private String operacao;
private String clausula;
//getters and setters
}
In another class I have a method that must go through a set of columns, which may be a Set and sometimes a Set. And this method should analyze two attributes (which are common to both child classes, since it was inherited from the parent class) of each of the items in that list. I'm doing it this way:
private void trataFiltro(Set<Coluna> colunas){
StringBuilder sb = new StringBuilder();
sb.append(query);
for(Coluna coluna: colunas){
if(coluna.isExibeFiltro()){
if(coluna.getTipoFiltro().equals("texto")){
System.out.println("A");
}else if(coluna.getTipoFiltro().equals("dominio")){
System.out.println("B");
}else if(coluna.getTipoFiltro().startsWith("tempo")){
System.out.println("C");
}else {
System.out.println("D");
}
}
}
}
However, when I try to call the method as follows:
trataFiltro(relatorio.getColunasDoRelatorio());
or
trataFiltro(relatorio.getColunasDoGrafico());
It's not compiling and says:
The method is setFilter (Set) is not applicable for the arguments Set
Because both classes have the attributes that are required by the method, should not the code work? How can I solve this? I have to write the same method for each of the classes, changing only the argument?