--- old/src/java.base/share/classes/java/util/Optional.java 2018-04-17 22:26:25.895416383 -0700 +++ new/src/java.base/share/classes/java/util/Optional.java 2018-04-17 22:26:25.604389587 -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. * --- old/src/java.base/share/classes/java/util/OptionalDouble.java 2018-04-17 22:26:26.475469791 -0700 +++ new/src/java.base/share/classes/java/util/OptionalDouble.java 2018-04-17 22:26:26.206445021 -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. * --- old/src/java.base/share/classes/java/util/OptionalInt.java 2018-04-17 22:26:27.032521081 -0700 +++ new/src/java.base/share/classes/java/util/OptionalInt.java 2018-04-17 22:26:26.765496495 -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. * --- old/src/java.base/share/classes/java/util/OptionalLong.java 2018-04-17 22:26:27.626575778 -0700 +++ new/src/java.base/share/classes/java/util/OptionalLong.java 2018-04-17 22:26:27.356550916 -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. * --- old/test/jdk/java/util/Optional/Basic.java 2018-04-17 22:26:28.219630383 -0700 +++ new/test/jdk/java/util/Optional/Basic.java 2018-04-17 22:26:27.933604048 -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); --- old/test/jdk/java/util/Optional/BasicDouble.java 2018-04-17 22:26:28.886691803 -0700 +++ new/test/jdk/java/util/Optional/BasicDouble.java 2018-04-17 22:26:28.560661784 -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); --- old/test/jdk/java/util/Optional/BasicInt.java 2018-04-17 22:26:29.468745395 -0700 +++ new/test/jdk/java/util/Optional/BasicInt.java 2018-04-17 22:26:29.166717586 -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); --- old/test/jdk/java/util/Optional/BasicLong.java 2018-04-17 22:26:30.046798618 -0700 +++ new/test/jdk/java/util/Optional/BasicLong.java 2018-04-17 22:26:29.761772375 -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);