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

Improve spec of NumberFormat's methods with unsupported operations

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 22
    • core-libs
    • None
    • behavioral
    • minimal
    • Simply a specification update.
    • Java API
    • SE

      Summary

      Improve the specification of NumberFormat's unsupported methods.

      Problem

      setCurrency(), getCurrency(), getRoundingMode(), and setRoundingMode() are methods that are not supported in the default implementation of NumberFormat. Subclasses that need to use any of these methods should override and implement them accordingly.

      The specification of setCurrency(), getCurrency(), getRoundingMode(), and setRoundingMode() were written before the introduction of the implSpec tag. As it stands, it is written in a way that does not separate the implementation specification from the API specification.

      Solution

      Use the implSpec tag to distinguish the API specification from the implementation specification.

      Specification

      Update getCurrency()

           /**
            * Gets the currency used by this number format when formatting
            * currency values. The initial value is derived in a locale dependent
      -     * way. The returned value may be null if no valid
      +     * way. The returned value may be {@code null} if no valid
            * currency could be determined and no currency has been set using
      -     * {@link #setCurrency(java.util.Currency) setCurrency}.
      -     * <p>
      -     * The default implementation throws
      -     * {@code UnsupportedOperationException}.
      +     * {@link #setCurrency(Currency)}.
            *
      +     * @implSpec The default implementation always throws {@code
      +     * UnsupportedOperationException}. Subclasses should override this method
      +     * if currency formatting is desired.
            * @return the currency used by this number format, or {@code null}
      -     * @throws    UnsupportedOperationException if the number format class
      -     * doesn't implement currency formatting
      +     * @throws    UnsupportedOperationException if the implementation of this
      +     *            method does not support this operation
            * @since 1.4
            */

      Update setCurrency()

            * Sets the currency used by this number format when formatting
            * currency values. This does not update the minimum or maximum
            * number of fraction digits used by the number format.
      -     * <p>
      -     * The default implementation throws
      -     * {@code UnsupportedOperationException}.
            *
      +     * @implSpec The default implementation always throws {@code
      +     * UnsupportedOperationException}. Subclasses should override this method
      +     * if currency formatting is desired.
            * @param currency the new currency to be used by this number format
      -     * @throws    UnsupportedOperationException if the number format class
      -     * doesn't implement currency formatting
      -     * @throws    NullPointerException if {@code currency} is null
      +     * @throws    NullPointerException if {@code currency} is {@code null}
      +     * @throws    UnsupportedOperationException if the implementation of this
      +     *            method does not support this operation
            * @since 1.4
            */

      Update getRoundingMode()

           /**
            * Gets the {@link java.math.RoundingMode} used in this NumberFormat.
      -     * The default implementation of this method in NumberFormat
      -     * always throws {@link java.lang.UnsupportedOperationException}.
      -     * Subclasses which handle different rounding modes should override
      -     * this method.
            *
      -     * @throws    UnsupportedOperationException The default implementation
      -     *     always throws this exception
      +     * @implSpec The default implementation always throws {@code
      +     * UnsupportedOperationException}. Subclasses which handle different
      +     * rounding modes should override this method.
            * @return The {@code RoundingMode} used for this NumberFormat.
      +     * @throws    UnsupportedOperationException if the implementation of this
      +     *            method does not support this operation
            * @see #setRoundingMode(RoundingMode)
            * @since 1.6
            */

      Update setRoundingMode()

           /**
            * Sets the {@link java.math.RoundingMode} used in this NumberFormat.
      -     * The default implementation of this method in NumberFormat always
      -     * throws {@link java.lang.UnsupportedOperationException}.
      -     * Subclasses which handle different rounding modes should override
      -     * this method.
            *
      -     * @throws    UnsupportedOperationException The default implementation
      -     *     always throws this exception
      -     * @throws    NullPointerException if {@code roundingMode} is null
      +     * @implSpec The default implementation throws {@code UnsupportedOperationException}.
      +     * Subclasses which handle different rounding modes should override this method.
      +     * @throws    NullPointerException if {@code roundingMode} is {@code null}
      +     * @throws    UnsupportedOperationException if the implementation of this
      +     *            method does not support this operation
            * @param roundingMode The {@code RoundingMode} to be used
            * @see #getRoundingMode()
            * @since 1.6

            jlu Justin Lu
            jlu Justin Lu
            Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: