@@ -47,27 +47,29 @@ private CategoryChart buildChart(List xData, List yData) {
4747
4848 private Map processRawData () {
4949
50- List <Integer > datasetList = Arrays .asList (36 , 25 , 38 , 46 , 55 , 68 , 72 , 55 , 36 , 38 , 67 , 45 , 22 , 48 , 91 , 46 , 52 , 61 , 58 , 55 );
50+ List <Integer > datasetList = Arrays .asList (
51+ 36 , 25 , 38 , 46 , 55 , 68 , 72 ,
52+ 55 , 36 , 38 , 67 , 45 , 22 , 48 ,
53+ 91 , 46 , 52 , 61 , 58 , 55 );
5154 Frequency frequency = new Frequency ();
5255 datasetList .forEach (d -> frequency .addValue (Double .parseDouble (d .toString ())));
5356
54- List processed = new ArrayList ();
55- datasetList .forEach (d -> {
56- double observation = Double .parseDouble (d .toString ());
57-
58- if (processed .contains (observation ))
59- return ;
60-
61- long observationFrequency = frequency .getCount (observation );
62- int upperBoundary = (observation > classWidth ) ? Math .multiplyExact ( (int ) Math .ceil (observation / classWidth ), classWidth ) : classWidth ;
63- int lowerBoundary = (upperBoundary > classWidth ) ? Math .subtractExact (upperBoundary , classWidth ) : 0 ;
64- String bin = lowerBoundary + "-" + upperBoundary ;
65-
66- updateDistributionMap (lowerBoundary , bin , observationFrequency );
67-
68- processed .add (observation );
69-
70- });
57+ datasetList .stream ()
58+ .map (d -> Double .parseDouble (d .toString ()))
59+ .distinct ()
60+ .forEach (observation -> {
61+ long observationFrequency = frequency .getCount (observation );
62+ int upperBoundary = (observation > classWidth )
63+ ? Math .multiplyExact ( (int ) Math .ceil (observation / classWidth ), classWidth )
64+ : classWidth ;
65+ int lowerBoundary = (upperBoundary > classWidth )
66+ ? Math .subtractExact (upperBoundary , classWidth )
67+ : 0 ;
68+ String bin = lowerBoundary + "-" + upperBoundary ;
69+
70+ updateDistributionMap (lowerBoundary , bin , observationFrequency );
71+
72+ });
7173
7274 return distributionMap ;
7375 }
0 commit comments