"CompareToIgnoreCase" does not work

1

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.

    
asked by Antonio Alejos 20.11.2018 в 18:30
source

1 answer

1

It's just a problem that you can solve. Let's look at the first 3 lines of your code:

if(CostosRef.getConcepto().equalsIgnoreCase(CostosHerr.getConcepto())) {
    if(CostosRef.getReferencia().equalsIgnoreCase(CostosHerr.getReferencia())) {
        if(CostosRef.getReferencia().equalsIgnoreCase("1000")) {

At this point, you know that the concepts are the same, that the references are the same, and that the reference is 1000. Then you should return the 0. But your code, keeps doing things when it reaches this point.

What you have to do is review your code and follow it step by step.

    
answered by 20.11.2018 / 19:03
source