You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by jm...@apache.org on 2024/02/14 04:59:43 UTC
(datasketches-java) 01/01: Correct minor issues flagged by checkstyle and/or IDE
This is an automated email from the ASF dual-hosted git repository.
jmalkin pushed a commit to branch ebpps_cleanup
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit d9166ff5ea086185e9b60f5b01a76d62577d9e33
Author: jmalkin <78...@users.noreply.github.com>
AuthorDate: Tue Feb 13 20:59:29 2024 -0800
Correct minor issues flagged by checkstyle and/or IDE
---
.../datasketches/sampling/EbppsItemsSample.java | 8 ++++----
.../datasketches/sampling/EbppsItemsSketch.java | 24 +++++++++++-----------
.../datasketches/sampling/EbppsSampleTest.java | 2 +-
.../datasketches/sampling/EbppsSketchTest.java | 14 ++++++-------
4 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/sampling/EbppsItemsSample.java b/src/main/java/org/apache/datasketches/sampling/EbppsItemsSample.java
index d85c99ea..26418eb8 100644
--- a/src/main/java/org/apache/datasketches/sampling/EbppsItemsSample.java
+++ b/src/main/java/org/apache/datasketches/sampling/EbppsItemsSample.java
@@ -60,7 +60,7 @@ class EbppsItemsSample<T> {
if (c < 0.0 || Double.isNaN(c) || Double.isInfinite(c))
throw new SketchesArgumentException("C must be nonnegative and finite. Found: " + c);
- c_ = c;
+ c_ = c;
partialItem_ = partialItem;
data_ = data;
rand_ = ThreadLocalRandom.current();
@@ -75,12 +75,12 @@ class EbppsItemsSample<T> {
if (theta < 0.0 || theta > 1.0 || Double.isNaN(theta))
throw new SketchesArgumentException("Theta must be in the range [0.0, 1.0]. Found: " + theta);
- c_ = theta;
+ c_ = theta;
if (theta == 1.0) {
if (data_ != null && data_.size() == 1) {
data_.set(0, item);
} else {
- data_ = new ArrayList<T>(1);
+ data_ = new ArrayList<>(1);
data_.add(item);
}
partialItem_ = null;
@@ -247,7 +247,7 @@ class EbppsItemsSample<T> {
sb.append("\t").append(idx++).append(":\t").append(item.toString()).append(LS);
sb.append(" partial: ");
if (partialItem_ != null)
- sb.append(partialItem_.toString()).append(LS);
+ sb.append(partialItem_).append(LS);
else
sb.append("NULL").append(LS);
diff --git a/src/main/java/org/apache/datasketches/sampling/EbppsItemsSketch.java b/src/main/java/org/apache/datasketches/sampling/EbppsItemsSketch.java
index 7a1a8757..e2abb542 100644
--- a/src/main/java/org/apache/datasketches/sampling/EbppsItemsSketch.java
+++ b/src/main/java/org/apache/datasketches/sampling/EbppsItemsSketch.java
@@ -62,7 +62,7 @@ public class EbppsItemsSketch<T> {
private EbppsItemsSample<T> sample_; // Object holding the current state of the sample
- private EbppsItemsSample<T> tmp_; // temporary storage
+ final private EbppsItemsSample<T> tmp_; // temporary storage
/**
* Constructor
@@ -76,14 +76,13 @@ public class EbppsItemsSketch<T> {
tmp_ = new EbppsItemsSample<>(1);
}
- // private copy constrcutor
+ // private copy constructor
private EbppsItemsSketch(EbppsItemsSketch<T> other) {
k_ = other.k_;
n_ = other.n_;
rho_ = other.rho_;
cumulativeWt_ = other.cumulativeWt_;
wtMax_ = other.wtMax_;
- rho_ = other.rho_;
sample_ = new EbppsItemsSample<>(other.sample_);
tmp_ = new EbppsItemsSample<>(1);
}
@@ -153,7 +152,7 @@ public class EbppsItemsSketch<T> {
}
if (isEmpty)
- return new EbppsItemsSketch<T>(k);
+ return new EbppsItemsSketch<>(k);
final long n = PreambleUtil.extractN(srcMem);
if (n < 0) {
@@ -195,14 +194,14 @@ public class EbppsItemsSketch<T> {
if (numFullItems >= numTotalItems)
throw new SketchesArgumentException("Possible Corruption: Expected partial item but none found");
- data = new ArrayList<>(itemsList.subList(0, numFullItems));
+ data = new ArrayList<>(itemsList.subList(0, numFullItems));
partialItem = itemsList.get(numFullItems); // 0-based, so last item
} else {
data = new ArrayList<>(itemsList);
partialItem = null; // just to be explicit
}
- EbppsItemsSample<T> sample = new EbppsItemsSample<T>(data, partialItem, c);
+ EbppsItemsSample<T> sample = new EbppsItemsSample<>(data, partialItem, c);
return new EbppsItemsSketch<>(sample, k, n, cumWt, maxWt, rho);
}
@@ -268,7 +267,8 @@ public class EbppsItemsSketch<T> {
* @param other the sketch to merge into the current object
*/
public void merge(final EbppsItemsSketch<T> other) {
- if (other.getCumulativeWeight() == 0.0) return;
+ if (other.getCumulativeWeight() == 0.0)
+ return;
else if (other.getCumulativeWeight() > cumulativeWt_) {
// need to swap this with other
// make a copy of other, merge into it, and take the result
@@ -307,15 +307,15 @@ public class EbppsItemsSketch<T> {
final double avgWt = other.cumulativeWt_ / other.getC();
ArrayList<T> items = other.sample_.getFullItems();
if (items != null) {
- for (int i = 0; i < items.size(); ++i) {
+ for (T item : items) {
// newWtMax is pre-computed
final double newCumWt = cumulativeWt_ + avgWt;
final double newRho = Math.min(1.0 / newWtMax, k_ / newCumWt);
if (cumulativeWt_ > 0.0)
sample_.downsample(newRho / rho_);
-
- tmp_.replaceContent(items.get(i), newRho * avgWt);
+
+ tmp_.replaceContent(item, newRho * avgWt);
sample_.merge(tmp_);
cumulativeWt_ = newCumWt;
@@ -335,7 +335,7 @@ public class EbppsItemsSketch<T> {
tmp_.replaceContent(other.sample_.getPartialItem(), newRho * otherCFrac * avgWt);
sample_.merge(tmp_);
- cumulativeWt_ = newCumWt;
+ // cumulativeWt_ will be assigned momentarily
rho_ = newRho;
}
@@ -511,7 +511,7 @@ public class EbppsItemsSketch<T> {
return outArr;
}
- private void checkK(final int k) {
+ private static void checkK(final int k) {
if (k <= 0 || k > MAX_K)
throw new SketchesArgumentException("k must be strictly positive and less than " + MAX_K);
}
diff --git a/src/test/java/org/apache/datasketches/sampling/EbppsSampleTest.java b/src/test/java/org/apache/datasketches/sampling/EbppsSampleTest.java
index e00c216a..eb21be34 100644
--- a/src/test/java/org/apache/datasketches/sampling/EbppsSampleTest.java
+++ b/src/test/java/org/apache/datasketches/sampling/EbppsSampleTest.java
@@ -136,7 +136,7 @@ public class EbppsSampleTest {
for (int i = 1; i <= k; ++i) {
s.replaceContent(i, 1.0);
sample.merge(s);
- assertEquals(sample.getC(), (double) i);
+ assertEquals(sample.getC(), i);
assertEquals(sample.getNumRetainedItems(), i);
}
diff --git a/src/test/java/org/apache/datasketches/sampling/EbppsSketchTest.java b/src/test/java/org/apache/datasketches/sampling/EbppsSketchTest.java
index dde0db66..e6c15112 100644
--- a/src/test/java/org/apache/datasketches/sampling/EbppsSketchTest.java
+++ b/src/test/java/org/apache/datasketches/sampling/EbppsSketchTest.java
@@ -120,8 +120,8 @@ public class EbppsSketchTest {
sk = createUnweightedSketch(k, n);
assertFalse(sk.isEmpty());
assertEquals(sk.getN(), n);
- assertEquals(sk.getC(), (double) k);
- assertEquals(sk.getCumulativeWeight(), (double) n);
+ assertEquals(sk.getC(), k);
+ assertEquals(sk.getCumulativeWeight(), n);
assertEquals(sk.getResult().size(), sk.getK());
for (Integer val : sk.getResult())
assertTrue(val < n);
@@ -131,14 +131,14 @@ public class EbppsSketchTest {
sk = createUnweightedSketch(k, n);
assertFalse(sk.isEmpty());
assertEquals(sk.getN(), n);
- assertEquals(sk.getCumulativeWeight(), (double) n);
- assertEquals(sk.getC(), (double) k, EPS);
+ assertEquals(sk.getCumulativeWeight(), n);
+ assertEquals(sk.getC(), k, EPS);
assertEquals(sk.getResult().size(), sk.getK());
for (Integer val : sk.getResult())
assertTrue(val < n);
// add a very heavy item
- sk.update(n, (double) n);
+ sk.update(n, n);
assertTrue(sk.getC() < sk.getK());
}
@@ -148,7 +148,7 @@ public class EbppsSketchTest {
final EbppsItemsSketch<Integer> sk1 = createUnweightedSketch(k, k);
final EbppsItemsSketch<Integer> sk2 = new EbppsItemsSketch<>(k / 2);
- sk2.update(-1, k / 10.0); // on eheavy item, but less than sk1 weight
+ sk2.update(-1, k / 10.0); // one heavy item, but less than sk1 weight
sk1.merge(sk2);
assertEquals(sk1.getK(), k / 2);
@@ -179,7 +179,7 @@ public class EbppsSketchTest {
@Test
public void serializeDeserializeString() {
// since C <= k we don't have the usual sketch notion of exact vs estimation
- // mode at any time. The only real serializaiton cases are empty and non-empty
+ // mode at any time. The only real serialization cases are empty and non-empty
// with and without a partial item
final int k = 10;
EbppsItemsSketch<String> sk = new EbppsItemsSketch<>(k);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org