You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commonsrdf.apache.org by stain <gi...@git.apache.org> on 2015/05/12 11:49:31 UTC

[GitHub] incubator-commonsrdf pull request: COMMONSRDF-14 define explicit h...

GitHub user stain opened a pull request:

    https://github.com/apache/incubator-commonsrdf/pull/13

    COMMONSRDF-14 define explicit hashCode

    Fixes [COMMONSRDF-14](https://issues.apache.org/jira/browse/COMMONSRDF-14) by defining explicit `hashCode()` for `BlankNode`, `IRI`, `Literal` and `Triple`.
    
    For comments on this pull request, please primarily use the Jira issue COMMONSRDF-14 thread, as GitHub email synchronization is not always working well.
    
    Generated javadocs:
    
    http://stain.github.io/incubator-commonsrdf/COMMONSRDF-14/org/apache/commons/rdf/api/BlankNode.html#hashCode--
    http://stain.github.io/incubator-commonsrdf/COMMONSRDF-14/org/apache/commons/rdf/api/IRI.html#hashCode--
    http://stain.github.io/incubator-commonsrdf/COMMONSRDF-14/org/apache/commons/rdf/api/Literal.html#hashCode--
    http://stain.github.io/incubator-commonsrdf/COMMONSRDF-14/org/apache/commons/rdf/api/Triple.html#hashCode--
    
    The approach I suggest here favours simplicity in the documentation - so `BlankNode` hashCode is equal to the String.hashCode() of its `uniqueReference()` without modifications, and likewise for `IRI` with `getUriString().hashCode()`:
    
    >  The returned hash code MUST be equal to the String.hashCode() of the getIRIString(). 
    
    .. while the compound objects are using [Objects.hash()](http://docs.oracle.com/javase/8/docs/api/java/util/Objects.html#hash-java.lang.Object...-):
    
    >  The returned hash code MUST be equal to the result of Objects.hash(Object...) with the arguments getLexicalForm(), getDatatype(), getLanguageTag(). 
    
    This means that our `hashCode()` definition does not need to define in detail how to combine these - but unfortunately `Objects.hash()` is also not explicit about this, so clients would then be forced to use Objects.hash(). They are not required to use the actual getter methods (e.g. LiteralImpl uses the private fields directly) - as long as the resulting hashCode is the same AS IF this had been done. Due to the direct mappings to the uniqueReference and IRI this means that a `TripleImpl` can take several shortcuts if it wants to. Combined with [COMMONSRDF-7](https://issues.apache.org/jira/browse/COMMONSRDF-7) for immutability the hashCode would stay the same for the duration of the object and can thus also be cached if so needed.
    
    ## Implementation notes:
    
    [Optional.hashCode()](http://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#hashCode--) returns the hashCode of the value, or `0` if it is not present. 
    
    (Warning: GPLv3 code links below!)
    
    In OpenJDK 8, [Objects.hash](https://github.com/stain/jdk8u/blob/master/src/share/classes/java/util/Objects.java#L127) calls [Arrays.hashCode](https://github.com/stain/jdk8u/blob/master/src/share/classes/java/util/Arrays.java#L4118) which adds the hashCode with `31` as multiplier. This is however not explicit.

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

    $ git pull https://github.com/stain/incubator-commonsrdf COMMONSRDF-14-hashCode

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

    https://github.com/apache/incubator-commonsrdf/pull/13.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 #13
    
----
commit 1a1bc326c9232b6d560c14d43c5e05a1e1e640b9
Author: Stian Soiland-Reyes <st...@apache.org>
Date:   2015-05-06T21:49:29Z

    COMMONSRDF-14 specify hashCode

commit 26da40856a86f6fdb511fdc0290b11c24518b704
Author: Stian Soiland-Reyes <st...@apache.org>
Date:   2015-05-12T09:06:29Z

    COMMONSRDF-14 Tests for hashCode requirements

commit 24da09e94a24081478eef19969a4c4be2f7ad66b
Author: Stian Soiland-Reyes <st...@apache.org>
Date:   2015-05-12T09:06:43Z

    COMMONSRDF-14 Update simple for hashCode definition

commit e0d8b5c6187d509004aa3be3865a0a3f2790d0cb
Author: Stian Soiland-Reyes <st...@apache.org>
Date:   2015-05-12T09:16:42Z

    COMMONSRDF-14 Javadoc formatting

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-commonsrdf pull request: COMMONSRDF-14 define explicit h...

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

    https://github.com/apache/incubator-commonsrdf/pull/13


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---