You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by KoenDG <gi...@git.apache.org> on 2017/09/19 16:06:18 UTC

[GitHub] kafka pull request #3904: [MINOR] Added equals() method to Stamped

GitHub user KoenDG opened a pull request:

    https://github.com/apache/kafka/pull/3904

    [MINOR] Added equals() method to Stamped

    Please don't let analyzing this PR take away from actual working time. I did this in my spare time, it's not intended to take away from your working hours. It may well be that this is a non-issue.
    
    As the title states: I added equals() method to Stamped.java because a class that implements Comparable should always have this.
    
    This was pointed out to me by Intellij's code analysis, which warned that classes implementing Comparable should always implement both compareTo() and equals(). This is because an end-user can at some point add objects of that class to java.util.SortedSet. If the compareTo() and equals() implementations are not consistent, that would violate the contract of java.util.Set, which is defined in terms of equals().
    
    findBugs also complained about PunctuationScheduler, a subclass of Stamped, nothing having equals, so I also implemented that.
    
    The equals() in Stamped.java is written to be consistent with how the already-existing compareTo() works in that class. The hashCode() is autogenerated, with only the timestamp field, as that is the only one used by compareTo() and equals().
    
    findBugs complained about PunctuationSchedule.java, a subclass of Stamped.java, also needing these methods if Stamped.java had them. So I had equals() and hashCode() auto-generated for them.
    
    ./gradlew test ran fine.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/KoenDG/kafka stampedEquals

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/kafka/pull/3904.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #3904
    
----
commit aea3d72aa5f6854a845e76eb4359ca456ae7209f
Author: coscale_kdegroot <ko...@coscale.com>
Date:   2017-09-19T15:34:32Z

    Added equals() method to Stamped, because a class that implements Comparable should always have this.
    findBugs complained about PunctuationSchedula, a subclass of Stamped, nothing having equals, so also implemented that.
    
    Since the compareTo and equals methods don't take the value field into account, neither should hashCode.

----


---

[GitHub] kafka pull request #3904: [MINOR] Added equals() method to Stamped

Posted by KoenDG <gi...@git.apache.org>.
Github user KoenDG closed the pull request at:

    https://github.com/apache/kafka/pull/3904


---