1 package net.pterodactylus.sone.test;
3 import java.util.concurrent.atomic.AtomicReference;
5 import javax.annotation.Nonnull;
6 import javax.annotation.Nullable;
8 import net.pterodactylus.util.config.ConfigurationException;
9 import net.pterodactylus.util.config.Value;
11 import com.google.common.base.Objects;
14 * Simple {@link Value} implementation.
16 public class TestValue<T> implements Value<T> {
18 private final AtomicReference<T> value = new AtomicReference<>();
20 public TestValue(@Nullable T originalValue) {
21 value.set(originalValue);
26 public T getValue() throws ConfigurationException {
32 public T getValue(@Nullable T defaultValue) {
33 final T realValue = value.get();
34 return (realValue != null) ? realValue : defaultValue;
38 public void setValue(@Nullable T newValue) throws ConfigurationException {
43 public int hashCode() {
44 return value.hashCode();
48 public boolean equals(Object obj) {
49 return (obj instanceof TestValue) && Objects.equal(value.get(),
50 ((TestValue) obj).value.get());
55 public String toString() {
56 return String.valueOf(value.get());
60 public static <T> Value<T> from(@Nullable T value) {
61 return new TestValue<>(value);