From c521ef3215c1763925dff714653a3b48c42e1bed Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Sun, 3 Jul 2016 12:18:59 +0100 Subject: [PATCH] Snapshot --- build.gradle | 2 +- out.yml | 8 ++ src/main/java/connected/TestFromYaml.java | 52 +++++++ .../java/connected/TestTcpCommunication.java | 100 ++++++------- src/main/java/yaml/Contact.java | 14 ++ src/main/java/yaml/Phone.java | 6 + .../java/{connected => yaml}/TestParsing.java | 136 +++++++++--------- test.yml | 11 ++ 8 files changed, 206 insertions(+), 123 deletions(-) create mode 100644 out.yml create mode 100644 src/main/java/connected/TestFromYaml.java create mode 100644 src/main/java/yaml/Contact.java create mode 100644 src/main/java/yaml/Phone.java rename src/main/java/{connected => yaml}/TestParsing.java (91%) create mode 100644 test.yml diff --git a/build.gradle b/build.gradle index b44bee4..b605a2e 100644 --- a/build.gradle +++ b/build.gradle @@ -10,5 +10,5 @@ repositories { } dependencies { - + compile 'com.esotericsoftware.yamlbeans:yamlbeans:1.09' } \ No newline at end of file diff --git a/out.yml b/out.yml new file mode 100644 index 0000000..fd8ab02 --- /dev/null +++ b/out.yml @@ -0,0 +1,8 @@ +address: 4011 16th Ave S +phone numbers: +- number: 206-555-5138 + name: Home +- number: 425-555-2306 + name: Work +name: Nathan Sweet +age: 28 diff --git a/src/main/java/connected/TestFromYaml.java b/src/main/java/connected/TestFromYaml.java new file mode 100644 index 0000000..8398a5c --- /dev/null +++ b/src/main/java/connected/TestFromYaml.java @@ -0,0 +1,52 @@ +package connected; + +import java.io.FileReader; +import java.io.OutputStreamWriter; +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.Map; + +import yaml.Contact; + +import com.esotericsoftware.yamlbeans.YamlReader; +import com.esotericsoftware.yamlbeans.YamlWriter; + +public class TestFromYaml { + + + + public static void main(String[] args) throws Exception { + YamlReader reader = new YamlReader(new FileReader("test.yml")); + + // while (true) { + //Map contact = (Map) reader.read(); + //if (contact == null) break; + //System.out.println(contact.get("age")); + Class clazz = Contact.class; + for (Field field : clazz.getDeclaredFields()) { + Class type = field.getType(); + if (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)) { + System.out.println(field.getName()); + ParameterizedType listType = (ParameterizedType) field.getGenericType(); + Class x = (Class) listType.getActualTypeArguments()[0]; + System.out.println(x); + reader.getConfig().setPropertyElementType(clazz, field.getName(), x); + } + } + //reader.getConfig().setPropertyElementType(Contact.class, "phoneNumbers", Phone.class); + + Contact x = reader.read(Contact.class); + System.out.println(x.phoneNumbers.get(0)); + System.out.println(x.phoneNumbers.get(0).number); + //System.out.println(x.phoneNumbers.get(0).get("number")); + YamlWriter writer = new YamlWriter(new OutputStreamWriter(System.out)); + //writer.write(contact); + //writer.close(); + // } + + } + +} + diff --git a/src/main/java/connected/TestTcpCommunication.java b/src/main/java/connected/TestTcpCommunication.java index bfb1437..8b64ec1 100644 --- a/src/main/java/connected/TestTcpCommunication.java +++ b/src/main/java/connected/TestTcpCommunication.java @@ -1,54 +1,46 @@ -package connected; - -import java.util.Properties; - -import base.work.Work; - -import com.github.boukefalos.ibuddy.iBuddy; -import com.github.boukefalos.lirc.Lirc; -import com.github.boukefalos.lirc.Loader; - -import dummy.Dummy; - -public class TestTcpCommunication { - public static void main(String[] args) { - try { - Properties localProperties = new Properties(); - localProperties.setProperty("implementation", "local"); - localProperties.setProperty("server", "true"); - localProperties.setProperty("server.port", "8883"); - localProperties.setProperty("server.protocol", "tcp"); - - Properties remoteProperties = new Properties(); - remoteProperties.setProperty("implementation", "remote"); - remoteProperties.setProperty("protocol", "tcp"); - remoteProperties.setProperty("remote.host", "localhost"); - remoteProperties.setProperty("remote.port", "8883"); - - Loader localLoader = new Loader(localProperties); - Loader remoteLoader = new Loader(remoteProperties); - - //Lirc localLirc = localLoader.getLirc(); - Lirc remoteLirc = remoteLoader.getLirc(); - - Properties iBuddyProperties = new Properties(); - iBuddyProperties.setProperty("implementation", "local"); - iBuddy iBuddy = new com.github.boukefalos.ibuddy.Loader(iBuddyProperties).getiBuddy(); - Dummy dummy = new Dummy(remoteLirc, iBuddy); - - Work server = localLoader.getServer(); - - // Can we reuse the same Thread for all Listens? - //localLirc.start(); - remoteLirc.start(); - server.start(); - dummy.start(); - - - Thread.sleep(10000); - //server.exit(); - } catch (Exception e) { - e.printStackTrace(); - } - } -} +package connected; + +import java.util.Properties; + +import base.Control; + +import com.github.boukefalos.ibuddy.iBuddy; +import com.github.boukefalos.lirc.Lirc; +import com.github.boukefalos.lirc.Loader; + +import dummy.Dummy; + +public class TestTcpCommunication { + public static void main(String[] args) throws Exception { + Properties localProperties = new Properties(); + localProperties.setProperty("implementation", "local"); + localProperties.setProperty("server", "true"); + localProperties.setProperty("server.port", "8883"); + localProperties.setProperty("server.protocol", "tcp"); + + Properties remoteProperties = new Properties(); + remoteProperties.setProperty("implementation", "remote"); + remoteProperties.setProperty("protocol", "tcp"); + remoteProperties.setProperty("remote.host", "localhost"); + remoteProperties.setProperty("remote.port", "8883"); + + Loader localLoader = new Loader(localProperties); + Loader remoteLoader = new Loader(remoteProperties); + + Lirc localLirc = localLoader.getLirc(); + Lirc remoteLirc = remoteLoader.getLirc(); + + Properties iBuddyProperties = new Properties(); + iBuddyProperties.setProperty("implementation", "local"); + iBuddy iBuddy = new com.github.boukefalos.ibuddy.Loader(iBuddyProperties).getiBuddy(); + Dummy dummy = new Dummy(localLirc, iBuddy); + + Control server = localLoader.getServer(); + + remoteLirc.start(); + server.start(); + dummy.start(); + + Thread.sleep(10000); + } +} diff --git a/src/main/java/yaml/Contact.java b/src/main/java/yaml/Contact.java new file mode 100644 index 0000000..11c2c5c --- /dev/null +++ b/src/main/java/yaml/Contact.java @@ -0,0 +1,14 @@ +package yaml; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Contact { + public String name; + public int age; + public String address; + public List phoneNumbers; // HashMap + public Map other; + //public HashMap x; +} diff --git a/src/main/java/yaml/Phone.java b/src/main/java/yaml/Phone.java new file mode 100644 index 0000000..a32d6f2 --- /dev/null +++ b/src/main/java/yaml/Phone.java @@ -0,0 +1,6 @@ +package yaml; + +public class Phone { + public String name; + public String number; +} diff --git a/src/main/java/connected/TestParsing.java b/src/main/java/yaml/TestParsing.java similarity index 91% rename from src/main/java/connected/TestParsing.java rename to src/main/java/yaml/TestParsing.java index abb73da..b292463 100644 --- a/src/main/java/connected/TestParsing.java +++ b/src/main/java/yaml/TestParsing.java @@ -1,68 +1,68 @@ -package connected; - -import java.util.HashMap; - -import lirc.Lirc; -import base.work.Listen; - -import com.github.boukefalos.lirc.LircButton; -import com.github.boukefalos.lirc.implementation.LocalImplementation; -import com.github.boukefalos.lirc.util.SignalObject; -public class TestParsing extends Listen> { - public static void main(String[] args) { - new TestParsing().start(); - } - - protected HashMap buttonMap; - //protected LircTaskMapCycle taskMapCycle; - //buttonMap = new HashMap(); - - public void start() { - LocalImplementation lirc = new LocalImplementation(); - - /*public void put(String name, LircButton[] LircButtonArray) { - buttonMap.put(name, LircButtonArray); - }*/ - - - /*public LircButton parseButton(Scanner scanner) throws UnknownButtonException { - try { - - LircButton[] buttonArray = buttonMap.get(remote); - f (buttonArray != null) { - for (LircButton button : buttonArray) { - if (button.getCode().equals(code)) { - return button; - } - } - } - } catch (InputMismatchException e) { - logger.error("", e); - } catch (NoSuchElementException e) { - logger.error("", e); - } - throw new UnknownButtonException(); -}*/ - - /*put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); - put(DenonRC176Button.NAME, DenonRC176Button.values()); - put(SamsungBN5901015AButton.NAME, SamsungBN5901015AButton.values());*/ - - lirc.Lirc.Signal x = Lirc.Signal.BEGIN; - //lirc.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); - lirc.start(); - super.start(); - - try { - Thread.sleep(100000000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - public void put(String name, LircButton[] LircButtonArray) { - buttonMap.put(name, LircButtonArray); - } -} +package yaml; + +import java.util.HashMap; + +import lirc.Lirc; +import base.work.Listen; + +import com.github.boukefalos.lirc.LircButton; +import com.github.boukefalos.lirc.implementation.Local; +import com.github.boukefalos.lirc.util.SignalObject; +public class TestParsing extends Listen> { + public static void main(String[] args) { + new TestParsing().start(); + } + + protected HashMap buttonMap; + //protected LircTaskMapCycle taskMapCycle; + //buttonMap = new HashMap(); + + public void start() { + Local lirc = new Local(); + + /*public void put(String name, LircButton[] LircButtonArray) { + buttonMap.put(name, LircButtonArray); + }*/ + + + /*public LircButton parseButton(Scanner scanner) throws UnknownButtonException { + try { + + LircButton[] buttonArray = buttonMap.get(remote); + f (buttonArray != null) { + for (LircButton button : buttonArray) { + if (button.getCode().equals(code)) { + return button; + } + } + } + } catch (InputMismatchException e) { + logger.error("", e); + } catch (NoSuchElementException e) { + logger.error("", e); + } + throw new UnknownButtonException(); +}*/ + + /*put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); + put(DenonRC176Button.NAME, DenonRC176Button.values()); + put(SamsungBN5901015AButton.NAME, SamsungBN5901015AButton.values());*/ + + lirc.Lirc.Signal x = Lirc.Signal.BEGIN; + //lirc.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); + lirc.start(); + super.start(); + + try { + Thread.sleep(100000000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public void put(String name, LircButton[] LircButtonArray) { + buttonMap.put(name, LircButtonArray); + } +} diff --git a/test.yml b/test.yml new file mode 100644 index 0000000..801e11c --- /dev/null +++ b/test.yml @@ -0,0 +1,11 @@ +name: Nathan Sweet +age: 28 +address: 4011 16th Ave S +phoneNumbers: + - name: Home + number: 206-555-5138 + - name: Work + number: 425-555-2306 +other: + name: Home + number: 206-555-5138 \ No newline at end of file