aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-08-28 13:44:10 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2017-08-28 13:44:10 +0200
commit36a72fe393ebd51f6ef4e486f463d560b93d18cd (patch)
tree1fb6b6bf23a442b6e10771fbfab6e954234cf732 /vespajlib/src
parent82049904c1ae9235eab7d11027dc85919819bee9 (diff)
Explicitly pass the correct allocated hosts
Diffstat (limited to 'vespajlib/src')
-rw-r--r--vespajlib/src/main/java/com/yahoo/lang/SettableOptional.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/lang/SettableOptional.java b/vespajlib/src/main/java/com/yahoo/lang/SettableOptional.java
new file mode 100644
index 00000000000..74abd4101a4
--- /dev/null
+++ b/vespajlib/src/main/java/com/yahoo/lang/SettableOptional.java
@@ -0,0 +1,35 @@
+package com.yahoo.lang;
+
+import java.util.NoSuchElementException;
+
+/**
+ * An optional which contains a settable value
+ *
+ * @author bratseth
+ */
+public final class SettableOptional<T> {
+
+ private T value = null;
+
+ /** Creates a new empty settable optional */
+ public SettableOptional() {}
+
+ /** Creates a new settable optional with the given value */
+ public SettableOptional(T value) { this.value = value; }
+
+ public boolean isPresent() {
+ return value != null;
+ }
+
+ public T get() {
+ if (value == null)
+ throw new NoSuchElementException("No value present");
+ return value;
+ }
+
+ public void set(T value) {
+ this.value = value;
+ }
+
+}
+