diff --git a/ApplianceModels.json b/ApplianceModels.json new file mode 100644 index 0000000..319ecb0 --- /dev/null +++ b/ApplianceModels.json @@ -0,0 +1,56 @@ +{ + "version": "1.0", + "models": [ + { + "model": "Sony AF9", + "type": "TV", + "functions": [ + { + "function": "DOWN", + "code": 1002 + }, { + "function": "LEFT", + "code": 1003 + }, { + "function": "RIGHT", + "code": 1004 + }, { + "function": "DOWN", + "code": 1005 + }, { + "function": "SELECT", + "code": 1006 + } + ] + } + , { + "model": "UBP-X800", + "type": "Blu-ray & DVD player", + "functions": [ + { + "function": "MAIN MENU", + "code": 2002 + }, { + "function": "SPEED +", + "code": 2003 + }, { + "function": "SPEED -", + "code": 2004 + }, { + "function": "NEXT", + "code": 2005 + }, { + "function": "PLAY", + "code": 2006 + }, { + "function": "STOP", + "code": 2007 + }, { + "function": "SELECT", + "code": 2008 + } + ] + } + ] +} + diff --git a/src/main/java/ApplianceModelsDefinition.java b/src/main/java/ApplianceModelsDefinition.java new file mode 100644 index 0000000..e885923 --- /dev/null +++ b/src/main/java/ApplianceModelsDefinition.java @@ -0,0 +1,122 @@ +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +public class ApplianceModelsDefinition { + private String version; + private List models; + private ObjectMapper objectMapper; + + ApplianceModelsDefinition(){ + this.objectMapper = new ObjectMapper(); + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public List getModels() { + return models; + } + + public void setModels(List models) { + this.models = models; + } + + public boolean importFromJSON(){ + try { + ApplianceModelsDefinition applianceModelsDefinition; + applianceModelsDefinition= objectMapper.readValue(new FileInputStream("ApplianceModels.json"), ApplianceModelsDefinition.class); + this.version = applianceModelsDefinition.getVersion(); + this.models = applianceModelsDefinition.getModels(); + return true; + } catch (JsonMappingException e) { + throw new RuntimeException(e); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (JsonParseException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} + +class Model { + private String model; + private String type; + private List functions; + + Model(String name, String type){ + this.model = name; + this.type = type; + } + Model(String name){ + this.model = name; + } + Model(){ + + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public List getFunctions() { + return functions; + } + + public void setFunctions(List functions) { + this.functions = functions; + } +} + +class Function { + private String function; + private int code; + + Function(String function, int code){ + this.function = function; + this.code = code; + } + Function(){ + + } + + public String getFunction() { + return function; + } + + public void setFunction(String function) { + this.function = function; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } +} diff --git a/src/main/java/Appliances.java b/src/main/java/Appliances.java new file mode 100644 index 0000000..56f906a --- /dev/null +++ b/src/main/java/Appliances.java @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.List; + +public class Appliances { + private String name; // Name of appliance. + private List