From 4dcc43061d05f14ceddbb9f3a0c43ab908b89a4b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 3 Jan 2021 23:58:21 +0100 Subject: VPN work. Also better sorting of output objects. --- src/main/java/io/trygvis/rules/acme/AcmeIo.java | 19 +++++++++++++------ src/main/java/io/trygvis/rules/engine/Main.java | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/main/java/io/trygvis') diff --git a/src/main/java/io/trygvis/rules/acme/AcmeIo.java b/src/main/java/io/trygvis/rules/acme/AcmeIo.java index 488c93a..0bd0f1e 100644 --- a/src/main/java/io/trygvis/rules/acme/AcmeIo.java +++ b/src/main/java/io/trygvis/rules/acme/AcmeIo.java @@ -15,8 +15,8 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; -import java.util.HashMap; import java.util.List; +import java.util.TreeMap; import java.util.function.Function; @SuppressWarnings("unchecked") @@ -83,10 +83,6 @@ public class AcmeIo { private static > Comparator comparable(Class klass, String name) { - if (klass.getName().contains("Wg")) { - System.out.println("AcmeIo.invoker"); - } - try { var method = klass.getMethod("get" + name.substring(0, 1).toUpperCase() + name.substring(1)); if (!method.isAccessible()) { @@ -98,6 +94,17 @@ public class AcmeIo { try { var x = (T) method.invoke(a); var y = (T) method.invoke(b); + + if (x == null && y == null) { + return 0; + } + + if (x == null) { + return -1; + } else if (y == null) { + return 1; + } + return x.compareTo(y); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); @@ -133,7 +140,7 @@ public class AcmeIo { } } - var facts = new HashMap, FactCollection>(factHandles.size()); + var facts = new TreeMap, FactCollection>(Comparator.comparing(Class::getName)); for (var handle : factHandles) { if (handle instanceof DefaultFactHandle h) { var obj = h.getObject(); diff --git a/src/main/java/io/trygvis/rules/engine/Main.java b/src/main/java/io/trygvis/rules/engine/Main.java index a3b0259..5556db7 100644 --- a/src/main/java/io/trygvis/rules/engine/Main.java +++ b/src/main/java/io/trygvis/rules/engine/Main.java @@ -38,7 +38,7 @@ public class Main { io.dump("phase-1", session.getFactHandles()); - io.dump("vs0", session.getFactHandles(), (Object o) -> { + io.dump("vpn0", session.getFactHandles(), (Object o) -> { return o.getClass().getName().contains("Wg") || o instanceof Machine || o instanceof DnsEntry; }); -- cgit v1.2.3