Spec and API review for {Int,Long,Double}SummaryStatistics
Mike Duigou
mike.duigou at oracle.com
Fri Mar 29 10:46:43 PDT 2013
On Mar 28 2013, at 18:55 , Joe Bowbeer wrote:
> Why not have is.getSum return long?
>
There is a getAsLong() version which does return a long. For many cases it's known that the result will not overflow and it makes sense for an Int focused class to provide a result of the same size.
> Does getSum of a long stream throw an exception?
>
No. None of the implementations currently detect overflow. If overflow was encountered it would have to be thrown from accept() rather than from getSum().
Worth the cost to implement? I am not sure.
Mike
> On Mar 28, 2013 7:37 PM, "Mike Duigou" <mike.duigou at oracle.com> wrote:
> I've responded to the survey feedback and updated the implementations with additional Javadoc.
>
> One comment which was not addressed was whether getAverage() should throw a zero division ArithmeticException if no values had been recorded. I believe the current default of returning 0.0 is reasonable and it is convenient to not have to check the catch the exception. It's also in line with the defaults we provide for sum, sumOfSquares, min, and max. For any of these defaults users can check the count themselves and choose to substitute their own default. double average = summary.getCount() != 0 ? summary.getAverage() : Double.NAN;
>
> I did introduce an ArithmeticException to IntSummaryStatistics.getSum() if the sum cannot be expressed as an int. Remember that the sum is internally maintained in a long and there is a long accessor, getAsLong().
>
> Mike
>
> On Mar 22 2013, at 15:00 , Brian Goetz wrote:
>
> > I've posted a survey at:
> > https://www.surveymonkey.com/s/5VTLT26
> >
> > To do an API and spec review for the classes Int/Long/DoubleSummaryStatistics. If you have comments, please provide them in the SurveyMonkey form. Usual password.
> >
>
More information about the lambda-libs-spec-observers
mailing list