Spec and API review for {Int,Long,Double}SummaryStatistics

Joe Bowbeer joe.bowbeer at gmail.com
Sat Mar 30 07:30:02 PDT 2013

Are there any similar APIs to use for guidance here?

This inconsistency regarding exceptions seems weird to me.

1. I would rather that all getSum methods throw exceptions or none do.

A runtime unchecked exception in a numeric get accessor seems dangerous. So
my strong preference is that neither do.

2. ints.getSum returning long seems like the natural signature.  In the
cases where the sum is known to be int, I'd make this the user's
responsibility. Similar to size of files and stream, and various others.
(I'd cast to int in those cases and add an assertion.)

I suggest:

1. Remove ints.getSumAsLong
2. ints.getSum returns long

 On Mar 29, 2013 11:46 AM, "Mike Duigou" <mike.duigou at oracle.com> wrote:

> 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.
>> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-experts/attachments/20130330/c5dc6a9b/attachment.html 

More information about the lambda-libs-spec-experts mailing list