8184693: add Pattern.isEmpty
authorvtheeyarath
Wed, 18 Apr 2018 10:30:57 -0700
changeset 49823 af4b57a556be
parent 49822 53aae0c219e6
child 49824 e242740a92b8
8184693: add Pattern.isEmpty Summary: added method Pattern.isEmpty Reviewed-by: forax, chegar, smarks, psandoz, rriggs
src/java.base/share/classes/java/util/Optional.java
src/java.base/share/classes/java/util/OptionalDouble.java
src/java.base/share/classes/java/util/OptionalInt.java
src/java.base/share/classes/java/util/OptionalLong.java
test/jdk/java/util/Optional/Basic.java
test/jdk/java/util/Optional/BasicDouble.java
test/jdk/java/util/Optional/BasicInt.java
test/jdk/java/util/Optional/BasicLong.java
--- a/src/java.base/share/classes/java/util/Optional.java	Wed Apr 18 16:02:53 2018 -0400
+++ b/src/java.base/share/classes/java/util/Optional.java	Wed Apr 18 10:30:57 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -160,6 +160,17 @@
     }
 
     /**
+     * If a value is  not present, returns {@code true}, otherwise
+     * {@code false}.
+     *
+     * @return  {@code true} if a value is not present, otherwise {@code false}
+     * @since   11
+     */
+    public boolean isEmpty() {
+        return value == null;
+    }
+
+    /**
      * If a value is present, performs the given action with the value,
      * otherwise does nothing.
      *
--- a/src/java.base/share/classes/java/util/OptionalDouble.java	Wed Apr 18 16:02:53 2018 -0400
+++ b/src/java.base/share/classes/java/util/OptionalDouble.java	Wed Apr 18 10:30:57 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -140,6 +140,17 @@
     }
 
     /**
+     * If a value is not present, returns {@code true}, otherwise
+     * {@code false}.
+     *
+     * @return  {@code true} if a value is not present, otherwise {@code false}
+     * @since   11
+     */
+    public boolean isEmpty() {
+        return !isPresent;
+    }
+
+    /**
      * If a value is present, performs the given action with the value,
      * otherwise does nothing.
      *
--- a/src/java.base/share/classes/java/util/OptionalInt.java	Wed Apr 18 16:02:53 2018 -0400
+++ b/src/java.base/share/classes/java/util/OptionalInt.java	Wed Apr 18 10:30:57 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -140,6 +140,17 @@
     }
 
     /**
+     * If a value is not present, returns {@code true}, otherwise
+     * {@code false}.
+     *
+     * @return  {@code true} if a value is not present, otherwise {@code false}
+     * @since   11
+     */
+    public boolean isEmpty() {
+        return !isPresent;
+    }
+
+    /**
      * If a value is present, performs the given action with the value,
      * otherwise does nothing.
      *
--- a/src/java.base/share/classes/java/util/OptionalLong.java	Wed Apr 18 16:02:53 2018 -0400
+++ b/src/java.base/share/classes/java/util/OptionalLong.java	Wed Apr 18 10:30:57 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -140,6 +140,17 @@
     }
 
     /**
+     * If a value is not present, returns {@code true}, otherwise
+     * {@code false}.
+     *
+     * @return  {@code true} if a value is not present, otherwise {@code false}
+     * @since   11
+     */
+    public boolean isEmpty() {
+        return !isPresent;
+    }
+
+    /**
      * If a value is present, performs the given action with the value,
      * otherwise does nothing.
      *
--- a/test/jdk/java/util/Optional/Basic.java	Wed Apr 18 16:02:53 2018 -0400
+++ b/test/jdk/java/util/Optional/Basic.java	Wed Apr 18 10:30:57 2018 -0700
@@ -52,6 +52,7 @@
         assertFalse(empty.equals("unexpected"));
 
         assertFalse(empty.isPresent());
+        assertTrue(empty.isEmpty());
         assertEquals(empty.hashCode(), 0);
         assertEquals(empty.orElse("x"), "x");
         assertEquals(empty.orElseGet(() -> "y"), "y");
@@ -87,6 +88,7 @@
         assertFalse(opt.equals("unexpected"));
 
         assertTrue(opt.isPresent());
+        assertFalse(opt.isEmpty());
         assertEquals(opt.hashCode(), expected.hashCode());
         assertEquals(opt.orElse("unexpected"), expected);
         assertEquals(opt.orElseGet(() -> "unexpected"), expected);
--- a/test/jdk/java/util/Optional/BasicDouble.java	Wed Apr 18 16:02:53 2018 -0400
+++ b/test/jdk/java/util/Optional/BasicDouble.java	Wed Apr 18 10:30:57 2018 -0700
@@ -51,6 +51,7 @@
         assertFalse(empty.equals("unexpected"));
 
         assertFalse(empty.isPresent());
+        assertTrue(empty.isEmpty());
         assertEquals(empty.hashCode(), 0);
         assertEquals(empty.orElse(UNEXPECTED), UNEXPECTED);
         assertEquals(empty.orElseGet(() -> UNEXPECTED), UNEXPECTED);
@@ -86,6 +87,7 @@
         assertFalse(opt.equals("unexpected"));
 
         assertTrue(opt.isPresent());
+        assertFalse(opt.isEmpty());
         assertEquals(opt.hashCode(), Double.hashCode(expected));
         assertEquals(opt.orElse(UNEXPECTED), expected);
         assertEquals(opt.orElseGet(() -> UNEXPECTED), expected);
--- a/test/jdk/java/util/Optional/BasicInt.java	Wed Apr 18 16:02:53 2018 -0400
+++ b/test/jdk/java/util/Optional/BasicInt.java	Wed Apr 18 10:30:57 2018 -0700
@@ -52,6 +52,7 @@
         assertFalse(empty.equals("unexpected"));
 
         assertFalse(empty.isPresent());
+        assertTrue(empty.isEmpty());
         assertEquals(empty.hashCode(), 0);
         assertEquals(empty.orElse(UNEXPECTED), UNEXPECTED);
         assertEquals(empty.orElseGet(() -> UNEXPECTED), UNEXPECTED);
@@ -87,6 +88,7 @@
         assertFalse(opt.equals("unexpected"));
 
         assertTrue(opt.isPresent());
+        assertFalse(opt.isEmpty());
         assertEquals(opt.hashCode(), Integer.hashCode(expected));
         assertEquals(opt.orElse(UNEXPECTED), expected);
         assertEquals(opt.orElseGet(() -> UNEXPECTED), expected);
--- a/test/jdk/java/util/Optional/BasicLong.java	Wed Apr 18 16:02:53 2018 -0400
+++ b/test/jdk/java/util/Optional/BasicLong.java	Wed Apr 18 10:30:57 2018 -0700
@@ -51,6 +51,7 @@
         assertFalse(empty.equals("unexpected"));
 
         assertFalse(empty.isPresent());
+        assertTrue(empty.isEmpty());
         assertEquals(empty.hashCode(), 0);
         assertEquals(empty.orElse(UNEXPECTED), UNEXPECTED);
         assertEquals(empty.orElseGet(() -> UNEXPECTED), UNEXPECTED);
@@ -86,6 +87,7 @@
         assertFalse(opt.equals("unexpected"));
 
         assertTrue(opt.isPresent());
+        assertFalse(opt.isEmpty());
         assertEquals(opt.hashCode(), Long.hashCode(expected));
         assertEquals(opt.orElse(UNEXPECTED), expected);
         assertEquals(opt.orElseGet(() -> UNEXPECTED), expected);