I'm doing a program that compares attributes to me and returns the value (-1, 0, 1) when my attributes are the same or not.
This is my method code:
public int Comparar(CostosImpl CostosRef, CostosImpl CostosHerr, boolean cotizar) {
if(CostosRef.getConcepto().equalsIgnoreCase(CostosHerr.getConcepto())) {
if(CostosRef.getReferencia().equalsIgnoreCase(CostosHerr.getReferencia())) {
if(CostosRef.getReferencia().equalsIgnoreCase("1000")) {
int equals = CostosRef.getDescripcion().compareToIgnoreCase(CostosHerr.getDescripcion());
if(equals == 0) {
equals = CostosRef.getNumeroParte().compareToIgnoreCase(CostosHerr.getNumeroParte());
if(equals == 0) {
if(!cotizar) {
return Double.compare(CostosRef.getMonto(), CostosHerr.getMonto());
}
}
return equals;
} else
return equals;
}
}
else {
int equals = CostosRef.getReferencia().compareToIgnoreCase(CostosHerr.getReferencia());
if(equals == 0) {
if(!cotizar) {
return Double.compare(CostosRef.getMonto(), CostosHerr.getMonto());
}
}
return equals;
}
}
return 0;
}
It's simple, at the beginning it only validates if "Concept" and "Reference" are equal, if "References" are the same, we proceed to check if the value is 1000 and hence more process ... My problem in itself, is that my program MUST rethink a value of 0 if the attributes "Concept" and "Reference" are equal.
These are my attributes:
CostosRef.setConcepto("Refaccion");
CostosRef.setReferencia("1000");
CostosRef.setMonto(150);
CostosRef.setDescripcion("ABISAG.SUP.PUER.TRA.D");
CostosRef.setNumeroParte("67550T9d3AT00ZZ");
CostosHerr.setConcepto("Refaccion");
CostosHerr.setReferencia("1000");
CostosHerr.setMonto(150);
CostosHerr.setDescripcion("cABISAG.SUP.PUER.TRA.D");
CostosHerr.setNumeroParte("67550T9d3AT00ZZ");
As you can see, "Reference" and "Concept" coincide, and I hope that I return a value of 0 and it does not, it returns a negative.
What could I add?.
Thank you.