changeset 7487:1ca7473e08aa

Add missing specification of null handling behaviour. Contributed-by: alan.bateman@oracle.com
author mduigou
date Wed, 20 Feb 2013 13:49:08 -0800
parents f93625257fbd
children c499c13fa66a
files src/share/classes/java/time/chrono/HijrahDeviationReader.java src/share/classes/java/util/Optional.java src/share/classes/java/util/OptionalDouble.java src/share/classes/java/util/OptionalInt.java src/share/classes/java/util/OptionalLong.java
diffstat 5 files changed, 50 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/time/chrono/HijrahDeviationReader.java	Wed Feb 20 10:16:45 2013 -0800
+++ b/src/share/classes/java/time/chrono/HijrahDeviationReader.java	Wed Feb 20 13:49:08 2013 -0800
@@ -70,7 +70,7 @@
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoField;
 import java.util.Arrays;
-import java.util.function.Block;
+import java.util.function.Consumer;
 
 /**
  * A reader for Hijrah Deviation files.
@@ -126,13 +126,13 @@
      * @param typeId the name of the calendar
      * @param calendarType the calendar type
      * @return {@code true} if the file was read and each entry accepted by the
-     * Block; else {@code false} no configuration was done
+     * Consumer; else {@code false} no configuration was done
      *
      * @throws IOException for zip/jar file handling exception.
      * @throws ParseException if the format of the configuration file is wrong.
      */
     static boolean readDeviation(String typeId, String calendarType,
-            Block<HijrahChronology.Deviation> block) throws IOException, ParseException {
+            Consumer<HijrahChronology.Deviation> consumer) throws IOException, ParseException {
         InputStream is = getConfigFileInputStream(typeId);
         if (is != null) {
             try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
@@ -142,7 +142,7 @@
                     num++;
                     HijrahChronology.Deviation entry = parseLine(line, num);
                     if (entry != null) {
-                        block.accept(entry);
+                        consumer.accept(entry);
                     }
                 }
             }
--- a/src/share/classes/java/util/Optional.java	Wed Feb 20 10:16:45 2013 -0800
+++ b/src/share/classes/java/util/Optional.java	Wed Feb 20 13:49:08 2013 -0800
@@ -122,8 +122,12 @@
     }
 
     /**
-     * Execute the specified block with the value if a value is present,
+     * Execute the specified consumer with the value if a value is present,
      * otherwise do nothing.
+     *
+     * @param consumer block to be executed if a value is present.
+     * @throws NullPointerException if value is present and {@code consumer} is
+     * null.
      */
     public void ifPresent(Consumer<? super T> consumer) {
         if (value != null)
@@ -147,6 +151,7 @@
      * @param other {@code Supplier} who's result is returned if there is no
      * value present.
      * @return the value if present otherwise return result of {@code other}.
+     * @throws NullPointerException if value is absent and {@code other} is null.
      */
     public T orElseGet(Supplier<T> other) {
         return value != null ? value : other.get();
@@ -161,6 +166,8 @@
      * be thrown.
      * @return the value.
      * @throws V if there is no value present.
+     * @throws NullPointerException if value is absent and
+     * {@code exceptionSupplier} is null.
      */
     public <V extends Throwable> T orElseThrow(Supplier<V> exceptionSupplier) throws V {
         if (value != null) {
@@ -179,6 +186,8 @@
      * the default zero arguments constructor.
      * @return the value.
      * @throws V if there is no value present.
+     * @throws NullPointerException if value is absent and
+     * {@code exceptionClass} is null.
      */
     public <V extends Throwable> T orElseThrow(Class<V> exceptionClass) throws V {
         if (value != null) {
--- a/src/share/classes/java/util/OptionalDouble.java	Wed Feb 20 10:16:45 2013 -0800
+++ b/src/share/classes/java/util/OptionalDouble.java	Wed Feb 20 13:49:08 2013 -0800
@@ -124,12 +124,16 @@
     }
 
     /**
-     * Execute the specified block with the value if a value is present,
+     * Execute the specified consumer with the value if a value is present,
      * otherwise do nothing.
+     *
+     * @param consumer block to be executed if a value is present.
+     * @throws NullPointerException if value is present and {@code consumer} is
+     * null.
      */
-    public void ifPresent(DoubleConsumer block) {
+    public void ifPresent(DoubleConsumer consumer) {
         if (isPresent)
-            block.accept(value);
+            consumer.accept(value);
     }
 
     /**
@@ -149,6 +153,7 @@
      * @param other {@code DoubleSupplier} who's result is returned if there is no
      * value present.
      * @return the value if present otherwise return result of {@code other}.
+     * @throws NullPointerException if value is absent and {@code other} is null.
      */
     public double orElseGet(DoubleSupplier other) {
         return isPresent ? value : other.getAsDouble();
@@ -163,6 +168,8 @@
      * be thrown.
      * @return the value.
      * @throws V if there is no value present.
+     * @throws NullPointerException if value is absent and
+     * {@code exceptionSupplier} is null.
      */
     public<V extends Throwable> double orElseThrow(Supplier<V> exceptionSupplier) throws V {
         if (isPresent) {
@@ -181,6 +188,8 @@
      * the default zero arguments constructor.
      * @return the value.
      * @throws V if there is no value present.
+     * @throws NullPointerException if value is absent and
+     * {@code exceptionClass} is null.
      */
     public<V extends Throwable> double orElseThrow(Class<V> exceptionClass) throws V {
         if (isPresent) {
--- a/src/share/classes/java/util/OptionalInt.java	Wed Feb 20 10:16:45 2013 -0800
+++ b/src/share/classes/java/util/OptionalInt.java	Wed Feb 20 13:49:08 2013 -0800
@@ -124,12 +124,16 @@
     }
 
     /**
-     * Execute the specified block with the value if a value is present,
+     * Execute the specified consumer with the value if a value is present,
      * otherwise do nothing.
+     *
+     * @param consumer block to be executed if a value is present.
+     * @throws NullPointerException if value is present and {@code consumer} is
+     * null.
      */
-    public void ifPresent(IntConsumer block) {
+    public void ifPresent(IntConsumer consumer) {
         if (isPresent)
-            block.accept(value);
+            consumer.accept(value);
     }
 
     /**
@@ -149,6 +153,7 @@
      * @param other {@code IntSupplier} who's result is returned if there is no
      * value present.
      * @return the value if present otherwise return result of {@code other}.
+     * @throws NullPointerException if value is absent and {@code other} is null.
      */
     public int orElseGet(IntSupplier other) {
         return isPresent ? value : other.getAsInt();
@@ -163,6 +168,8 @@
      * be thrown.
      * @return the value.
      * @throws V if there is no value present.
+     * @throws NullPointerException if value is absent and
+     * {@code exceptionSupplier} is null.
      */
     public<V extends Throwable> int orElseThrow(Supplier<V> exceptionSupplier) throws V {
         if (isPresent) {
@@ -181,6 +188,8 @@
      * the default zero arguments constructor.
      * @return the value.
      * @throws V if there is no value present.
+     * @throws NullPointerException if value is absent and
+     * {@code exceptionClass} is null.
      */
     public<V extends Throwable> int orElseThrow(Class<V> exceptionClass) throws V {
         if (isPresent) {
--- a/src/share/classes/java/util/OptionalLong.java	Wed Feb 20 10:16:45 2013 -0800
+++ b/src/share/classes/java/util/OptionalLong.java	Wed Feb 20 13:49:08 2013 -0800
@@ -124,12 +124,16 @@
     }
 
     /**
-     * Execute the specified block with the value if a value is present,
+     * Execute the specified consumer with the value if a value is present,
      * otherwise do nothing.
+     *
+     * @param consumer block to be executed if a value is present.
+     * @throws NullPointerException if value is present and {@code consumer} is
+     * null.
      */
-    public void ifPresent(LongConsumer block) {
+    public void ifPresent(LongConsumer consumer) {
         if (isPresent)
-            block.accept(value);
+            consumer.accept(value);
     }
 
     /**
@@ -149,6 +153,7 @@
      * @param other {@code LongSupplier} who's result is returned if there is no
      * value present.
      * @return the value if present otherwise return result of {@code other}.
+     * @throws NullPointerException if value is absent and {@code other} is null.
      */
     public long orElseGet(LongSupplier other) {
         return isPresent ? value : other.getAsLong();
@@ -163,6 +168,8 @@
      * be thrown.
      * @return the value.
      * @throws V if there is no value present.
+     * @throws NullPointerException if value is absent and
+     * {@code exceptionSupplier} is null.
      */
     public<V extends Throwable> long orElseThrow(Supplier<V> exceptionSupplier) throws V {
         if (isPresent) {
@@ -181,6 +188,8 @@
      * the default zero arguments constructor.
      * @return the value.
      * @throws V if there is no value present.
+     * @throws NullPointerException if value is absent and
+     * {@code exceptionClass} is null.
      */
     public<V extends Throwable> long orElseThrow(Class<V> exceptionClass) throws V {
         if (isPresent) {