This commit is contained in:
2016-07-03 12:18:59 +01:00
parent 4cb0910910
commit c521ef3215
8 changed files with 206 additions and 123 deletions

View File

@@ -10,5 +10,5 @@ repositories {
} }
dependencies { dependencies {
compile 'com.esotericsoftware.yamlbeans:yamlbeans:1.09'
} }

8
out.yml Normal file
View File

@@ -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

View File

@@ -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();
// }
}
}

View File

@@ -1,54 +1,46 @@
package connected; package connected;
import java.util.Properties; import java.util.Properties;
import base.work.Work; import base.Control;
import com.github.boukefalos.ibuddy.iBuddy; import com.github.boukefalos.ibuddy.iBuddy;
import com.github.boukefalos.lirc.Lirc; import com.github.boukefalos.lirc.Lirc;
import com.github.boukefalos.lirc.Loader; import com.github.boukefalos.lirc.Loader;
import dummy.Dummy; import dummy.Dummy;
public class TestTcpCommunication { public class TestTcpCommunication {
public static void main(String[] args) { public static void main(String[] args) throws Exception {
try { Properties localProperties = new Properties();
Properties localProperties = new Properties(); localProperties.setProperty("implementation", "local");
localProperties.setProperty("implementation", "local"); localProperties.setProperty("server", "true");
localProperties.setProperty("server", "true"); localProperties.setProperty("server.port", "8883");
localProperties.setProperty("server.port", "8883"); localProperties.setProperty("server.protocol", "tcp");
localProperties.setProperty("server.protocol", "tcp");
Properties remoteProperties = new Properties();
Properties remoteProperties = new Properties(); remoteProperties.setProperty("implementation", "remote");
remoteProperties.setProperty("implementation", "remote"); remoteProperties.setProperty("protocol", "tcp");
remoteProperties.setProperty("protocol", "tcp"); remoteProperties.setProperty("remote.host", "localhost");
remoteProperties.setProperty("remote.host", "localhost"); remoteProperties.setProperty("remote.port", "8883");
remoteProperties.setProperty("remote.port", "8883");
Loader localLoader = new Loader(localProperties);
Loader localLoader = new Loader(localProperties); Loader remoteLoader = new Loader(remoteProperties);
Loader remoteLoader = new Loader(remoteProperties);
Lirc localLirc = localLoader.getLirc();
//Lirc localLirc = localLoader.getLirc(); Lirc remoteLirc = remoteLoader.getLirc();
Lirc remoteLirc = remoteLoader.getLirc();
Properties iBuddyProperties = new Properties();
Properties iBuddyProperties = new Properties(); iBuddyProperties.setProperty("implementation", "local");
iBuddyProperties.setProperty("implementation", "local"); iBuddy iBuddy = new com.github.boukefalos.ibuddy.Loader(iBuddyProperties).getiBuddy();
iBuddy iBuddy = new com.github.boukefalos.ibuddy.Loader(iBuddyProperties).getiBuddy(); Dummy dummy = new Dummy(localLirc, iBuddy);
Dummy dummy = new Dummy(remoteLirc, iBuddy);
Control server = localLoader.getServer();
Work server = localLoader.getServer();
remoteLirc.start();
// Can we reuse the same Thread for all Listens? server.start();
//localLirc.start(); dummy.start();
remoteLirc.start();
server.start(); Thread.sleep(10000);
dummy.start(); }
}
Thread.sleep(10000);
//server.exit();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -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<Phone> phoneNumbers; // HashMap<String,String>
public Map<String,String> other;
//public HashMap<Phone> x;
}

View File

@@ -0,0 +1,6 @@
package yaml;
public class Phone {
public String name;
public String number;
}

View File

@@ -1,68 +1,68 @@
package connected; package yaml;
import java.util.HashMap; import java.util.HashMap;
import lirc.Lirc; import lirc.Lirc;
import base.work.Listen; import base.work.Listen;
import com.github.boukefalos.lirc.LircButton; import com.github.boukefalos.lirc.LircButton;
import com.github.boukefalos.lirc.implementation.LocalImplementation; import com.github.boukefalos.lirc.implementation.Local;
import com.github.boukefalos.lirc.util.SignalObject; import com.github.boukefalos.lirc.util.SignalObject;
public class TestParsing extends Listen<SignalObject<LircButton>> { public class TestParsing extends Listen<SignalObject<LircButton>> {
public static void main(String[] args) { public static void main(String[] args) {
new TestParsing().start(); new TestParsing().start();
} }
protected HashMap<String, LircButton[]> buttonMap; protected HashMap<String, LircButton[]> buttonMap;
//protected LircTaskMapCycle taskMapCycle; //protected LircTaskMapCycle taskMapCycle;
//buttonMap = new HashMap<String, LircButton[]>(); //buttonMap = new HashMap<String, LircButton[]>();
public void start() { public void start() {
LocalImplementation lirc = new LocalImplementation(); Local lirc = new Local();
/*public void put(String name, LircButton[] LircButtonArray) { /*public void put(String name, LircButton[] LircButtonArray) {
buttonMap.put(name, LircButtonArray); buttonMap.put(name, LircButtonArray);
}*/ }*/
/*public LircButton parseButton(Scanner scanner) throws UnknownButtonException { /*public LircButton parseButton(Scanner scanner) throws UnknownButtonException {
try { try {
LircButton[] buttonArray = buttonMap.get(remote); LircButton[] buttonArray = buttonMap.get(remote);
f (buttonArray != null) { f (buttonArray != null) {
for (LircButton button : buttonArray) { for (LircButton button : buttonArray) {
if (button.getCode().equals(code)) { if (button.getCode().equals(code)) {
return button; return button;
} }
} }
} }
} catch (InputMismatchException e) { } catch (InputMismatchException e) {
logger.error("", e); logger.error("", e);
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
logger.error("", e); logger.error("", e);
} }
throw new UnknownButtonException(); throw new UnknownButtonException();
}*/ }*/
/*put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); /*put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values());
put(DenonRC176Button.NAME, DenonRC176Button.values()); put(DenonRC176Button.NAME, DenonRC176Button.values());
put(SamsungBN5901015AButton.NAME, SamsungBN5901015AButton.values());*/ put(SamsungBN5901015AButton.NAME, SamsungBN5901015AButton.values());*/
lirc.Lirc.Signal x = Lirc.Signal.BEGIN; lirc.Lirc.Signal x = Lirc.Signal.BEGIN;
//lirc.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); //lirc.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values());
lirc.start(); lirc.start();
super.start(); super.start();
try { try {
Thread.sleep(100000000); Thread.sleep(100000000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
public void put(String name, LircButton[] LircButtonArray) { public void put(String name, LircButton[] LircButtonArray) {
buttonMap.put(name, LircButtonArray); buttonMap.put(name, LircButtonArray);
} }
} }

11
test.yml Normal file
View File

@@ -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