Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8190381

public state constructors for Int/Long/DoubleSummaryStatistics

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 10
    • core-libs
    • None
    • source, binary
    • minimal
    • Hide
      There is a very small risk that the addition of a new constructor will conflict with that of a sub-class resulting in source and binary incompatibilities. However, since the recored state is private and the getter methods are final this risk seems minimal.
      Show
      There is a very small risk that the addition of a new constructor will conflict with that of a sub-class resulting in source and binary incompatibilities. However, since the recored state is private and the getter methods are final this risk seems minimal.
    • Java API
    • SE

      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

            psandoz Paul Sandoz
            psandoz Paul Sandoz
            Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: