Update to BAEL-1425 (#4399)

* added example code for Java mail

* added examp code for BAEL-1425

* updated example code for BAEL-1425

* updated example code for BAEL-1425
This commit is contained in:
Seun Matt 2018-06-03 22:56:14 +01:00 committed by maibin
parent fb8224d8d4
commit 5ef5e539e4
1 changed files with 30 additions and 25 deletions

View File

@ -10,8 +10,13 @@ import java.util.*;
public class Histogram {
private Map distributionMap;
private int classWidth;
public Histogram() {
distributionMap = new TreeMap();
classWidth = 10;
Map distributionMap = processRawData();
List yData = new ArrayList();
yData.addAll(distributionMap.values());
@ -46,43 +51,43 @@ public class Histogram {
Frequency frequency = new Frequency();
datasetList.forEach(d -> frequency.addValue(Double.parseDouble(d.toString())));
int classWidth = 10;
Map distributionMap = new TreeMap();
List processed = new ArrayList();
datasetList.forEach(d -> {
double observation = Double.parseDouble(d.toString());
double observation = Double.parseDouble(d.toString());
if(processed.contains(observation))
return;
if(processed.contains(observation))
return;
long observationFrequency = frequency.getCount(observation);
int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth;
int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0;
String bin = lowerBoundary + "-" + upperBoundary;
long observationFrequency = frequency.getCount(observation);
int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth;
int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0;
String bin = lowerBoundary + "-" + upperBoundary;
updateDistributionMap(lowerBoundary, bin, observationFrequency);
int prevUpperBoundary = lowerBoundary;
int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0;
String prevBin = prevLowerBoundary + "-" + prevUpperBoundary;
if(!distributionMap.containsKey(prevBin))
distributionMap.put(prevBin, 0);
if(!distributionMap.containsKey(bin)) {
distributionMap.put(bin, observationFrequency);
}
else {
long oldFrequency = Long.parseLong(distributionMap.get(bin).toString());
distributionMap.replace(bin, oldFrequency + observationFrequency);
}
processed.add(observation);
processed.add(observation);
});
return distributionMap;
}
private void updateDistributionMap(int lowerBoundary, String bin, long observationFrequency) {
int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0;
String prevBin = prevLowerBoundary + "-" + lowerBoundary;
if(!distributionMap.containsKey(prevBin))
distributionMap.put(prevBin, 0);
if(!distributionMap.containsKey(bin)) {
distributionMap.put(bin, observationFrequency);
}
else {
long oldFrequency = Long.parseLong(distributionMap.get(bin).toString());
distributionMap.replace(bin, oldFrequency + observationFrequency);
}
}
public static void main(String[] args) {
new Histogram();
}