You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/08/27 15:32:22 UTC

[GitHub] [jena] afs commented on a change in pull request #785: JENA-1936: Value-equality indexing for binary datatypes

afs commented on a change in pull request #785:
URL: https://github.com/apache/jena/pull/785#discussion_r478508997



##########
File path: jena-core/src/main/java/org/apache/jena/graph/impl/LiteralLabelImpl.java
##########
@@ -303,20 +304,59 @@ public String getLexicalForm() {
 		return lexicalForm;
 	}
     
-    /** 
-     	Answer the value used to index this literal
-        TODO Consider pushing indexing decisions down to the datatype
-    */
+    /**
+     * Answer an object used to index this literal. This object must provide
+     * {@link Object#equals} and {@link Object#hashCode} based on values, not object
+     * instance identity.
+     */
     @Override
     public Object getIndexingValue() {
-        return
-            isXML() ? this
-            : !lang.equals( "" ) ? getLexicalForm() + "@" + lang.toLowerCase(Locale.ROOT)
-            : wellformed ? getValue()
-            : getLexicalForm() 
-            ;
+        if ( isXML() )
+            return this;
+        if ( !lang.equals("") )
+            return getLexicalForm() + "@" + lang.toLowerCase(Locale.ROOT);
+        if ( wellformed ) {
+            Object value = getValue();
+            // JENA-1936
+            // byte[] does not provide hashCode/equals based on the contents of the array.
+            if ( value instanceof byte[] )
+                return new ByteArray((byte[])value);
+            return value;
+        }
+        return getLexicalForm();
     }
 
+    /**
+     * {@code byte[]} wrapper that provides {@code hashCode} and {@code equals} based
+     * on the value of the array.
+     */
+    static class ByteArray {
+        private final byte[] bytes;
+        /*package*/ ByteArray(byte[] bytes) {

Review comment:
       OK - done. We are assuming the `byte[]` isn't changing.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org