Switching PCs

This commit is contained in:
pahimar 2013-11-19 20:19:33 -05:00
parent 02eead3672
commit ce3097c7e4
3 changed files with 92 additions and 0 deletions

View file

@ -0,0 +1,29 @@
package com.pahimar.ee3.api;
import java.lang.reflect.Type;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.pahimar.ee3.item.CustomWrappedStack;
public class CustomWrappedStackSerializer implements JsonDeserializer<CustomWrappedStack>, JsonSerializer<CustomWrappedStack> {
@Override
public JsonElement serialize(CustomWrappedStack customWrappedStack, Type type, JsonSerializationContext context) {
// TODO Auto-generated method stub
return null;
}
@Override
public CustomWrappedStack deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -0,0 +1,30 @@
package com.pahimar.ee3.api;
import java.lang.reflect.Type;
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;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.pahimar.ee3.emc.EmcValue;
public class EmcValueSerializer implements JsonDeserializer<EmcValue>, JsonSerializer<EmcValue> {
@Override
public JsonElement serialize(EmcValue emcValue, Type type, JsonSerializationContext context) {
JsonObject jsonObject = new JsonObject();
return null;
}
@Override
public EmcValue deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -4,6 +4,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.pahimar.ee3.api.EmcValueSerializer;
/**
* Equivalent-Exchange-3
*
@ -15,6 +20,7 @@ import java.util.List;
*/
public class EmcValue implements Comparable<EmcValue> {
private static final Gson gson = (new GsonBuilder()).registerTypeAdapter(EmcValue.class, new EmcValueSerializer()).create();
public final float[] components;
public EmcValue() {
@ -148,6 +154,33 @@ public class EmcValue implements Comparable<EmcValue> {
return -1;
}
}
/**
* Deserializes an EmcValue object from the given serialized json String
*
* @param jsonEmcValue Json encoded String representing a EmcValue object
* @return The EmcValue that was encoded as json, or null if a valid EmcValue could not be decoded from given String
*/
public static EmcValue createFromJson(String jsonEmcValue) {
try {
return (EmcValue) gson.fromJson(jsonEmcValue, EmcValue.class);
}
catch (JsonSyntaxException exception) {
// TODO Log something regarding the failed parse
}
return null;
}
/**
* Returns this EmcValue as a json serialized String
*
* @return Json serialized String of this EmcValue
*/
public String toJson() {
return gson.toJson(this);
}
private static List<EmcComponent> collateComponents(List<EmcComponent> uncollatedComponents) {