Skip to content

Commit

Permalink
Change internal State structures to be unsyncronized
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Aug 7, 2023
1 parent 69a7cd8 commit 814cda2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ private static boolean evaluateRelationships(Query elm, State state, CqlEngine v
state.push(new Variable().withName(relationship.getAlias()).withValue(relatedElement));
try {
Object satisfiesRelatedCondition = visitor.visitExpression(relationship.getSuchThat(), state);
if (relationship instanceof org.hl7.elm.r1.With
|| relationship instanceof org.hl7.elm.r1.Without) {
if (satisfiesRelatedCondition instanceof Boolean && (Boolean) satisfiesRelatedCondition) {
if ((relationship instanceof org.hl7.elm.r1.With
|| relationship instanceof org.hl7.elm.r1.Without) && Boolean.TRUE.equals(satisfiesRelatedCondition)) {
hasSatisfyingData = true;
break; // Once we have detected satisfying data, no need to continue testing
}
}
} finally {
state.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public State(Environment environment) {

private final Environment environment;

private Stack<String> currentContext = new Stack<>();
private Deque<String> currentContext = new ArrayDeque<>();

private Stack<Stack<Variable> > windows = new Stack<>();
private Stack<Library> currentLibrary = new Stack<>();
private Deque<Deque<Variable> > windows = new ArrayDeque<>();
private Deque<Library> currentLibrary = new ArrayDeque<>();

private Stack<HashSet<Object>> evaluatedResourceStack = new Stack<>();
private Deque<HashSet<Object>> evaluatedResourceStack = new ArrayDeque<>();

private Map<String, Object> parameters = new HashMap<>();
private Map<String, Object> contextValues = new HashMap<>();
Expand Down Expand Up @@ -104,11 +104,11 @@ public void setContextValues(Map<String, Object> contextValues) {
this.contextValues = contextValues;
}

public Stack<Stack<Variable>> getWindows() {
public Deque<Deque<Variable>> getWindows() {
return windows;
}

public void setWindows(Stack<Stack<Variable>> windows) {
public void setWindows(Deque<Deque<Variable>> windows) {
this.windows = windows;
}

Expand Down Expand Up @@ -170,7 +170,7 @@ public void init(Library library) {
}

public void pop() {
if (!windows.peek().empty())
if (!windows.peek().isEmpty())
getStack().pop();
}

Expand All @@ -179,10 +179,10 @@ public void push(Variable variable) {
}

public Variable resolveVariable(String name) {
for (int i = windows.size() - 1; i >= 0; i--) {
for (int j = 0; j < windows.get(i).size(); j++) {
if (windows.get(i).get(j).getName().equals(name)) {
return windows.get(i).get(j);
for (var window : windows) {
for (var v : window) {
if (v.getName().equals(name)) {
return v;
}
}
}
Expand All @@ -200,14 +200,14 @@ public Variable resolveVariable(String name, boolean mustResolve) {
}

public void pushWindow() {
windows.push(new Stack<>());
windows.push(new ArrayDeque<>());
}

public void popWindow() {
windows.pop();
}

private Stack<Variable> getStack() {
private Deque<Variable> getStack() {
return windows.peek();
}

Expand All @@ -225,11 +225,11 @@ public void exitContext() {
}

public String getCurrentContext() {
if (currentContext.empty()) {
if (currentContext.isEmpty()) {
return null;
}

return currentContext.peek();
return currentContext.peekFirst();
}

public Object getCurrentContextValue() {
Expand All @@ -242,7 +242,7 @@ public Object getCurrentContextValue() {
}

public Set<Object> getEvaluatedResources() {
if (evaluatedResourceStack.empty()) {
if (evaluatedResourceStack.isEmpty()) {
throw new IllegalStateException("Attempted to get the evaluatedResource stack when it's empty");
}

Expand All @@ -260,7 +260,7 @@ public void pushEvaluatedResourceStack() {

//serves pop and merge to the down
public void popEvaluatedResourceStack() {
if (evaluatedResourceStack.empty()) {
if (evaluatedResourceStack.isEmpty()) {
throw new IllegalStateException("Attempted to pop the evaluatedResource stack when it's empty");
}

Expand Down Expand Up @@ -288,9 +288,9 @@ public Object resolveAlias(String name) {
}

public Object resolveIdentifierRef(String name) {
for (int i = windows.size() - 1; i >= 0; i--) {
for (int j = 0; j < windows.get(i).size(); j++) {
Object value = windows.get(i).get(j).getValue();
for (var window : windows) {
for (var v : window) {
var value = v.getValue();
if (value instanceof org.opencds.cqf.cql.engine.runtime.Tuple) {
for (String key : ((org.opencds.cqf.cql.engine.runtime.Tuple) value).getElements().keySet()) {
if (key.equals(name)) {
Expand Down

0 comments on commit 814cda2

Please sign in to comment.