Commit fda72c0b authored by Tanita's avatar Tanita

rename ProductState to State

parent 177981b7
package model;
import com.google.gson.annotations.SerializedName;
import models.ProductState;
import models.State;
import models.StockState;
public class Product {
......@@ -10,7 +10,7 @@ public class Product {
private double price;
@SerializedName("init_price")
private double initPrice;
private ProductState state;
private State state;
@SerializedName("honorary_code")
private String honoraryCode;
......@@ -56,11 +56,11 @@ public class Product {
this.price = price;
}
public ProductState getState() {
public State getState() {
return state;
}
public void setState(ProductState state) {
public void setState(State state) {
this.state = state;
}
......
......@@ -3,7 +3,7 @@ package models;
import services.CodeGenerator;
import model.Product;
public class SaleState extends ProductState {
public class SaleState extends State {
public SaleState() {
super("for_sale");
}
......
......@@ -2,7 +2,7 @@ package models;
import model.Product;
public class SoldState extends ProductState{
public class SoldState extends State {
public SoldState() {
super("sold");
......
......@@ -2,10 +2,10 @@ package models;
import model.Product;
public abstract class ProductState {
public abstract class State {
private final String title;
protected ProductState(String title) {
protected State(String title) {
this.title = title;
}
......
......@@ -2,7 +2,7 @@ package models;
import model.Product;
public class StockState extends ProductState{
public class StockState extends State {
public StockState() {
super("in_stock");
}
......
......@@ -6,7 +6,7 @@ import application.utils.FileReader;
import application.utils.FileWriter;
import model.Product;
import models.ProductCollection;
import models.ProductState;
import models.State;
import java.io.IOException;
import java.nio.file.Files;
......@@ -15,8 +15,8 @@ import java.nio.file.Paths;
public class ProductRepository {
private final Gson gson = new GsonBuilder()
.registerTypeAdapter(ProductState.class, new ProductStateDeserialize())
.registerTypeAdapter(ProductState.class, new ProductStateSerialize())
.registerTypeAdapter(State.class, new ProductStateDeserialize())
.registerTypeAdapter(State.class, new ProductStateSerialize())
.setPrettyPrinting()
.create();
......
......@@ -5,14 +5,14 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import models.SaleState;
import models.ProductState;
import models.State;
import models.SoldState;
import models.StockState;
import java.lang.reflect.Type;
public class ProductStateDeserialize implements JsonDeserializer<ProductState> {
public ProductState deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
public class ProductStateDeserialize implements JsonDeserializer<State> {
public State deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
String type = json.getAsString();
switch (type){
......
......@@ -4,12 +4,12 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import models.ProductState;
import models.State;
import java.lang.reflect.Type;
public class ProductStateSerialize implements JsonSerializer<ProductState> {
public JsonElement serialize(ProductState src, Type typeOfSrc, JsonSerializationContext context) {
public class ProductStateSerialize implements JsonSerializer<State> {
public JsonElement serialize(State src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.getTitle());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment