github-code-scanning[bot] commented on code in PR #447:
URL: https://github.com/apache/datasketches-java/pull/447#discussion_r1235819900


##########
src/main/java/org/apache/datasketches/common/ArrayOfNumbersSerDe.java:
##########
@@ -144,7 +127,76 @@
               + i + ": " + numType);
       }
     }
-
     return array;
   }
+
+  @Override
+  public int sizeOf(final Number item) {
+    if ( item instanceof Long)         { return Byte.BYTES + Long.BYTES; }

Review Comment:
   ## Chain of 'instanceof' tests
   
   This if block performs a chain of 6 type tests - consider alternatives, e.g. 
polymorphism or the visitor pattern.
   
   [Show more 
details](https://github.com/apache/datasketches-java/security/code-scanning/588)



##########
src/main/java/org/apache/datasketches/common/ArrayOfItemsSerDe.java:
##########
@@ -49,4 +49,34 @@
    */
   public abstract T[] deserializeFromMemory(Memory mem, int numItems);
 
+  /**
+   * Returns the serialized size in bytes of a specific item.
+   * @param item a specific item
+   * @return the serialized size in bytes of a specific item.
+   */
+  public abstract int sizeOf(T item);
+
+  /**
+   * Returns the serialized size in bytes of the array of items.
+   * @param items an array of items.
+   * @return the serialized size in bytes of the array of items.
+   */
+  public int sizeOf(final T[] items) {
+    int bytes = 0;
+    for (int i = 0; i < items.length; i++) {
+      bytes += sizeOf(items[i]);
+    }
+    return bytes;
+  }
+
+  /**
+   * Returns the serialized size in bytes of the number of items.
+   * The capacity of the given Memory can be much larger that the required 
size of the items.
+   * @param mem the given Memory.
+   * @param offset the starting offset in the given Memory.
+   * @param numItems the number of serialized items contained in the Memory
+   * @return the serialized size in bytes of the number of items.
+   */
+  public abstract int sizeOf(Memory mem, long offset, int numItems);

Review Comment:
   ## Useless parameter
   
   The parameter 'offset' is never used.
   
   [Show more 
details](https://github.com/apache/datasketches-java/security/code-scanning/587)



##########
src/main/java/org/apache/datasketches/kll/KllDoublesSketch.java:
##########
@@ -336,6 +350,10 @@
   abstract double getMaxDoubleItem();
 
   abstract double getMinDoubleItem();
+  
+  final int getTheSingleItemBytes() {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [KllSketch.getTheSingleItemBytes](1); it is advisable 
to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/datasketches-java/security/code-scanning/590)



##########
src/main/java/org/apache/datasketches/common/ArrayOfNumbersSerDe.java:
##########
@@ -144,7 +127,76 @@
               + i + ": " + numType);
       }
     }
-
     return array;
   }
+
+  @Override
+  public int sizeOf(final Number item) {
+    if ( item instanceof Long)         { return Byte.BYTES + Long.BYTES; }
+    else if ( item instanceof Integer) { return Byte.BYTES + Integer.BYTES; }
+    else if ( item instanceof Short)   { return Byte.BYTES + Short.BYTES; }
+    else if ( item instanceof Byte)    { return Byte.BYTES + Byte.BYTES; }
+    else if ( item instanceof Double)  { return Byte.BYTES + Double.BYTES; }
+    else if ( item instanceof Float)   { return Byte.BYTES + Float.BYTES; }
+    else { throw new SketchesArgumentException(
+        "Item must be one of: Long, Integer, Short, Byte, Double, Float"); }
+  }
+
+  @Override
+  public int sizeOf(final Number[] items) {
+    int bytes = 0;
+    for (final Number item: items) {
+      if (item instanceof Long)         { bytes += Byte.BYTES + Long.BYTES; }

Review Comment:
   ## Chain of 'instanceof' tests
   
   This if block performs a chain of 6 type tests - consider alternatives, e.g. 
polymorphism or the visitor pattern.
   
   [Show more 
details](https://github.com/apache/datasketches-java/security/code-scanning/589)



##########
src/main/java/org/apache/datasketches/kll/KllFloatsSketch.java:
##########
@@ -336,6 +350,10 @@
   abstract float getMaxFloatItem();
 
   abstract float getMinFloatItem();
+  
+  final int getTheSingleItemBytes() {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [KllSketch.getTheSingleItemBytes](1); it is advisable 
to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/datasketches-java/security/code-scanning/591)



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to