// Path: QuestionApp/src/ca/ualberta/cs/cmput301f14t14/questionapp/data/ICommentable.java
// public interface ICommentable {
// 
// }
// 
// Path: QuestionApp/src/ca/ualberta/cs/cmput301f14t14/questionapp/model/Comment.java
// public class Comment<T extends ICommentable> implements Serializable {
// 	
// 	private static final long serialVersionUID = 2455600018596168474L;
// 
// 	private String body;
// 	private String author;
// 	private UUID id;
// 	private UUID parent;
// 	private Date date;
// 	private LocationHolder location;
// 
// 	public Comment() {
// 		setId(new UUID(0L, 0L));
// 		this.body = "";
// 		this.author = "";
// 		this.parent = null;
// 		setDate(new Date());
// 	}
// 	
// 	public Comment(UUID parent, String body, String username) {
// 		setId(UUID.randomUUID());
// 		this.body = body;
// 		this.author = username;
// 		this.parent = parent;
// 		setDate(new Date());
// 	}
// 
// 	public String getBody() {
// 		return body;
// 	}
// 	
// 	public void setBody(String body) {
// 		this.body = body;
// 	}
// 
// 	public String getAuthor() {
// 		return author;
// 	}
// 	
// 	public void setAuthor(String username) {
// 		this.author = username;
// 	}
// 
// 	public UUID getId() {
// 		return id;
// 	}
// 
// 	public void setId(UUID id) {
// 		this.id = id;
// 	}
// 	
// 	public UUID getParent() {
// 		return parent;
// 	}
// 	
// 	public void setParent(UUID parent) {
// 		this.parent = parent;
// 	}
// 
// 	//Check the attributes against each other and returns true if . Returns false otherwise or if a 
// 	//non comment is equated
// 	@Override
// 	public boolean equals(Object o) {
// 		if (!(o instanceof Comment<?>)) return false;
// 		@SuppressWarnings("unchecked")
// 		Comment<T> c = (Comment<T>) o;
// 		return c.id.equals(this.id) && c.body.equals(this.body) && c.author.equals(this.author); 
// 	}
// 	
// 	//Return string representation of a comment
// 	@Override
// 	public String toString() {
// 		return String.format("Comment [%s - %s]", body, author);
// 	}
// 
// 	public Date getDate() {
// 		return date;
// 	}
// 
// 	public void setDate(Date date) {
// 		this.date = date;
// 	}
// 
// 	public Location getLocation() {
// 		if(location == null){
// 			return null;
// 		}
// 		return location.getLocation();
// 	}
// 
// 	public void setLocation(LocationHolder lh) {
// 		this.location = lh;
// 	}
// 
// 	public void setLocation(Location location) {
// 		
// 		this.location = LocationHolder.getLocationHolder(location);
// 	}
// }
// 
// Path: QuestionApp/src/ca/ualberta/cs/cmput301f14t14/questionapp/model/LocationHolder.java
// public class LocationHolder implements Serializable {
// 
// 	/**
// 	 * Class that holds latitude and longitude and generates a Location when needed. Allows for easy serialization.
// 	 */
// 	private static final long serialVersionUID = -9097277563557497450L;
// 
// 	public double latitude;
// 	public double longitude;
// 	public LocationHolder(double lat, double lon){
// 		latitude = lat;
// 		longitude = lon;
// 	}
// 	
// 	public Location getLocation(){
// 		Location loc = new Location("");
// 		loc.setLatitude(latitude);
// 		loc.setLongitude(longitude);
// 		return loc;
// 	}
// 	
// 	public static LocationHolder getLocationHolder(Location loc){
// 		if (loc == null){
// 			return new LocationHolder(0,0);
// 		}
// 		return new LocationHolder(loc.getLatitude(), loc.getLongitude());
// 	}
// }


import java.lang.reflect.Type;
import java.util.Date;
import java.util.UUID;
import ca.ualberta.cs.cmput301f14t14.questionapp.data.ICommentable;
import ca.ualberta.cs.cmput301f14t14.questionapp.model.Comment;
import ca.ualberta.cs.cmput301f14t14.questionapp.model.LocationHolder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
package ca.ualberta.cs.cmput301f14t14.questionapp.model.serializer;




/**
 * Class used by GSON to deserialize Answer objects
 */
public class CommentDeserializer<T extends ICommentable> implements JsonDeserializer<Comment<T>> {

	public Comment<T> deserialize(final JsonElement json, final Type type,
			final JsonDeserializationContext context) throws JsonParseException {
		final JsonObject jsonObject = json.getAsJsonObject();

		final Comment<T> comment = new Comment<T>();
		comment.setId(UUID.fromString(jsonObject.get("id").getAsString()));
		comment.setParent(UUID.fromString(jsonObject.get("parent").getAsString()));
		comment.setBody(jsonObject.get("body").getAsString());
		comment.setAuthor(jsonObject.get("author").getAsString());
		comment.setDate((Date) context.deserialize(jsonObject.get("date"), Date.class));
// Path: QuestionApp/src/ca/ualberta/cs/cmput301f14t14/questionapp/data/ICommentable.java
// public interface ICommentable {
// 
// }
// 
// Path: QuestionApp/src/ca/ualberta/cs/cmput301f14t14/questionapp/model/Comment.java
// public class Comment<T extends ICommentable> implements Serializable {
// 	
// 	private static final long serialVersionUID = 2455600018596168474L;
// 
// 	private String body;
// 	private String author;
// 	private UUID id;
// 	private UUID parent;
// 	private Date date;
// 	private LocationHolder location;
// 
// 	public Comment() {
// 		setId(new UUID(0L, 0L));
// 		this.body = "";
// 		this.author = "";
// 		this.parent = null;
// 		setDate(new Date());
// 	}
// 	
// 	public Comment(UUID parent, String body, String username) {
// 		setId(UUID.randomUUID());
// 		this.body = body;
// 		this.author = username;
// 		this.parent = parent;
// 		setDate(new Date());
// 	}
// 
// 	public String getBody() {
// 		return body;
// 	}
// 	
// 	public void setBody(String body) {
// 		this.body = body;
// 	}
// 
// 	public String getAuthor() {
// 		return author;
// 	}
// 	
// 	public void setAuthor(String username) {
// 		this.author = username;
// 	}
// 
// 	public UUID getId() {
// 		return id;
// 	}
// 
// 	public void setId(UUID id) {
// 		this.id = id;
// 	}
// 	
// 	public UUID getParent() {
// 		return parent;
// 	}
// 	
// 	public void setParent(UUID parent) {
// 		this.parent = parent;
// 	}
// 
// 	//Check the attributes against each other and returns true if . Returns false otherwise or if a 
// 	//non comment is equated
// 	@Override
// 	public boolean equals(Object o) {
// 		if (!(o instanceof Comment<?>)) return false;
// 		@SuppressWarnings("unchecked")
// 		Comment<T> c = (Comment<T>) o;
// 		return c.id.equals(this.id) && c.body.equals(this.body) && c.author.equals(this.author); 
// 	}
// 	
// 	//Return string representation of a comment
// 	@Override
// 	public String toString() {
// 		return String.format("Comment [%s - %s]", body, author);
// 	}
// 
// 	public Date getDate() {
// 		return date;
// 	}
// 
// 	public void setDate(Date date) {
// 		this.date = date;
// 	}
// 
// 	public Location getLocation() {
// 		if(location == null){
// 			return null;
// 		}
// 		return location.getLocation();
// 	}
// 
// 	public void setLocation(LocationHolder lh) {
// 		this.location = lh;
// 	}
// 
// 	public void setLocation(Location location) {
// 		
// 		this.location = LocationHolder.getLocationHolder(location);
// 	}
// }
// 
// Path: QuestionApp/src/ca/ualberta/cs/cmput301f14t14/questionapp/model/LocationHolder.java
// public class LocationHolder implements Serializable {
// 
// 	/**
// 	 * Class that holds latitude and longitude and generates a Location when needed. Allows for easy serialization.
// 	 */
// 	private static final long serialVersionUID = -9097277563557497450L;
// 
// 	public double latitude;
// 	public double longitude;
// 	public LocationHolder(double lat, double lon){
// 		latitude = lat;
// 		longitude = lon;
// 	}
// 	
// 	public Location getLocation(){
// 		Location loc = new Location("");
// 		loc.setLatitude(latitude);
// 		loc.setLongitude(longitude);
// 		return loc;
// 	}
// 	
// 	public static LocationHolder getLocationHolder(Location loc){
// 		if (loc == null){
// 			return new LocationHolder(0,0);
// 		}
// 		return new LocationHolder(loc.getLatitude(), loc.getLongitude());
// 	}
// }


// Path: QuestionApp/src/ca/ualberta/cs/cmput301f14t14/questionapp/model/serializer/CommentDeserializer.java
import java.lang.reflect.Type;
import java.util.Date;
import java.util.UUID;
import ca.ualberta.cs.cmput301f14t14.questionapp.data.ICommentable;
import ca.ualberta.cs.cmput301f14t14.questionapp.model.Comment;
import ca.ualberta.cs.cmput301f14t14.questionapp.model.LocationHolder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

package ca.ualberta.cs.cmput301f14t14.questionapp.model.serializer;




/**
 * Class used by GSON to deserialize Answer objects
 */
public class CommentDeserializer<T extends ICommentable> implements JsonDeserializer<Comment<T>> {

	public Comment<T> deserialize(final JsonElement json, final Type type,
			final JsonDeserializationContext context) throws JsonParseException {
		final JsonObject jsonObject = json.getAsJsonObject();

		final Comment<T> comment = new Comment<T>();
		comment.setId(UUID.fromString(jsonObject.get("id").getAsString()));
		comment.setParent(UUID.fromString(jsonObject.get("parent").getAsString()));
		comment.setBody(jsonObject.get("body").getAsString());
		comment.setAuthor(jsonObject.get("author").getAsString());
		comment.setDate((Date) context.deserialize(jsonObject.get("date"), Date.class));
		comment.setLocation((LocationHolder) context.deserialize(jsonObject.get("location"), LocationHolder.class));