package water.api.dsl.util;

import water.Iced;

import java.util.Random;

/**
 * Wraps an value, with a random int (Used in reservoir sampling)
 */
public class SampleItem extends Iced implements Comparable<SampleItem> {
    private static final Random rand = new Random();
    public final int    randomOrder;
    public final double value;

    public SampleItem(int randomOrder, double value) {
        this.randomOrder = randomOrder;
        this.value = value;
    }

    public SampleItem(double value) {
        this.value       = value;
        this.randomOrder = rand.nextInt();
    }

    public int getRandomOrder() {
        return randomOrder;
    }

    public double getValue() {
        return value;
    }

    @Override
    public int compareTo(SampleItem that) {
        if(this == that) {
          return(0);
        }else if(that == null ) {
          return(1);
        }else {
          return( java.lang.Integer.compare(this.randomOrder,that.randomOrder) );
        }
    }

    @Override
    public String toString() {
        return "SampleItemStub{" +
                "randomOrder=" + randomOrder +
                ", value=" + value +
                '}';
    }
}

@@ -33,44 +33,44 @@
 ort 
-water.Iced;%0A%0Aimport java.util.Random
+java.util.Random;%0A%0Aimport water.Iced
 ;%0A%0A/
@@ -823,11 +823,10 @@
 turn
-(0)
+ 0
 ;%0A  
@@ -877,11 +877,10 @@
 turn
-(1)
+ 1
 ;%0A  
@@ -913,36 +913,9 @@
 turn
-( java.lang.Integer.compare(
+ 
 this
@@ -926,17 +926,19 @@
 domOrder
-,
+ - 
 that.ran
@@ -949,11 +949,9 @@
 rder
-) )
+ 
 ;%0A  

Fix of integer compare.