public class EdgeRules {
private EELFLogger logger = EELFManager.getInstance().getLogger(EdgeRules.class);
-
+
private DocumentContext rulesDoc;
/**
String json = this.getEdgeRuleJson(rulesFilename);
rulesDoc = JsonPath.parse(json);
}
-
+
private String getEdgeRuleJson(String rulesFilename) {
InputStream is = getClass().getResourceAsStream(rulesFilename);
Scanner scanner = new Scanner(is);
String json = scanner.useDelimiter("\\Z").next();
scanner.close();
-
+
return json;
}
-
+
/**
* Loads the versioned DbEdgeRules json file for later parsing.
*/
private static class Helper {
private static final EdgeRules INSTANCE = new EdgeRules();
private static final Map<Version, EdgeRules> INSTANCEMAP = new ConcurrentHashMap<>();
-
+
private static EdgeRules getEdgeRulesByFilename(String rulesFilename) {
return new EdgeRules(rulesFilename);
}
-
+
private static EdgeRules getVersionedEdgeRules(Version v) {
if (Version.isLatest(v)) {
return INSTANCE;
/**
* Loads edge rules from the given file.
- *
+ *
* @param rulesFilename - name of the file to load rules from
* @return the EdgeRules instance
*/
public static EdgeRules getInstance(String rulesFilename) {
return Helper.getEdgeRulesByFilename(rulesFilename);
}
-
+
/**
* Adds the tree edge.
*
return result;
}
-
-
+
+
/**
* Gets the edge rule of the given type that exists between A and B.
* Will check B|A as well, and flips the direction accordingly if that succeeds
/**
* Verifies that all required properties are defined in the given edge rule.
* If they are not, throws a RuntimeException.
- *
+ *
* @param rule - Map<String edge property, String edge property value> representing
* an edge rule
*/
}
}
}
-
+
/**
* Reads all the edge rules from the loaded json file.
- *
+ *
* @return List<Map<String edge property, String edge property value>>
* Each map represents a rule read from the json.
*/
private List<Map<String, String>> readRules() {
return readRules(null);
}
-
+
/**
* Reads the edge rules from the loaded json file, using the given filter
* to get specific rules. If filter is null, will get all rules.
- *
+ *
* @param filter - may be null to indicate get all
* @return List<Map<String edge property, String edge property value>>
* Each map represents a rule read from the json.
}
return results;
}
-
+
/**
* Gets all the edge rules we define.
*
return result;
}
- /**
+ /**
* Gets all edge rules that define a child relationship from
* the given node type.
- *
+ *
* @param nodeType
* @return
*/