1 package net.pterodactylus.sone;
3 import java.util.concurrent.atomic.AtomicReference;
5 import net.pterodactylus.util.config.ConfigurationException;
6 import net.pterodactylus.util.config.Value;
8 import com.google.common.base.Objects;
11 * Simple {@link Value} implementation.
13 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
15 public class TestValue<T> implements Value<T> {
17 private final AtomicReference<T> value = new AtomicReference<T>();
19 public TestValue(T originalValue) {
20 value.set(originalValue);
24 public T getValue() throws ConfigurationException {
29 public T getValue(T defaultValue) {
30 final T realValue = value.get();
31 return (realValue != null) ? realValue : defaultValue;
35 public void setValue(T newValue) throws ConfigurationException {
40 public int hashCode() {
41 return value.hashCode();
45 public boolean equals(Object obj) {
46 return (obj instanceof TestValue) && Objects.equal(value.get(),
47 ((TestValue) obj).value.get());
51 public String toString() {
52 return String.valueOf(value.get());
55 public static <T> Value<T> from(T value) {
56 return new TestValue<T>(value);