Code 1 in generated java classes

Hi all.

is there anyone who can tell me 1. what the following code is good for and 2. give me some hints about what the code is actually does [ small java course]. I found this code snippet in some other java programs.

private java.lang.Object __equalsCalc = null;
    public synchronized boolean equals(java.lang.Object obj) {
        if (!(obj instanceof AdabasEmployeesTypeIncome)) return false;
        AdabasEmployeesTypeIncome other = (AdabasEmployeesTypeIncome) obj;
        if (obj == null) return false;
        if (this == obj) return true;
        if (__equalsCalc != null) {
            return (__equalsCalc == obj);
        }
        __equalsCalc = obj;
        boolean _equals;
        _equals = true && 
            ((this.currencyCode==null && other.getCurrencyCode()==null) || 
             (this.currencyCode!=null &&
              this.currencyCode.equals(other.getCurrencyCode()))) &&
            ((this.annualSalary==null && other.getAnnualSalary()==null) || 
             (this.annualSalary!=null &&
              java.util.Arrays.equals(this.annualSalary, other.getAnnualSalary()))) &&
            ((this.annualBonus==null && other.getAnnualBonus()==null) || 
             (this.annualBonus!=null &&
              java.util.Arrays.equals(this.annualBonus, other.getAnnualBonus())));
        __equalsCalc = null;
        return _equals;
    }

Best Regards

Dago

Hi,
I would expect to find this code in the definition of class AdabasEmployeesTypeIncome, where it overrides the “.equals()” comparison method. You can use this method in a statement like


AdabasEmployeesTypeIncome myIncome = someIncome;
if (myIncome.equals(someOtherIncome)) { do something };

Basically it locks the object being compared (synchronized), then tests the parameter object (which can be any type of Object) to make sure it is actually of type “AdabasEmployeesTypeIncome” (two objects can’t be equal if they are of different type). If not, the method returns false. If the parameter type is correct, the code casts the parameter object into its correct type to get access to the properties it needs to compare. If the object being compared is null, the result is false. If both objects have the same “handle” (==) they must be the same object, therefore return true. The code then returns true if all the individual properties of both objects are the same, or null. Otherwise it returns false. You get the idea.

Thank’s a lot for your reply.
Yes , the last part of your reply gives me the idea whay and what happens.

Best regards
Dago