1
I have two classes (ColunaDoGrafico
and ColunaDoRelatorio
) extending 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 consists basically 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 classes Colunadografico and Colunadorelatorio inherit from Coluna and have other particular attributes to each one.
Are basically:
public class ColunaDoGrafico extends Coluna {
private String apresentacao;
private boolean eixoY;
private boolean eixoX;
private String operacao;
//getters and setters
}
and:
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 should go through a set of columns, which can now be a Set and can now be a Set. And this method should analyze two attributes (which are common to both daughter classes, since it was inherited from the mother class) from 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 in the following way:
trataFiltro(relatorio.getColunasDoRelatorio());
or
trataFiltro(relatorio.getColunasDoGrafico());
It’s not compiling and it says :
The method trataFiltro(Set) is not applicable for the Arguments Set
Because both classes have the attributes that are required for the method, shouldn’t the code work? How do I fix this? I have to write the same method for each class, changing only the argument?
Add the two missing classes as well.
– user28595
I’ve already added :)
– oitathi
Missed the gets involved in the error.
– user28595
put the report class gets and sets
– oitathi
The error is certainly not in the code presented. Where does this method come from? Please place the complete classes or if it is too big, make a [mcve], with pieces not even to simulate the problem.
– user28595