Skip to content

Commit

Permalink
Exception class renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
liancheng committed Jan 25, 2016
1 parent 12bbefb commit 4abc4e0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ public int getVersionNumber() {
* Note that only Count-Min sketches with the same {@code depth}, {@code width}, and random seed
* can be merged.
*
* @exception CountMinSketchMergeException if the {@code other} {@link CountMinSketch} has
* @exception IncompatibleMergeException if the {@code other} {@link CountMinSketch} has
* incompatible depth, width, relative-error, confidence, or random seed.
*/
public abstract CountMinSketch mergeInPlace(CountMinSketch other)
throws CountMinSketchMergeException;
throws IncompatibleMergeException;

/**
* Writes out this {@link CountMinSketch} to an output stream in binary format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,27 +287,29 @@ private long estimateCountForStringItem(String item) {
}

@Override
public CountMinSketch mergeInPlace(CountMinSketch other) throws CountMinSketchMergeException {
public CountMinSketch mergeInPlace(CountMinSketch other) throws IncompatibleMergeException {
if (other == null) {
throw new CountMinSketchMergeException("Cannot merge null estimator");
throw new IncompatibleMergeException("Cannot merge null estimator");
}

if (!(other instanceof CountMinSketchImpl)) {
throw new CountMinSketchMergeException("Cannot merge estimator of class " + other.getClass().getName());
throw new IncompatibleMergeException(
"Cannot merge estimator of class " + other.getClass().getName()
);
}

CountMinSketchImpl that = (CountMinSketchImpl) other;

if (this.depth != that.depth) {
throw new CountMinSketchMergeException("Cannot merge estimators of different depth");
throw new IncompatibleMergeException("Cannot merge estimators of different depth");
}

if (this.width != that.width) {
throw new CountMinSketchMergeException("Cannot merge estimators of different width");
throw new IncompatibleMergeException("Cannot merge estimators of different width");
}

if (!Arrays.equals(this.hashA, that.hashA)) {
throw new CountMinSketchMergeException("Cannot merge estimators of different seed");
throw new IncompatibleMergeException("Cannot merge estimators of different seed");
}

for (int i = 0; i < this.table.length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package org.apache.spark.util.sketch;

public class CountMinSketchMergeException extends Exception {
public CountMinSketchMergeException(String message) {
public class IncompatibleMergeException extends Exception {
public IncompatibleMergeException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ class CountMinSketchSuite extends FunSuite { // scalastyle:ignore funsuite
testItemType[String]("String") { r => r.nextString(r.nextInt(20)) }

test("incompatible merge") {
intercept[CountMinSketchMergeException] {
intercept[IncompatibleMergeException] {
CountMinSketch.create(10, 10, 1).mergeInPlace(null)
}

intercept[CountMinSketchMergeException] {
intercept[IncompatibleMergeException] {
val sketch1 = CountMinSketch.create(10, 20, 1)
val sketch2 = CountMinSketch.create(10, 20, 2)
sketch1.mergeInPlace(sketch2)
}

intercept[CountMinSketchMergeException] {
intercept[IncompatibleMergeException] {
val sketch1 = CountMinSketch.create(10, 10, 1)
val sketch2 = CountMinSketch.create(10, 20, 2)
sketch1.mergeInPlace(sketch2)
Expand Down

0 comments on commit 4abc4e0

Please sign in to comment.