Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package io.advantageous.qbit.metrics.support;
  
  
  import java.util.Arrays;
  
  import static io.advantageous.boon.primitive.Int.bigSum;
  import static io.advantageous.boon.primitive.Int.varianceDouble;

Holds primitive values in a list like object for ints.

Has sum, mean, median, standardDeviation, reduceBy, variance.

Author(s):
Rick Hightower
 
 public class StatList extends AbstractList<Integer> {


    
Values in this list.
 
     private int[] values;
    
Index of last value added.
 
     private int end;

    
Create a new list with this many items in it.

Parameters:
capacity capacity
 
     public StatList(final int capacity) {
         this. = new int[capacity];
     }


    
Create a new list with exactly 10 items in it.
 
     public StatList() {
         this. = new int[10];
     }


    
Create a new list with this many items in it.

Parameters:
values values
 
     public StatList(int values[]) {
         this. = values;
         this. = values.length;
     }
 
     public void clear() {
         this. = new int[10];
         this. = 0;
     }

    
Get the value at index

Parameters:
index index
Returns:
value
 
     @Override
     public Integer get(int index) {
         return [index];
     }


    
Get the value at index but don't use a wrapper

Parameters:
index index
Returns:
value
 
     public final int getInt(int index) {
         return [index];
     }

    
Add a new value to the list.

Parameters:
integer new value
Returns:
was able to add.
 
     @Override
     public boolean add(Integer integer) {
         if ( + 1 >= .) {
              = Int.grow();
         }
         [] = integer;
         ++;
         return true;
    }

    
Add a new value to the list but don't employ a wrapper.

Parameters:
integer new value
Returns:
was able to add.
    public boolean addInt(int integer) {
        if ( + 1 >= .) {
             = Int.grow();
        }
        [] = integer;
        ++;
        return true;
    }

    
Add a new value to the list but don't employ a wrapper.

Parameters:
integer new value
Returns:
was able to add.
    public StatList add(int integer) {
        if ( + 1 >= .) {
             = Int.grow();
        }
        [] = integer;
        ++;
        return this;
    }

    
Add a new array to the list.

Parameters:
newValues new values
Returns:
was able to add.
    public boolean addArray(int... newValues) {
        if ( + newValues.length >= .) {
             = Int.grow(, (. + newValues.length) * 2);
        }
        System.arraycopy(newValues, 0, newValues.length);
         += newValues.length;
        return true;
    }

    
Set a value in the list.

Parameters:
index index
element new value
Returns:
old value at this index
    @Override
    public Integer set(int indexInteger element) {
        int oldValue = [index];
        [index] = element;
        return oldValue;
    }


    
Set in a new value no wrapper

Parameters:
index index
element new value
Returns:
old value at this index
    public int setInt(int indexint element) {
        int oldValue = [index];
        [index] = element;
        return oldValue;
    }

    
Return the current size.

Returns:
size
    @Override
    public int size() {
        return ;
    }


    
Sums the values with bounds checking.

Returns:
sum
    public int sum() {
        return Int.sum();
    }


    
Get a copy of the array up to the end element.

Returns:
array
    public int[] toValueArray() {
        return java.util.Arrays.copyOfRange(, 0, );
    }


    
This would be a good opportunity to reintroduce dynamic invoke

Parameters:
function function
Returns:
array
    public long reduceBy(Object function) {
        return Int.reduceBy(function);
    }


    
This would be a good opportunity to reintroduce dynamic invoke

Parameters:
function function
name name
Returns:
result
    public long reduceBy(Object functionString name) {
        return Int.reduceBy(functionname);
    }


    

Parameters:
reduceBy reduceBy function
Returns:
the reduction
    public long reduceBy(Int.ReduceBy reduceBy) {
        return Int.reduceBy(reduceBy);
    }

    
Mean

Returns:
mean
    public float mean() {
        return (floatmeanDouble(, 0, );
    }
    private static double meanDoubleint[] valuesfinal int startfinal int length ) {
        double mean = ((double)bigSum(valuesstartlength))/ ((doublelength);
        return mean;
    }


    
standardDeviation

Returns:
standardDeviation
    public float standardDeviation() {
        double variance = varianceDouble(, 0, );
        return (float) Math.sqrt(variance);
    }


    
variance

Returns:
variance
    public float variance() {
        return (float)varianceDouble(, 0, );
    }


    
max

Returns:
max
    public int max() {
        return Int.max();
    }


    
min

Returns:
min
    public int min() {
        return Int.min();
    }


    
median

Returns:
median
    public int median() {
        return Int.median();
    }


    
sort
    public void sort() {
        Arrays.sort(, 0, );
    }
    @Override
    public boolean equals(Object o) {
        if (this == oreturn true;
        if (o == null || getClass() != o.getClass()) return false;
        StatList integers = (StatListo;
        if ( != integers.endreturn false;
        if (!Int.equals(0, integers.values)) return false;
        return true;
    }
    @Override
    public int hashCode() {
        int result = 1;
        result = 31 * result + ( != null ? Int.hashCode(0, ) : 0);
        result = 31 * result + ;
        return result;
    }
New to GrepCode? Check out our FAQ X