package lr;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by luca on 28/02/16.
 */
public class Data<T> {

    private String key;
    private int hash;
    private T value;

    public Data(String key, int hash, T value) {
        this.key = key;
        this.hash = hash;
        this.value = value;
    }

    public Data(JSONObject json) {
        try {
            this.key = json.getString("key");
        } catch (JSONException e) { }

        try {
            this.hash = json.getInt("hash");
        } catch (JSONException e) { }

        try {
            this.value = (T)json.get("value");
        } catch (JSONException e) { }
    }

    public void setKey(String key) {
        this.key = key;
    }

    public void setHash(int hash) {
        this.hash = hash;
    }

    public void setValue(T value) {
        this.value = value;
    }

    public String getKey() {

        return key;
    }

    public int getHash() {
        return hash;
    }

    public T getValue() {
        return value;
    }

    @Override
    public String toString() {
        return "Data{" +
                "key='" + key + '\'' +
                ", hash=" + hash +
                ", value=" + value +
                '}';
    }
}

@@ -454,32 +454,73 @@
 ONException e) %7B
+%0A            e.printStackTrace();%0A       
  %7D%0A%0A        try 
@@ -601,33 +601,116 @@
 ion e) %7B
- %7D%0A%0A        try %7B
+%0A            e.printStackTrace();%0A        %7D%0A%0A        try %7B%0A            //TODO: improve the cast to T
 %0A       
@@ -730,16 +730,17 @@
 ue = (T)
+ 
 json.get
@@ -785,16 +785,57 @@
 ion e) %7B
+%0A            e.printStackTrace();%0A       
  %7D%0A    %7D

fix empty catch