package biz.plexers.sparrow.core;

public class Resource {

	private String name;
	private int quantity;
	private Choices type;

	public enum Choices {

		Lumber, Cannons, Crew, Metal
	}

	public void changeQ(int offset) {

		if (quantity > offset) {
			quantity += offset;
		}

	}

	public void consume(Resource other) {

		if (other != null) {
			if (this.type.equals(other)) {
				this.quantity += other.quantity;
			}
		}
	}
}

@@ -34,423 +34,1603 @@
 %0D%0A%0D%0A
-public class Resource %7B%0D%0A%0D%0A%09private String name;%0D%0A%09private int quantity;%0D%0A%09private Choices type;%0D%0A%0D%0A%09public enum Choices %7B%0D%0A%0D%0A%09%09Lumber, Cannons, Crew, Metal%0D%0A%09%7D%0D%0A%0D%0A%09public void changeQ(int offset) %7B%0D%0A%0D%0A%09%09if (quantity %3E offset) %7B%0D%0A%09%09%09quantity += offset;%0D%0A%09%09%7D%0D%0A%0D%0A%09%7D%0D%0A%0D%0A%09public void consume(Resource other) %7B%0D%0A%0D%0A%09%09if (other != null) %7B%0D%0A%09%09%09if (this.type.equals(other)) %7B%0D%0A%09%09%09%09this.quantity += other.quantity;%0D%0A%09%09%09%7D%0D%0A%09%09%7D
+import java.io.IOException;%0D%0Aimport java.util.Map;%0D%0A%0D%0Aimport com.fasterxml.jackson.annotation.JsonCreator;%0D%0Aimport com.fasterxml.jackson.core.JsonGenerator;%0D%0Aimport com.fasterxml.jackson.core.JsonProcessingException;%0D%0Aimport com.fasterxml.jackson.databind.JsonSerializer;%0D%0Aimport com.fasterxml.jackson.databind.SerializerProvider;%0D%0Aimport com.fasterxml.jackson.databind.annotation.JsonSerialize;%0D%0A%0D%0A@JsonSerialize(using = Resource.Serializer.class)%0D%0Apublic class Resource %7B%0D%0A%0D%0A%09private String name;%0D%0A%09private int quantity;%0D%0A%09private Choices type;%0D%0A%0D%0A%09public enum Choices %7B%0D%0A%0D%0A%09%09Lumber, Cannons, Crew, Metal%0D%0A%09%7D%0D%0A%0D%0A%09public void changeQ(int offset) %7B%0D%0A%0D%0A%09%09if (quantity %3E offset) %7B%0D%0A%09%09%09quantity += offset;%0D%0A%09%09%7D%0D%0A%0D%0A%09%7D%0D%0A%0D%0A%09public void consume(Resource other) %7B%0D%0A%0D%0A%09%09if (other != null) %7B%0D%0A%09%09%09if (this.type.equals(other)) %7B%0D%0A%09%09%09%09this.quantity += other.quantity;%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09private Resource(Map%3CString, Object%3E props) %7B%0D%0A%09%09name = (String) props.get(%22name%22);%0D%0A%09%09quantity = (int) props.get(%22quantity%22);%0D%0A%09%09type = (Choices) props.get(%22type%22);%0D%0A%09%7D%0D%0A%0D%0A%09@JsonCreator%0D%0A%09public static Resource factory(Map%3CString, Object%3E props) %7B%0D%0A%09%09return new Resource(props);%0D%0A%09%7D%0D%0A%0D%0A%09public class Serializer extends JsonSerializer%3CResource%3E %7B%0D%0A%0D%0A%09%09@Override%0D%0A%09%09public void serialize(Resource value, JsonGenerator jgen,%0D%0A%09%09%09%09SerializerProvider provider) throws IOException,%0D%0A%09%09%09%09JsonProcessingException %7B%0D%0A%09%09%09jgen.writeStartObject();%0D%0A%09%09%09jgen.writeStringField(%22name%22, value.name);%0D%0A%09%09%09jgen.writeNumberField(%22quantity%22, value.quantity);%0D%0A%09%09%09jgen.writeObjectField(%22type%22, value.type);%0D%0A%09%09%09jgen.writeEndObject();%0D%0A%0D%0A%09%09%7D%0D%0A
 %0D%0A%09%7D

Make Resource serializable