summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-01-03 23:58:21 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-01-03 23:58:21 +0100
commit4dcc43061d05f14ceddbb9f3a0c43ab908b89a4b (patch)
tree6287e48715840f68ae3449e491fb3a0b5a45f480 /src/main/java
parentb7d0da791505ec08bc5e87dc1f5245078c8b3d42 (diff)
downloadrules-sandbox-4dcc43061d05f14ceddbb9f3a0c43ab908b89a4b.tar.gz
rules-sandbox-4dcc43061d05f14ceddbb9f3a0c43ab908b89a4b.tar.bz2
rules-sandbox-4dcc43061d05f14ceddbb9f3a0c43ab908b89a4b.tar.xz
rules-sandbox-4dcc43061d05f14ceddbb9f3a0c43ab908b89a4b.zip
VPN work.
Also better sorting of output objects.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/trygvis/rules/acme/AcmeIo.java19
-rw-r--r--src/main/java/io/trygvis/rules/engine/Main.java2
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;
});