summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk/same/VariableFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main/java/com/orbekk/same/VariableFactory.java')
-rw-r--r--same/src/main/java/com/orbekk/same/VariableFactory.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/same/VariableFactory.java b/same/src/main/java/com/orbekk/same/VariableFactory.java
new file mode 100644
index 0000000..81b7615
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/VariableFactory.java
@@ -0,0 +1,54 @@
+package com.orbekk.same;
+
+import org.codehaus.jackson.type.TypeReference;
+
+/**
+ * TODO: Use WeakReference in order to make variables GC-able.
+ */
+public class VariableFactory {
+ Client.ClientInterface client;
+
+ private class VariableImpl<T> implements Variable<T> {
+ String identifier;
+ TypeReference<T> type;
+ T value;
+
+ public VariableImpl(String identifier, TypeReference<T> type) {
+ this.identifier = identifier;
+ this.type = type;
+ }
+
+ @Override
+ public T get() {
+ return value;
+ }
+
+ @Override
+ public void set(T value) {
+ }
+
+ @Override
+ public void update() {
+ value = client.getState().getParsedData(identifier, type);
+ }
+
+ @Override
+ public void setOnChangeListener(Variable.OnChangeListener<T> listener) {
+ throw new RuntimeException("Not implemented.");
+ }
+ }
+
+ public static VariableFactory create(Client.ClientInterface client) {
+ return new VariableFactory(client);
+ }
+
+ VariableFactory(Client.ClientInterface client) {
+ this.client = client;
+ }
+
+ public <T> Variable<T> create(String identifier, TypeReference<T> type) {
+ Variable<T> variable = new VariableImpl<T>(identifier, type);
+ variable.update();
+ return variable;
+ }
+}