Skip to content

Commit 539fbfd

Browse files
Reduce logical dependencies on TypeQL toString() (#56)
## What is the goal of this PR? As outlined in #54, a change in TypeQL meant that some of the `toString()` representations have changed. This PR reduces reliance on `toString()` for correctness, though more work needs to be done to eliminate the dependency. ## What are the changes implemented in this PR? * Fix one `toString()` check that included a comma that no longer exists * Replace to usages of `toString()` contains checks with operations over the TypeQL query object.
1 parent 6129787 commit 539fbfd

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/main/java/generator/AppendAttributeGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public boolean appendAttributeInsertStatementValid(TypeQLInsert insert) {
114114
if (insert == null) return false;
115115
if (!insert.toString().contains("isa " + appendConfiguration.getMatch().getType())) return false;
116116
for (Configuration.Definition.Attribute ownershipThingGetter : appendConfiguration.getMatch().getOwnerships()) {
117-
if (!insert.toString().contains(", has " + ownershipThingGetter.getAttribute())) return false;
117+
if (!insert.toString().contains("has " + ownershipThingGetter.getAttribute())) return false;
118118
}
119119
if (appendConfiguration.getInsert().getRequiredOwnerships() != null) {
120120
for (Configuration.Definition.Attribute attribute : appendConfiguration.getInsert().getRequiredOwnerships()) {

src/main/java/generator/RelationGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) {
101101
// ENTITY & RELATION PLAYER BY ATTRIBUTE(s)
102102
if (playerType(player).equals("byAttribute")) {
103103
ThingVariable.Thing playerMatchStatement = getThingPlayerMatchStatementByAttribute(row, player, playerVar);
104-
if (playerMatchStatement.toString().contains(", has")) {
104+
if (playerMatchStatement.constraints().stream().anyMatch(ThingConstraint::isHas)) {
105105
playerMatchStatements.add(playerMatchStatement);
106106
playerVars.add(playerVar);
107107
roleTypes.add(player.getRole());
@@ -186,7 +186,7 @@ private ArrayList<ThingVariable<?>> recursiveAssemblyMatchStatement(String[] row
186186
//terminating condition - byAttribute player:
187187
ArrayList<ThingVariable<?>> statements = new ArrayList<>();
188188
ThingVariable<?> statement = getThingPlayerMatchStatementByAttribute(row, player, playerVar);
189-
if (statement != null && statement.toString().contains(", has")) {
189+
if (statement != null && statement.constraints().stream().anyMatch(ThingConstraint::isHas)) {
190190
statements.add(statement);
191191
}
192192
return statements;

0 commit comments

Comments
 (0)