Move test Value implementation to top-level class.
[Sone.git] / src / test / java / net / pterodactylus / sone / TestValue.java
1 package net.pterodactylus.sone;
2
3 import java.util.concurrent.atomic.AtomicReference;
4
5 import net.pterodactylus.util.config.ConfigurationException;
6 import net.pterodactylus.util.config.Value;
7
8 /**
9 * Simple {@link Value} implementation.
10 *
11 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
12 */
13 public class TestValue<T> implements Value<T> {
14
15         private final AtomicReference<T> value = new AtomicReference<T>();
16
17         public TestValue(T originalValue) {
18                 value.set(originalValue);
19         }
20
21         @Override
22         public T getValue() throws ConfigurationException {
23                 return value.get();
24         }
25
26         @Override
27         public T getValue(T defaultValue) {
28                 final T realValue = value.get();
29                 return (realValue != null) ? realValue : defaultValue;
30         }
31
32         @Override
33         public void setValue(T newValue) throws ConfigurationException {
34                 value.set(newValue);
35         }
36
37 }