Summary
Construct DoubleSummaryStatistics, LongSummaryStatistics, and IntSummaryStatistics with non-default/initial state.
Problem
It is not possible to reconstruct *SummaryStatistics from it's recorded values. For example to be "cloned" or transmitted in a serial form and reconstituted.
Solution
Add constructors to *SummaryStatistics accepting pre-recorded state.
Specification
The specification for the three constructors are:
/**
* Constructs a non-empty instance with the specified {@code count},
* {@code min}, {@code max}, and {@code sum}.
*
* <p>If {@code count} is zero then the remaining arguments are ignored and
* an empty instance is constructed.
*
* <p>If the arguments are inconsistent then an {@code IllegalArgumentException}
* is thrown. The necessary consistent argument conditions are:
* <ul>
* <li>{@code count >= 0}</li>
* <li>{@code (min <= max && !isNaN(sum)) || (isNaN(min) && isNaN(max) && isNaN(sum))}</li>
* </ul>
* @apiNote
* The enforcement of argument correctness means that the retrieved set of
* recorded values obtained from a {@code DoubleSummaryStatistics} source
* instance may not be a legal set of arguments for this constructor due to
* arithmetic overflow of the source's recorded count of values.
* The consistent argument conditions are not sufficient to prevent the
* creation of an internally inconsistent instance. An example of such a
* state would be an instance with: {@code count} = 2, {@code min} = 1,
* {@code max} = 2, and {@code sum} = 0.
*
* @param count the count of values
* @param min the minimum value
* @param max the maximum value
* @param sum the sum of all values
* @throws IllegalArgumentException if the arguments are inconsistent
* @since 10
*/
public DoubleSummaryStatistics(long count, double min, double max, double sum)
throws IllegalArgumentException
/**
* Constructs a non-empty instance with the specified {@code count},
* {@code min}, {@code max}, and {@code sum}.
*
* <p>If {@code count} is zero then the remaining arguments are ignored and
* an empty instance is constructed.
*
* <p>If the arguments are inconsistent then an {@code IllegalArgumentException}
* is thrown. The necessary consistent argument conditions are:
* <ul>
* <li>{@code count >= 0}</li>
* <li>{@code min <= max}</li>
* </ul>
* @apiNote
* The enforcement of argument correctness means that the retrieved set of
* recorded values obtained from a {@code LongSummaryStatistics} source
* instance may not be a legal set of arguments for this constructor due to
* arithmetic overflow of the source's recorded count of values.
* The consistent argument conditions are not sufficient to prevent the
* creation of an internally inconsistent instance. An example of such a
* state would be an instance with: {@code count} = 2, {@code min} = 1,
* {@code max} = 2, and {@code sum} = 0.
*
* @param count the count of values
* @param min the minimum value
* @param max the maximum value
* @param sum the sum of all values
* @throws IllegalArgumentException if the arguments are inconsistent
* @since 10
*/
public LongSummaryStatistics(long count, long min, long max, long sum)
throws IllegalArgumentException
/**
* Constructs a non-empty instance with the specified {@code count},
* {@code min}, {@code max}, and {@code sum}.
*
* <p>If {@code count} is zero then the remaining arguments are ignored and
* an empty instance is constructed.
*
* <p>If the arguments are inconsistent then an {@code IllegalArgumentException}
* is thrown. The necessary consistent argument conditions are:
* <ul>
* <li>{@code count >= 0}</li>
* <li>{@code min <= max}</li>
* </ul>
* @apiNote
* The enforcement of argument correctness means that the retrieved set of
* recorded values obtained from a {@code IntSummaryStatistics} source
* instance may not be a legal set of arguments for this constructor due to
* arithmetic overflow of the source's recorded count of values.
* The consistent argument conditions are not sufficient to prevent the
* creation of an internally inconsistent instance. An example of such a
* state would be an instance with: {@code count} = 2, {@code min} = 1,
* {@code max} = 2, and {@code sum} = 0.
*
* @param count the count of values
* @param min the minimum value
* @param max the maximum value
* @param sum the sum of all values
* @throws IllegalArgumentException if the arguments are inconsistent
* @since 10
*/
public IntSummaryStatistics(long count, int min, int max, long sum)
throws IllegalArgumentException
- csr of
-
JDK-8178117 public state constructors for Int/Long/DoubleSummaryStatistics
- Resolved