changeset 8904:473ca46f3096

Revert forEach() back to ifPresent() for Optionals
author henryjen
date Wed, 26 Jun 2013 13:01:17 -0700
parents a35de55b9a42
children eb9b9342c22e
files 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 test/java/util/Optional/BasicDouble.java test/java/util/Optional/BasicInt.java test/java/util/Optional/BasicLong.java
diffstat 7 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Optional.java	Wed Jun 26 15:41:05 2013 -0400
+++ b/src/share/classes/java/util/Optional.java	Wed Jun 26 13:01:17 2013 -0700
@@ -37,7 +37,7 @@
  * <p>Additional methods that depend on the presence or absence of a contained
  * value are provided, such as {@link #orElse(java.lang.Object) orElse()}
  * (return a default value if value not present) and
- * {@link #ifPresent(java.util.function.Consumer)} (execute a block
+ * {@link #ifPresent(java.util.function.Consumer) ifPresent()} (execute a block
  * of code if the value is present).
  *
  * @since 1.8
--- a/src/share/classes/java/util/OptionalDouble.java	Wed Jun 26 15:41:05 2013 -0400
+++ b/src/share/classes/java/util/OptionalDouble.java	Wed Jun 26 13:01:17 2013 -0700
@@ -36,7 +36,7 @@
  * <p>Additional methods that depend on the presence or absence of a contained
  * value are provided, such as {@link #orElse(double) orElse()}
  * (return a default value if value not present) and
- * {@link #forEach(java.util.function.DoubleConsumer) forEach()} (execute a block
+ * {@link #ifPresent(java.util.function.DoubleConsumer) ifPresent()} (execute a block
  * of code if the value is present).
  *
  * @since 1.8
@@ -132,7 +132,7 @@
      * @throws NullPointerException if value is present and {@code consumer} is
      * null
      */
-    public void forEach(DoubleConsumer consumer) {
+    public void ifPresent(DoubleConsumer consumer) {
         if (isPresent)
             consumer.accept(value);
     }
--- a/src/share/classes/java/util/OptionalInt.java	Wed Jun 26 15:41:05 2013 -0400
+++ b/src/share/classes/java/util/OptionalInt.java	Wed Jun 26 13:01:17 2013 -0700
@@ -36,7 +36,7 @@
  * <p>Additional methods that depend on the presence or absence of a contained
  * value are provided, such as {@link #orElse(int) orElse()}
  * (return a default value if value not present) and
- * {@link #forEach(java.util.function.IntConsumer) forEach()} (execute a block
+ * {@link #ifPresent(java.util.function.IntConsumer) ifPresent()} (execute a block
  * of code if the value is present).
  *
  * @since 1.8
@@ -132,7 +132,7 @@
      * @throws NullPointerException if value is present and {@code consumer} is
      * null
      */
-    public void forEach(IntConsumer consumer) {
+    public void ifPresent(IntConsumer consumer) {
         if (isPresent)
             consumer.accept(value);
     }
--- a/src/share/classes/java/util/OptionalLong.java	Wed Jun 26 15:41:05 2013 -0400
+++ b/src/share/classes/java/util/OptionalLong.java	Wed Jun 26 13:01:17 2013 -0700
@@ -36,7 +36,7 @@
  * <p>Additional methods that depend on the presence or absence of a contained
  * value are provided, such as {@link #orElse(long) orElse()}
  * (return a default value if value not present) and
- * {@link #forEach(java.util.function.LongConsumer) forEach()} (execute a block
+ * {@link #ifPresent(java.util.function.LongConsumer) ifPresent()} (execute a block
  * of code if the value is present).
  *
  * @since 1.8
@@ -132,7 +132,7 @@
      * @throws NullPointerException if value is present and {@code consumer} is
      * null
      */
-    public void forEach(LongConsumer consumer) {
+    public void ifPresent(LongConsumer consumer) {
         if (isPresent)
             consumer.accept(value);
     }
--- a/test/java/util/Optional/BasicDouble.java	Wed Jun 26 15:41:05 2013 -0400
+++ b/test/java/util/Optional/BasicDouble.java	Wed Jun 26 13:01:17 2013 -0700
@@ -48,7 +48,7 @@
         assertTrue(0 == empty.hashCode());
         assertTrue(!empty.toString().isEmpty());
         assertTrue(!empty.isPresent());
-        empty.forEach(v -> { fail(); });
+        empty.ifPresent(v -> { fail(); });
         assertEquals(2.0, empty.orElse(2.0));
         assertEquals(2.0, empty.orElseGet(()-> 2.0));
     }
@@ -96,7 +96,7 @@
         assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString()));
         assertEquals(1.0, present.getAsDouble());
         try {
-            present.forEach(v -> { throw new ObscureException(); });
+            present.ifPresent(v -> { throw new ObscureException(); });
             fail();
         } catch(ObscureException expected) {
 
--- a/test/java/util/Optional/BasicInt.java	Wed Jun 26 15:41:05 2013 -0400
+++ b/test/java/util/Optional/BasicInt.java	Wed Jun 26 13:01:17 2013 -0700
@@ -48,7 +48,7 @@
         assertTrue(0 == empty.hashCode());
         assertTrue(!empty.toString().isEmpty());
         assertTrue(!empty.isPresent());
-        empty.forEach(v -> { fail(); });
+        empty.ifPresent(v -> { fail(); });
         assertEquals(2, empty.orElse(2));
         assertEquals(2, empty.orElseGet(()-> 2));
     }
@@ -96,7 +96,7 @@
         assertTrue(-1 != present.toString().indexOf(Integer.toString(present.getAsInt()).toString()));
         assertEquals(1, present.getAsInt());
         try {
-            present.forEach(v -> { throw new ObscureException(); });
+            present.ifPresent(v -> { throw new ObscureException(); });
             fail();
         } catch(ObscureException expected) {
 
--- a/test/java/util/Optional/BasicLong.java	Wed Jun 26 15:41:05 2013 -0400
+++ b/test/java/util/Optional/BasicLong.java	Wed Jun 26 13:01:17 2013 -0700
@@ -48,7 +48,7 @@
         assertTrue(0 == empty.hashCode());
         assertTrue(!empty.toString().isEmpty());
         assertTrue(!empty.isPresent());
-        empty.forEach(v -> { fail(); });
+        empty.ifPresent(v -> { fail(); });
         assertEquals(2, empty.orElse(2));
         assertEquals(2, empty.orElseGet(()-> 2));
     }
@@ -96,7 +96,7 @@
         assertTrue(-1 != present.toString().indexOf(Long.toString(present.getAsLong()).toString()));
         assertEquals(1L, present.getAsLong());
         try {
-            present.forEach(v -> { throw new ObscureException(); });
+            present.ifPresent(v -> { throw new ObscureException(); });
             fail();
         } catch(ObscureException expected) {