diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-28 13:44:10 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-28 13:44:10 +0200 |
commit | 36a72fe393ebd51f6ef4e486f463d560b93d18cd (patch) | |
tree | 1fb6b6bf23a442b6e10771fbfab6e954234cf732 /vespajlib/src | |
parent | 82049904c1ae9235eab7d11027dc85919819bee9 (diff) |
Explicitly pass the correct allocated hosts
Diffstat (limited to 'vespajlib/src')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/lang/SettableOptional.java | 35 |
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; + } + +} + |