This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch Fix_getResultAndReset
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git

commit 8841d5afcd48c34bc20ef82159ce2818f110e75d
Author: Lee Rhodes <[email protected]>
AuthorDate: Mon Aug 4 16:48:32 2025 -0700

    This fixes the "getResultAndReset" issue flagged by Copilot.
---
 .../quantiles/DirectUpdateDoublesSketch.java       | 31 +++++++----
 .../quantiles/DirectUpdateDoublesSketchR.java      | 20 ++++---
 .../datasketches/quantiles/DoublesUnionImpl.java   |  2 +-
 .../quantiles/HeapUpdateDoublesSketch.java         | 60 ++++++++++-----------
 .../apache/datasketches/quantiles/ItemsSketch.java | 55 +++++++++++--------
 .../apache/datasketches/quantiles/ItemsUnion.java  | 61 ++++++++++------------
 .../quantiles/UpdateDoublesSketch.java             |  2 +-
 .../datasketches/quantiles/ItemsSketchTest.java    | 20 +++----
 .../datasketches/quantiles/ItemsUnionTest.java     |  8 +--
 .../QuantilesSketchCrossLanguageTest.java          |  2 +-
 .../datasketches/quantiles/ReadOnlyMemoryTest.java |  2 +-
 .../quantiles/SerDeCompatibilityTest.java          |  2 +-
 12 files changed, 142 insertions(+), 123 deletions(-)

diff --git 
a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java
 
b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java
index dbf34c81e..fdbbf4602 100644
--- 
a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java
+++ 
b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java
@@ -100,8 +100,9 @@ final class DirectUpdateDoublesSketch extends 
DirectUpdateDoublesSketchR {
     return new DirectUpdateDoublesSketch(k, dstSeg, mSegReq);
   }
 
-  static DirectUpdateDoublesSketch(final DirectUpdateDoublesSketch skIn) {
-    return null;
+  static HeapUpdateDoublesSketch heapify(final DirectUpdateDoublesSketch skIn) 
{
+    final MemorySegment segIn = skIn.getMemorySegment();
+    return HeapUpdateDoublesSketch.heapifyInstance(segIn);
   }
 
   /**
@@ -214,6 +215,23 @@ final class DirectUpdateDoublesSketch extends 
DirectUpdateDoublesSketchR {
   }
 
   //Restricted overrides
+
+  @Override
+  HeapUpdateDoublesSketch getSketchAndReset() {
+    final HeapUpdateDoublesSketch skCopy = heapify(this);
+    reset();
+    return skCopy;
+  }
+
+  @Override
+  double[] growCombinedBuffer(final int curCombBufItemCap, final int 
itemSpaceNeeded) {
+    seg_ = growCombinedSegBuffer(itemSpaceNeeded);
+    // copy out any data that was there
+    final double[] newCombBuf = new double[itemSpaceNeeded];
+    MemorySegment.copy(seg_, JAVA_DOUBLE_UNALIGNED, COMBINED_BUFFER, 
newCombBuf, 0, curCombBufItemCap);
+    return newCombBuf;
+  }
+
   //Puts
 
   @Override
@@ -249,15 +267,6 @@ final class DirectUpdateDoublesSketch extends 
DirectUpdateDoublesSketchR {
     //intentionally a no-op, not kept on-heap, always derived.
   }
 
-  @Override
-  double[] growCombinedBuffer(final int curCombBufItemCap, final int 
itemSpaceNeeded) {
-    seg_ = growCombinedSegBuffer(itemSpaceNeeded);
-    // copy out any data that was there
-    final double[] newCombBuf = new double[itemSpaceNeeded];
-    MemorySegment.copy(seg_, JAVA_DOUBLE_UNALIGNED, COMBINED_BUFFER, 
newCombBuf, 0, curCombBufItemCap);
-    return newCombBuf;
-  }
-
   //Direct supporting methods
 
   private MemorySegment growCombinedSegBuffer(final int itemSpaceNeeded) {
diff --git 
a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketchR.java
 
b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketchR.java
index a59a9121b..b1a403c14 100644
--- 
a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketchR.java
+++ 
b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketchR.java
@@ -160,7 +160,6 @@ class DirectUpdateDoublesSketchR extends 
UpdateDoublesSketch {
     final double[] combinedBuffer = new double[itemCap];
     MemorySegment.copy(seg_, JAVA_DOUBLE_UNALIGNED, COMBINED_BUFFER, 
combinedBuffer, 0, itemCap);
 
-
     return combinedBuffer;
   }
 
@@ -176,41 +175,46 @@ class DirectUpdateDoublesSketchR extends 
UpdateDoublesSketch {
     return seg_;
   }
 
+  @Override
+  UpdateDoublesSketch getSketchAndReset() {
+    throw new SketchesReadOnlyException("Call to getResultAndReset() on 
read-only sketch");
+  }
+
   //Puts
 
   @Override
   void putMinItem(final double minQuantile) {
-    throw new SketchesReadOnlyException("Call to putMinQuantile() on read-only 
buffer");
+    throw new SketchesReadOnlyException("Call to putMinQuantile() on read-only 
sketch");
   }
 
   @Override
   void putMaxItem(final double maxQuantile) {
-    throw new SketchesReadOnlyException("Call to putMaxQuantile() on read-only 
buffer");
+    throw new SketchesReadOnlyException("Call to putMaxQuantile() on read-only 
sketch");
   }
 
   @Override
   void putN(final long n) {
-    throw new SketchesReadOnlyException("Call to putN() on read-only buffer");
+    throw new SketchesReadOnlyException("Call to putN() on read-only sketch");
   }
 
   @Override
   void putCombinedBuffer(final double[] combinedBuffer) {
-    throw new SketchesReadOnlyException("Call to putCombinedBuffer() on 
read-only buffer");
+    throw new SketchesReadOnlyException("Call to putCombinedBuffer() on 
read-only sketch");
   }
 
   @Override
   void putBaseBufferCount(final int baseBufferCount) {
-    throw new SketchesReadOnlyException("Call to putBaseBufferCount() on 
read-only buffer");
+    throw new SketchesReadOnlyException("Call to putBaseBufferCount() on 
read-only sketch");
   }
 
   @Override
   void putBitPattern(final long bitPattern) {
-    throw new SketchesReadOnlyException("Call to putBaseBufferCount() on 
read-only buffer");
+    throw new SketchesReadOnlyException("Call to putBaseBufferCount() on 
read-only sketch");
   }
 
   @Override
   double[] growCombinedBuffer(final int curCombBufItemCap, final int 
itemSpaceNeeded) {
-    throw new SketchesReadOnlyException("Call to growCombinedBuffer() on 
read-only buffer");
+    throw new SketchesReadOnlyException("Call to growCombinedBuffer() on 
read-only sketch");
   }
 
   //Checks
diff --git 
a/src/main/java/org/apache/datasketches/quantiles/DoublesUnionImpl.java 
b/src/main/java/org/apache/datasketches/quantiles/DoublesUnionImpl.java
index e36f6e825..c3530e0b2 100644
--- a/src/main/java/org/apache/datasketches/quantiles/DoublesUnionImpl.java
+++ b/src/main/java/org/apache/datasketches/quantiles/DoublesUnionImpl.java
@@ -143,7 +143,7 @@ final class DoublesUnionImpl extends DoublesUnionImplR {
   @Override
   public UpdateDoublesSketch getResultAndReset() {
     if (gadget_ == null) { return null; } //Intentionally return null here for 
speed.
-    final UpdateDoublesSketch ds = gadget_;
+    final UpdateDoublesSketch ds = gadget_.getSketchAndReset();
     gadget_ = null;
     return ds;
   }
diff --git 
a/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java 
b/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java
index 30a2bdd9b..350f8cb3f 100644
--- 
a/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java
+++ 
b/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java
@@ -141,13 +141,13 @@ final class HeapUpdateDoublesSketch extends 
UpdateDoublesSketch {
   /**
    * Heapifies the given srcSeg, which must be a MemorySegment image of a 
DoublesSketch and may have data.
    *
-   * @param srcSeg a MemorySegment image of a sketch, which may be in compact 
or not compact form.
+   * @param srcSeg a MemorySegment image of a sketch, which may be in compact 
or updatable form.
    * @return a DoublesSketch on the Java heap.
    */
   static HeapUpdateDoublesSketch heapifyInstance(final MemorySegment srcSeg) {
     final long segCapBytes = srcSeg.byteSize();
-    if (segCapBytes < 8) {
-      throw new SketchesArgumentException("Source MemorySegment too small: " + 
segCapBytes + " < 8");
+    if ((segCapBytes < 8) || (segCapBytes > Integer.MAX_VALUE)) {
+      throw new SketchesArgumentException("Source MemorySegment byteSize must 
be >= 8 and <= Integer.MAX_VALUE: " + segCapBytes);
     }
 
     final int preLongs = extractPreLongs(srcSeg);
@@ -203,13 +203,6 @@ final class HeapUpdateDoublesSketch extends 
UpdateDoublesSketch {
     return n_;
   }
 
-  @Override
-  HeapUpdateDoublesSketch getResultAndReset() {
-    final HeapUpdateDoublesSketch skCopy = HeapUpdateDoublesSketch.copy(this);
-    reset();
-    return skCopy;
-  }
-
   @Override
   public boolean hasMemorySegment() {
     return false;
@@ -361,8 +354,8 @@ final class HeapUpdateDoublesSketch extends 
UpdateDoublesSketch {
   }
 
   @Override
-  int getCombinedBufferItemCapacity() {
-    return combinedBuffer_.length;
+  long getBitPattern() {
+    return bitPattern_;
   }
 
   @Override
@@ -371,8 +364,8 @@ final class HeapUpdateDoublesSketch extends 
UpdateDoublesSketch {
   }
 
   @Override
-  long getBitPattern() {
-    return bitPattern_;
+  int getCombinedBufferItemCapacity() {
+    return combinedBuffer_.length;
   }
 
   @Override
@@ -380,21 +373,29 @@ final class HeapUpdateDoublesSketch extends 
UpdateDoublesSketch {
     return null;
   }
 
-  //Puts
-
   @Override
-  void putMinItem(final double minItem) {
-    minItem_ = minItem;
+  HeapUpdateDoublesSketch getSketchAndReset() {
+    final HeapUpdateDoublesSketch skCopy = HeapUpdateDoublesSketch.copy(this);
+    reset();
+    return skCopy;
+  }
+
+  @Override //the returned array is not always used
+  double[] growCombinedBuffer(final int currentSpace, final int spaceNeeded) {
+    combinedBuffer_ = Arrays.copyOf(combinedBuffer_, spaceNeeded);
+    return combinedBuffer_;
   }
 
+  //Puts
+
   @Override
-  void putMaxItem(final double maxItem) {
-    maxItem_ = maxItem;
+  void putBaseBufferCount(final int baseBufferCount) {
+    baseBufferCount_ = baseBufferCount;
   }
 
   @Override
-  void putN(final long n) {
-    n_ = n;
+  void putBitPattern(final long bitPattern) {
+    bitPattern_ = bitPattern;
   }
 
   @Override
@@ -403,19 +404,18 @@ final class HeapUpdateDoublesSketch extends 
UpdateDoublesSketch {
   }
 
   @Override
-  void putBaseBufferCount(final int baseBufferCount) {
-    baseBufferCount_ = baseBufferCount;
+  void putMaxItem(final double maxItem) {
+    maxItem_ = maxItem;
   }
 
   @Override
-  void putBitPattern(final long bitPattern) {
-    bitPattern_ = bitPattern;
+  void putMinItem(final double minItem) {
+    minItem_ = minItem;
   }
 
-  @Override //the returned array is not always used
-  double[] growCombinedBuffer(final int currentSpace, final int spaceNeeded) {
-    combinedBuffer_ = Arrays.copyOf(combinedBuffer_, spaceNeeded);
-    return combinedBuffer_;
+  @Override
+  void putN(final long n) {
+    n_ = n;
   }
 
   /**
diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java 
b/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java
index b8d228989..fa856c8d0 100644
--- a/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java
+++ b/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java
@@ -72,7 +72,7 @@ import 
org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator;
  *
  * @see QuantilesAPI
  *
- * @param <T> The sketch data type
+ * @param <T> The sketch item data type.
  */
 public final class ItemsSketch<T> implements QuantilesGenericAPI<T> {
   final Class<T> clazz;
@@ -124,6 +124,8 @@ public final class ItemsSketch<T> implements 
QuantilesGenericAPI<T> {
    */
   public static final Random rand = new Random();
 
+  //**Constructors**
+
   private ItemsSketch(
       final int k,
       final Class<T> clazz,
@@ -138,9 +140,9 @@ public final class ItemsSketch<T> implements 
QuantilesGenericAPI<T> {
 
   /**
    * Obtains a new instance of an ItemsSketch using the DEFAULT_K.
-   * @param <T> The sketch data type
-   * @param clazz the given class of T
-   * @param comparator to compare items
+   * @param <T> The sketch item data type.
+   * @param clazz the given class of T.
+   * @param comparator to compare items.
    * @return an ItemSketch&lt;T&gt;.
    */
   public static <T> ItemsSketch<T> getInstance(
@@ -150,12 +152,12 @@ public final class ItemsSketch<T> implements 
QuantilesGenericAPI<T> {
   }
 
   /**
-   * Obtains a new instance of an ItemsSketch.
-   * @param <T> The sketch data type
-   * @param clazz the given class of T
+   * Obtains a new instance of an ItemsSketch using the given <i>k</i>.
+   * @param <T> The sketch item data type.
+   * @param clazz the given class of T.
    * @param k Parameter that controls space usage of sketch and accuracy of 
estimates.
    * Must be greater than 2 and less than 65536 and a power of 2.
-   * @param comparator to compare items
+   * @param comparator to compare items.
    * @return an ItemSketch&lt;T&gt;.
    */
   public static <T> ItemsSketch<T> getInstance(
@@ -175,15 +177,15 @@ public final class ItemsSketch<T> implements 
QuantilesGenericAPI<T> {
   }
 
   /**
-   * Heapifies the given srcSeg, which must be a MemorySegment image of a 
ItemsSketch
-   * @param clazz the given class of T
-   * @param srcSeg a MemorySegment image of a sketch.
-   * @param comparator to compare items
-   * @param serDe an instance of ArrayOfItemsSerDe
-   * @param <T> The sketch data type
-   * @return a ItemSketch&lt;T&gt; on the Java heap.
+   * Heapifies the given srcSeg, which must be a MemorySegment image of a 
ItemsSketch.
+   * @param <T> The sketch item data type.
+   * @param clazz the given class of T.
+   * @param srcSeg a MemorySegment image of a sketch generated from this class.
+   * @param comparator to compare items.
+   * @param serDe an instance of ArrayOfItemsSerDe.
+   * @return a ItemsSketch&lt;T&gt; on the Java heap.
    */
-  public static <T> ItemsSketch<T> getInstance(
+  public static <T> ItemsSketch<T> heapify(
       final Class<T> clazz,
       final MemorySegment srcSeg,
       final Comparator<? super T> comparator,
@@ -192,7 +194,6 @@ public final class ItemsSketch<T> implements 
QuantilesGenericAPI<T> {
     if (segCapBytes < 8) {
       throw new SketchesArgumentException("MemorySegment too small: " + 
segCapBytes);
     }
-
     final int preambleLongs = extractPreLongs(srcSeg);
     final int serVer = extractSerVer(srcSeg);
     final int familyID = extractFamilyID(srcSeg);
@@ -233,10 +234,10 @@ public final class ItemsSketch<T> implements 
QuantilesGenericAPI<T> {
   }
 
   /**
-   * Returns a copy of the given sketch
-   * @param <T> The sketch data type
-   * @param sketch the given sketch
-   * @return a copy of the given sketch
+   * Returns a copy of the given sketch.
+   * @param <T> The sketch item data type.
+   * @param sketch the given sketch.
+   * @return a copy of the given sketch.
    */
   static <T> ItemsSketch<T> copy(final ItemsSketch<T> sketch) {
     final ItemsSketch<T> qsCopy = ItemsSketch.getInstance(sketch.clazz, 
sketch.k_, sketch.comparator_);
@@ -251,7 +252,7 @@ public final class ItemsSketch<T> implements 
QuantilesGenericAPI<T> {
     return qsCopy;
   }
 
-  //END of Constructors
+  //**END of Constructors**
 
   @Override
   public double[] getCDF(final T[] splitPoints, final QuantileSearchCriteria 
searchCrit) {
@@ -581,6 +582,16 @@ public final class ItemsSketch<T> implements 
QuantilesGenericAPI<T> {
     return combinedBuffer_;
   }
 
+  /**
+   * Returns a copy of this sketch and then resets.
+   * @return a copy of this sketch and then resets.
+   */
+  ItemsSketch<T> getSketchAndReset() {
+    final ItemsSketch<T> skCopy = copy(this);
+    reset();
+    return skCopy;
+  }
+
   /**
    * Loads the Combined Buffer, min and max from the given items array.
    * The Combined Buffer is always in non-compact form and must be 
pre-allocated.
diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsUnion.java 
b/src/main/java/org/apache/datasketches/quantiles/ItemsUnion.java
index 8afbbc573..7473c0f20 100644
--- a/src/main/java/org/apache/datasketches/quantiles/ItemsUnion.java
+++ b/src/main/java/org/apache/datasketches/quantiles/ItemsUnion.java
@@ -30,7 +30,7 @@ import org.apache.datasketches.common.ArrayOfItemsSerDe;
 /**
  * The API for Union operations for generic ItemsSketches
  *
- * @param <T> type of item
+ * @param <T> The sketch item data type.
  *
  * @author Lee Rhodes
  * @author Alexander Saydakov
@@ -56,11 +56,11 @@ public final class ItemsUnion<T> {
   }
 
   /**
-   * Create an instance of ItemsUnion with the default k
-   * @param <T> The sketch data type
-   * @param clazz The sketch class type
-   * @param comparator to compare items
-   * @return an instance of ItemsUnion
+   * Create an instance of ItemsUnion with the default k.
+   * @param <T> The sketch item data type.
+   * @param clazz The sketch class type.
+   * @param comparator to compare items.
+   * @return a new instance of ItemsUnion
    */
   public static <T> ItemsUnion<T> getInstance(
       final Class<T> clazz,
@@ -71,14 +71,13 @@ public final class ItemsUnion<T> {
 
   /**
    * Create an instance of ItemsUnion
-   * @param clazz The sketch class type
-   * @param <T> The sketch data type
+   * @param <T> The sketch item data type.
+   * @param clazz The sketch class type.
    * @param maxK determines the accuracy and size of the union and is a 
maximum.
    * The effective <i>k</i> can be smaller due to unions with smaller <i>k</i> 
sketches.
-   * It is recommended that <i>maxK</i> be a power of 2 to enable unioning of 
sketches with a
-   * different <i>k</i>.
-   * @param comparator to compare items
-   * @return an instance of ItemsUnion
+   * <i>maxK</i> must be a power of 2 to enable unioning of sketches with a 
different <i>k</i>.
+   * @param comparator to compare items.
+   * @return an new instance of ItemsUnion
    */
   public static <T> ItemsUnion<T> getInstance(
       final Class<T> clazz,
@@ -89,31 +88,30 @@ public final class ItemsUnion<T> {
   }
 
   /**
-   * Heapify the given srcSeg into a Union object.
-   * @param clazz The sketch class type
-   * A reference to srcSeg will not be maintained internally.
-   * @param srcSeg the given srcSeg.
-   * @param comparator to compare items
-   * @param serDe an instance of ArrayOfItemsSerDe
-   * @param <T> The sketch data type
-   * @return an instance of ItemsUnion
+   * Initialize a new ItemsUnion with a heapified instance of an ItemsSketch 
from a MemorySegment.
+   * @param <T> The sketch data type.
+   * @param clazz The sketch class type.
+   * @param srcSeg the given srcSeg, an image of an ItemsSketch. A reference 
to srcSeg will not be maintained internally.
+   * @param comparator to compare items.
+   * @param serDe an instance of ArrayOfItemsSerDe.
+   * @return an ItemsUnion initialized with a heapified ItemsSketch from a 
MemorySegment.
    */
-  public static <T> ItemsUnion<T> getInstance(
+  public static <T> ItemsUnion<T> initializeWithMemorySegment(
       final Class<T> clazz,
       final MemorySegment srcSeg,
       final Comparator<? super T> comparator,
       final ArrayOfItemsSerDe<T> serDe) {
-    final ItemsSketch<T> gadget = ItemsSketch.getInstance(clazz, srcSeg, 
comparator, serDe);
+    final ItemsSketch<T> gadget = ItemsSketch.heapify(clazz, srcSeg, 
comparator, serDe);
     return new ItemsUnion<>(gadget.getK(), gadget.getComparator(), gadget);
   }
 
   /**
-   * Create an instance of ItemsUnion based on ItemsSketch
+   * Initialize a new ItemsUnion with an instance of ItemsSketch
    * @param <T> The sketch data type
-   * @param sketch the basis of the union
-   * @return an instance of ItemsUnion
+   * @param sketch an instance of ItemsSketch to initialize this union
+   * @return an initialized instance of ItemsUnion
    */
-  public static <T> ItemsUnion<T> getInstance(final ItemsSketch<T> sketch) {
+  public static <T> ItemsUnion<T> initialize(final ItemsSketch<T> sketch) {
     return new ItemsUnion<>(sketch.getK(), sketch.getComparator(), 
ItemsSketch.copy(sketch));
   }
 
@@ -150,7 +148,7 @@ public final class ItemsUnion<T> {
   public void union(
       final MemorySegment srcSeg,
       final ArrayOfItemsSerDe<T> serDe) {
-    final ItemsSketch<T> that = ItemsSketch.getInstance(clazz_, srcSeg, 
comparator_, serDe);
+    final ItemsSketch<T> that = ItemsSketch.heapify(clazz_, srcSeg, 
comparator_, serDe);
     gadget_ = updateLogic(maxK_, comparator_, gadget_, that);
   }
 
@@ -180,16 +178,13 @@ public final class ItemsUnion<T> {
   }
 
   /**
-   * Gets the result of this Union operation (without a copy) and resets this 
Union to the
-   * virgin state.
+   * Gets the sketch result of this Union operation and resets this Union to 
the virgin state.
    *
    * @return the result of this Union operation and reset.
    */
-  public ItemsSketch<T> getResultAndReset() {
+  public ItemsSketch<T> getResultAndReset() { //TODO
     if (gadget_ == null) { return null; } //Intentionally return null here for 
speed.
-    final ItemsSketch<T> hqs = gadget_;
-    gadget_ = null;
-    return hqs;
+    return gadget_.getSketchAndReset();
   }
 
   /**
diff --git 
a/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java 
b/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java
index ba9309f5f..8daa39ba5 100644
--- a/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java
+++ b/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java
@@ -76,7 +76,7 @@ public abstract class UpdateDoublesSketch extends 
DoublesSketch {
    * Returns a copy of this sketch and then resets this sketch with the same 
value of <i>k</i>.
    * @return a copy of this sketch and then resets this sketch with the same 
value of <i>k</i>.
    */
-  abstract UpdateDoublesSketch getResultAndReset();
+  abstract UpdateDoublesSketch getSketchAndReset();
 
   /**
    * Grows the combined buffer to the given spaceNeeded
diff --git 
a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java 
b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java
index 297bf9e66..86b40496c 100644
--- a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java
+++ b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchTest.java
@@ -263,7 +263,7 @@ public class ItemsSketchTest {
     final ArrayOfItemsSerDe<Long> serDe = new ArrayOfLongsSerDe();
     final byte[] bytes = sketch1.toByteArray(serDe);
     final ItemsSketch<Long> sketch2 =
-        ItemsSketch.getInstance(Long.class, MemorySegment.ofArray(bytes), 
Comparator.naturalOrder(), serDe);
+        ItemsSketch.heapify(Long.class, MemorySegment.ofArray(bytes), 
Comparator.naturalOrder(), serDe);
 
     for (int i = 501; i <= 1000; i++) {
       sketch2.update((long) i);
@@ -286,7 +286,7 @@ public class ItemsSketchTest {
     final ArrayOfItemsSerDe<Double> serDe = new ArrayOfDoublesSerDe();
     final byte[] bytes = sketch1.toByteArray(serDe);
     final ItemsSketch<Double> sketch2 =
-        ItemsSketch.getInstance(Double.class, MemorySegment.ofArray(bytes), 
Comparator.naturalOrder(), serDe);
+        ItemsSketch.heapify(Double.class, MemorySegment.ofArray(bytes), 
Comparator.naturalOrder(), serDe);
 
     for (int i = 501; i <= 1000; i++) {
       sketch2.update((double) i);
@@ -318,7 +318,7 @@ public class ItemsSketchTest {
 
     final ArrayOfItemsSerDe<String> serDe = new ArrayOfStringsSerDe();
     final byte[] bytes = sketch1.toByteArray(serDe);
-    final ItemsSketch<String> sketch2 = ItemsSketch.getInstance(String.class, 
MemorySegment.ofArray(bytes), numericOrder, serDe);
+    final ItemsSketch<String> sketch2 = ItemsSketch.heapify(String.class, 
MemorySegment.ofArray(bytes), numericOrder, serDe);
 
     for (int i = 501; i <= 1000; i++) {
       sketch2.update(Integer.toBinaryString(i << 10));
@@ -384,13 +384,13 @@ public class ItemsSketchTest {
   @Test(expectedExceptions = SketchesArgumentException.class)
   public void checkGetInstanceExcep1() {
     final MemorySegment seg = MemorySegment.ofArray(new byte[4]);
-    ItemsSketch.getInstance(String.class, seg, Comparator.naturalOrder(), new 
ArrayOfStringsSerDe());
+    ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), new 
ArrayOfStringsSerDe());
   }
 
   @Test(expectedExceptions = SketchesArgumentException.class)
   public void checkGetInstanceExcep2() {
     final MemorySegment seg = MemorySegment.ofArray(new byte[8]);
-    ItemsSketch.getInstance(String.class, seg, Comparator.naturalOrder(), new 
ArrayOfStringsSerDe());
+    ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), new 
ArrayOfStringsSerDe());
   }
 
   @Test
@@ -398,7 +398,7 @@ public class ItemsSketchTest {
     final ItemsSketch<String> sketch = ItemsSketch.getInstance(String.class, 
Comparator.naturalOrder());
     final byte[] byteArr = sketch.toByteArray(new ArrayOfStringsSerDe());
     final MemorySegment seg = MemorySegment.ofArray(byteArr);
-    ItemsSketch.getInstance(String.class, seg, Comparator.naturalOrder(), new 
ArrayOfStringsSerDe());
+    ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), new 
ArrayOfStringsSerDe());
   }
 
   @Test
@@ -440,7 +440,7 @@ public class ItemsSketchTest {
     final MemorySegment seg = MemorySegment.ofArray(byteArr);
     clearBits(seg, PreambleUtil.FLAGS_BYTE, (byte) 
PreambleUtil.COMPACT_FLAG_MASK);
     println(PreambleUtil.toString(seg, false));
-    ItemsSketch.getInstance(Double.class, seg, Comparator.naturalOrder(), 
serDe);
+    ItemsSketch.heapify(Double.class, seg, Comparator.naturalOrder(), serDe);
   }
 
   @Test
@@ -564,7 +564,7 @@ public class ItemsSketchTest {
     //ordered
     byteArr = is.toByteArray(true, serDe);
     seg = MemorySegment.ofArray(byteArr);
-    is2 = ItemsSketch.getInstance(String.class, seg, 
Comparator.naturalOrder(), serDe);
+    is2 = ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), 
serDe);
     for (double f = 0.1; f < 0.95; f += 0.1) {
       assertEquals(is.getQuantile(f), is2.getQuantile(f));
     }
@@ -572,7 +572,7 @@ public class ItemsSketchTest {
     //Not-ordered
     byteArr = is.toByteArray(false, serDe);
     seg = MemorySegment.ofArray(byteArr);
-    is2 = ItemsSketch.getInstance(String.class, seg, 
Comparator.naturalOrder(), serDe);
+    is2 = ItemsSketch.heapify(String.class, seg, Comparator.naturalOrder(), 
serDe);
     for (double f = 0.1; f < 0.95; f += 0.1) {
       assertEquals(is.getQuantile(f), is2.getQuantile(f));
     }
@@ -622,7 +622,7 @@ public class ItemsSketchTest {
     for (int i = 0; i < items.length; i++) { sketch.update(items[i]); }
     final byte[] serialized = sketch.toByteArray(new ArrayOfBooleansSerDe());
     final ItemsSketch<Boolean> deserialized =
-        ItemsSketch.getInstance(Boolean.class, 
MemorySegment.ofArray(serialized), Boolean::compareTo, new 
ArrayOfBooleansSerDe());
+        ItemsSketch.heapify(Boolean.class, MemorySegment.ofArray(serialized), 
Boolean::compareTo, new ArrayOfBooleansSerDe());
     checkSketchesEqual(sketch, deserialized);
   }
 
diff --git 
a/src/test/java/org/apache/datasketches/quantiles/ItemsUnionTest.java 
b/src/test/java/org/apache/datasketches/quantiles/ItemsUnionTest.java
index 6953bc97f..31281c768 100644
--- a/src/test/java/org/apache/datasketches/quantiles/ItemsUnionTest.java
+++ b/src/test/java/org/apache/datasketches/quantiles/ItemsUnionTest.java
@@ -42,7 +42,7 @@ public class ItemsUnionTest {
     ItemsUnion<Integer> union = ItemsUnion.getInstance(Integer.class, 
Comparator.naturalOrder());
     union.union(validSk);
 
-    union = ItemsUnion.getInstance(emptySk);
+    union = ItemsUnion.initialize(emptySk);
     // internal sketch is empty at this point
     union.union((ItemsSketch<Integer>) null);
     union.union(emptySk);
@@ -113,11 +113,11 @@ public class ItemsUnionTest {
     final Comparator<String> comp = Comparator.naturalOrder();
     final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
     final ItemsSketch<String> sketch = ItemsSketch.getInstance(String.class, 
comp);
-    ItemsUnion<String> union = ItemsUnion.getInstance(sketch);
+    ItemsUnion<String> union = ItemsUnion.initialize(sketch);
     union.reset();
     final byte[] byteArr = sketch.toByteArray(serDe);
     final MemorySegment seg = MemorySegment.ofArray(byteArr);
-    union = ItemsUnion.getInstance(String.class, seg, comp, serDe);
+    union = ItemsUnion.initializeWithMemorySegment(String.class, seg, comp, 
serDe);
     Assert.assertEquals(byteArr.length, 8);
     union.reset();
   }
@@ -372,7 +372,7 @@ public class ItemsUnionTest {
 
     final byte[] byteArr = buildIS(k, (2 * k) + 5).toByteArray(serDe);
     final MemorySegment seg = MemorySegment.ofArray(byteArr);
-    union = ItemsUnion.getInstance(Long.class, seg, Comparator.naturalOrder(), 
serDe);
+    union = ItemsUnion.initializeWithMemorySegment(Long.class, seg, 
Comparator.naturalOrder(), serDe);
     bytesOut = union.toByteArray(serDe);
     Assert.assertEquals(bytesOut.length, byteArr.length);
     Assert.assertEquals(bytesOut, byteArr); // assumes consistent internal use 
of toByteArray()
diff --git 
a/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
 
b/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
index 8e60bfe8f..20ceab5ca 100644
--- 
a/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
+++ 
b/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
@@ -129,7 +129,7 @@ public class QuantilesSketchCrossLanguageTest {
     final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
     for (final int n: nArr) {
       final byte[] byteArr = 
Files.readAllBytes(cppPath.resolve("quantiles_string_n" + n + "_cpp.sk"));
-      final ItemsSketch<String> sk = ItemsSketch.getInstance(
+      final ItemsSketch<String> sk = ItemsSketch.heapify(
           String.class,
           MemorySegment.ofArray(byteArr),
           numericOrder,
diff --git 
a/src/test/java/org/apache/datasketches/quantiles/ReadOnlyMemoryTest.java 
b/src/test/java/org/apache/datasketches/quantiles/ReadOnlyMemoryTest.java
index c5093b70d..42d9a0357 100644
--- a/src/test/java/org/apache/datasketches/quantiles/ReadOnlyMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/quantiles/ReadOnlyMemoryTest.java
@@ -259,7 +259,7 @@ public class ReadOnlyMemoryTest {
     try {
       u.getResultAndReset();
       fail();
-    } catch (final AssertionError e) { //null
+    } catch (final IllegalArgumentException e) { //null
       // expected
     }
   }
diff --git 
a/src/test/java/org/apache/datasketches/quantiles/SerDeCompatibilityTest.java 
b/src/test/java/org/apache/datasketches/quantiles/SerDeCompatibilityTest.java
index 958254524..d6d7eb9e3 100644
--- 
a/src/test/java/org/apache/datasketches/quantiles/SerDeCompatibilityTest.java
+++ 
b/src/test/java/org/apache/datasketches/quantiles/SerDeCompatibilityTest.java
@@ -60,7 +60,7 @@ public class SerDeCompatibilityTest {
     final byte[] bytes = cs.toByteArray(); // must be compact
 
     //reconstruct with ItemsSketch
-    final ItemsSketch<Double> sketch2 = ItemsSketch.getInstance(Double.class, 
MemorySegment.ofArray(bytes),
+    final ItemsSketch<Double> sketch2 = ItemsSketch.heapify(Double.class, 
MemorySegment.ofArray(bytes),
         Comparator.naturalOrder(), serDe);
 
     for (int i = 501; i <= 1000; i++) { sketch2.update((double) i); }


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

Reply via email to