From 463a4d7e78b97069d553527c0413cf7b5d7f7867 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 27 Aug 2023 01:48:09 +0200 Subject: [PATCH] New method #isSet() in Lazy and LazyOrException class --- .../src/main/java/fr/pandacube/lib/util/Lazy.java | 9 +++++++++ .../main/java/fr/pandacube/lib/util/LazyOrException.java | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/pandalib-util/src/main/java/fr/pandacube/lib/util/Lazy.java b/pandalib-util/src/main/java/fr/pandacube/lib/util/Lazy.java index 1d5d24e..4f33e8a 100644 --- a/pandalib-util/src/main/java/fr/pandacube/lib/util/Lazy.java +++ b/pandalib-util/src/main/java/fr/pandacube/lib/util/Lazy.java @@ -56,4 +56,13 @@ public class Lazy implements Supplier { cached = true; } + /** + * Tells if the value is currently set or not. + * @return true if the value has been set by calling the method {@link #get()} or {@link #set(Object)} but not yet + * reset by {@link #reset()}, or false otherwise. + */ + public synchronized boolean isSet() { + return cached; + } + } diff --git a/pandalib-util/src/main/java/fr/pandacube/lib/util/LazyOrException.java b/pandalib-util/src/main/java/fr/pandacube/lib/util/LazyOrException.java index c3b5063..1dd1e45 100644 --- a/pandalib-util/src/main/java/fr/pandacube/lib/util/LazyOrException.java +++ b/pandalib-util/src/main/java/fr/pandacube/lib/util/LazyOrException.java @@ -58,4 +58,13 @@ public class LazyOrException implements SupplierExceptio cached = true; } + /** + * Tells if the value is currently set or not. + * @return true if the value has been set by calling the method {@link #get()} or {@link #set(Object)} but not yet + * reset by {@link #reset()}, or false otherwise. + */ + public synchronized boolean isSet() { + return cached; + } + }