From 67e0ffad037f74dc636483abb84c5e3cd55257d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Wed, 18 Oct 2023 10:50:21 +0200 Subject: [PATCH] Task 2 done --- ApplianceModels.json | 56 +++++++++ src/main/java/ApplianceModelsDefinition.java | 122 +++++++++++++++++++ src/main/java/Appliances.java | 32 +++++ src/main/java/Button.java | 31 +++++ src/main/java/RCU.java | 58 +++++++++ src/main/java/Task2.java | 25 ++++ 6 files changed, 324 insertions(+) create mode 100644 ApplianceModels.json create mode 100644 src/main/java/ApplianceModelsDefinition.java create mode 100644 src/main/java/Appliances.java create mode 100644 src/main/java/Button.java create mode 100644 src/main/java/RCU.java create mode 100644 src/main/java/Task2.java 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