-
Notifications
You must be signed in to change notification settings - Fork 56
Class Statistics
Ori Roth edited this page Apr 2, 2017
·
3 revisions
public final class Statistics {
/*
* Forge (1)
*/
Statistics();
/*
* Type (6)
*/
void record(int a);
int n();
double min() throws ArithmeticException;
double max() throws ArithmeticException;
double mean() throws ArithmeticException;
double sd();
}
Exception types: ArithmeticException
.
// SSDLPedia
package il.ac.technion.cs.ssdl.utils;
import il.ac.technion.cs.ssdl.stereotypes.Instantiable;
/**
* A class to compute statistics, e.g., the minimal and maximal value, the mean
* and the standard deviation, of a sequence of integers.
*
* Author: Yossi Gil,
* See: 17/06/2008
*/
@Instantiable public final class Statistics {
/**
* Make a record the next element in the sequence.
*
* a the value to be recorded
*/
public void record(final int a) {
if (n() == 0)
min = max = a;
if (min > a)
min = a;
if (max < a)
max = a;
double d = 1;
for (int i = 0; i < MOMENTS; i++) {
s[i] += d;
d *= a;
}
}
/**
* Return: a non-negative integer, giving the number of elements in the
* sequence
*/
public int n() {
return (int) s[0];
}
/**
* Return: the smallest value of the elements in the sequence
* ArithmeticException in case this function was called prior to
* recording any elements in the sequence
*/
public double min() throws ArithmeticException {
checkEmpty();
return min;
}
/**
* Return: the largest value of the elements in the sequence
* ArithmeticException in case this function was called prior to
* recording any elements in the sequence
*/
public double max() throws ArithmeticException {
checkEmpty();
return max;
}
/**
* Return: the average value of the elements in the sequence
* ArithmeticException in case this function was called prior to
* recording any elements in the sequence
*/
public double mean() throws ArithmeticException {
checkEmpty();
return s[1] / n();
}
/**
* Return: the standard deviation of the elements in the sequence
*/
public double sd() {
return Math.sqrt(s[2] / n() - sqr(mean()));
}
double m2() {
return s[2];
}
private int min, max;
private final int MOMENTS = 4;
private final double[] s = new double[MOMENTS];
private static double sqr(final double d) {
return d * d;
}
private void checkEmpty() throws ArithmeticException {
if (n() == 0)
throw new ArithmeticException(EMPTY_SEQUENCE);
}
private static final String EMPTY_SEQUENCE = "No elements yet in sequene.";
}
Metric | Value | Acronym | Explanation |
---|---|---|---|
LOC | 97 | Lines Of Code | Total number of lines in the code |
SCC | 25 | SemiColons Count | Total number of semicolon tokens found in the code. |
NOT | 297 | Number Of Tokens | Comments, whitespace and text which cannot be made into a token not included. |
VCC | 1756 | Visible Characters Count | The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters. |
CCC | 877 | Code Characters Count | Total number of non-white characters in tokens. White space characters in string and character literals are not counted. |
UIC | 28 | Unique Identifiers Count | The number of different identifiers found in the code |
WHC | 3 | Weighted Horizontal Complexity | A heuritistic on horizontal complexity |
Statistic | Value |
---|---|
Average token length | 3 |
Tokens/line | 3.1 |
Visible characters/line | 18 |
Code characters/line | 9 |
Semicolons/tokens | 8% |
Comment text percentage | 50% |
Token Kind | Occurrences |
---|---|
KEYWORD | 61 |
OPERATOR | 21 |
LITERAL | 10 |
ID | 79 |
PUNCTUATION | 126 |
COMMENT | 8 |
OTHER | 176 |