diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/io/trygvis/rules/acme/AcmeIo.java | 19 | ||||
-rw-r--r-- | src/main/java/io/trygvis/rules/engine/Main.java | 2 |
2 files changed, 14 insertions, 7 deletions
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 <A, T extends Comparable<T>> Comparator comparable(Class<A> 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<Class<?>, FactCollection<Object>>(factHandles.size()); + var facts = new TreeMap<Class<?>, FactCollection<Object>>(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; }); |