Skip to content

Conversation

@softlg
Copy link
Contributor

@softlg softlg commented Aug 5, 2025

Purpose of the pull request

What's changed?

Checklist

  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

@delei
Copy link
Member

delei commented Aug 5, 2025

Is this PR be related with issue #406

Please describe the purpose of this PR in detail. If it is not related with any issues or discussions, we will not be able to merge it.

@softlg
Copy link
Contributor Author

softlg commented Aug 5, 2025

Is this PR be related with issue #406

Please describe the purpose of this PR in detail. If it is not related with any issues or discussions, we will not be able to merge it.

Yes.

@delei
Copy link
Member

delei commented Aug 5, 2025

This issue has already been assigned. To be friendly, please leave a comment on the issue. If the original author does not update it, we will reassign it to you.

@psxjoy
Copy link
Member

psxjoy commented Aug 5, 2025

I remember that using this annotation directly would cause problems? I'm not sure now, so it's best to provide the corresponding test cases :)

@delei
Copy link
Member

delei commented Aug 5, 2025

Hi, @softlg
Thank you for submitting this PR.

BTW, please modify the commit message, and you can refer to other PRs to improve your detailed content, use English for commit messages only.
e.g., bugfix: xxx

@softlg softlg changed the title bugfix:修复不同ReadSheet对像在比较的时候无法正确获取到值 bugfix:Fixed the issue where different ReadSheet objects could not get the correct value when comparing them. Aug 5, 2025
@softlg softlg changed the title bugfix:Fixed the issue where different ReadSheet objects could not get the correct value when comparing them. bugfix: Fixed the issue where different ReadSheet objects could not get the correct value when comparing them. Aug 5, 2025
@softlg
Copy link
Contributor Author

softlg commented Aug 5, 2025

I remember that using this annotation directly would cause problems? I'm not sure now, so it's best to provide the corresponding test cases :)

Could you please provide specific test cases for specific scenarios? I have used ReadSheet in my project and everything is normal.
image
If you are not sure, we can use the following code:

    @Override
    public boolean equals(Object obj) {
        
        if (this == obj) {
            return true;
        }  
        
        if (obj == null || getClass() != obj.getClass()) {
            return false;  
        }
        
        ReadSheet readSheet = (ReadSheet) obj;

        return sheetHidden == readSheet.sheetHidden && sheetVeryHidden == readSheet.sheetVeryHidden &&
                Objects.equals(sheetNo, readSheet.sheetNo) && Objects.equals(sheetName, readSheet.sheetName) &&
                Objects.equals(numRows, readSheet.numRows);
    }

    @Override
    public int hashCode() {
        return Objects.hash(sheetNo, sheetName, sheetHidden, sheetVeryHidden, numRows);
    }

@softlg
Copy link
Contributor Author

softlg commented Aug 5, 2025

Hi, @softlg Thank you for submitting this PR.

BTW, please modify the commit message, and you can refer to other PRs to improve your detailed content, use English for commit messages only. e.g., bugfix: xxx

done

@delei
Copy link
Member

delei commented Aug 5, 2025

Please add unit test code to the fastexcel-test module.

@softlg
Copy link
Contributor Author

softlg commented Aug 5, 2025

Please add unit test code to the fastexcel-test module.

I added relevant test cases, please check if there is anything else that needs to be added.

Copy link
Member

@psxjoy psxjoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run mvn spotless:apply to fix these violations.

sheet2.setHidden(false);
sheet2.setVeryHidden(true);

Assertions.assertEquals(sheet1.hashCode(), sheet2.hashCode());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wonder if what's the impacting by the hashCode(), seems above cases just call twice .

What's the actual scenario in your real case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ust wonder if what's the impacting by the hashCode(), seems above cases just call twice .

What's the actual scenario in your real case?

Zhège lìzǐ shì kěyǐ zhèngcháng yùnxíng de, jùtǐ kěyǐ kàn yǐxià lìzǐ:
23 / 5,000
This example can be run normally, see the following example:
image
If @EqualsAndHashCode is not implemented, sheet1 will be obtained directly, but sheet2 and sheet1 are expected to be different objects.

 @Test
    void testMapWithReadSheet() {

        ReadSheet sheet1 = new ReadSheet(1, "Sheet1");

        ReadSheet sheet2 = new ReadSheet(0, "Sheet2");

        Map<ReadSheet, String> map = new HashMap<>();
        map.put(sheet1, "sheet1 Value");
        //
        ReadSheet sheet3 = new ReadSheet(0, "Sheet2");
        map.put(sheet3, "sheet3 Value");

        String value = map.get(sheet2);
        System.out.println(value);

    }

When ReadSheet does not implement @EqualsAndHashCode, if sheet3 is not added to the map, the value is the value of sheet2, which is problematic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the test case mentioned the equals error. Just wonder if the actual case in file, what will trigger the exception scenario?

@softlg
Copy link
Contributor Author

softlg commented Aug 6, 2025

Run mvn spotless:apply to fix these violations.

done

@softlg softlg requested a review from psxjoy August 6, 2025 05:22
Copy link
Member

@psxjoy psxjoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@psxjoy psxjoy merged commit aa67957 into apache:main Aug 7, 2025
5 checks passed
@delei delei added this to the 1.3.0 milestone Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants