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

@@ -2,7 +2,7 @@ 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;
@@ -11,8 +11,7 @@ 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");
@@ -28,27 +27,20 @@ public class TestTcpCommunication {
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(remoteLirc, iBuddy); Dummy dummy = new Dummy(localLirc, iBuddy);
Work server = localLoader.getServer(); Control server = localLoader.getServer();
// Can we reuse the same Thread for all Listens?
//localLirc.start();
remoteLirc.start(); remoteLirc.start();
server.start(); server.start();
dummy.start(); dummy.start();
Thread.sleep(10000); 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,4 +1,4 @@
package connected; package yaml;
import java.util.HashMap; import java.util.HashMap;
@@ -6,7 +6,7 @@ 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) {
@@ -18,7 +18,7 @@ public class TestParsing extends Listen<SignalObject<LircButton>> {
//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);

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