Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a match state filter #689

Merged
merged 6 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions core/src/main/java/tc/oc/pgm/filters/FilterParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,44 @@ public ScoreFilter parseScoreFilter(Element el) throws InvalidXMLException {
return new ScoreFilter(XMLUtils.parseNumericRange(new Node(el), Integer.class));
}

@MethodParser("match-phase")
public Filter parseMatchPhase(Element el) throws InvalidXMLException {
return parseMatchPhaseFilter(el.getValue(), el);
}

@MethodParser("match-started")
public Filter parseMatchStarted(Element el) throws InvalidXMLException {
return parseMatchPhaseFilter("started", el);
}

@MethodParser("match-running")
public Filter parseMatchRunning(Element el) throws InvalidXMLException {
return parseMatchPhaseFilter("running", el);
}

@MethodParser("match-finished")
public Filter parseMatchFinished(Element el) throws InvalidXMLException {
return parseMatchPhaseFilter("finished", el);
}

private Filter parseMatchPhaseFilter(String matchState, Element el) throws InvalidXMLException {

switch (matchState) {
case "running":
return MatchPhaseFilter.RUNNING;
case "finished":
return MatchPhaseFilter.FINISHED;
case "starting":
return MatchPhaseFilter.STARTING;
case "idle":
return MatchPhaseFilter.IDLE;
case "started":
return MatchPhaseFilter.STARTED;
}

throw new InvalidXMLException("Invalid or no match state found", el);
}

// Methods for parsing QueryModifiers

@MethodParser("offset")
Expand Down
33 changes: 33 additions & 0 deletions core/src/main/java/tc/oc/pgm/filters/MatchPhaseFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package tc.oc.pgm.filters;

import tc.oc.pgm.api.filter.Filter;
import tc.oc.pgm.api.filter.query.MatchQuery;
import tc.oc.pgm.api.match.MatchPhase;

public class MatchPhaseFilter extends TypedFilter<MatchQuery> {

public static final MatchPhaseFilter RUNNING = new MatchPhaseFilter(MatchPhase.RUNNING);
public static final MatchPhaseFilter FINISHED = new MatchPhaseFilter(MatchPhase.FINISHED);
public static final MatchPhaseFilter STARTING = new MatchPhaseFilter(MatchPhase.STARTING);
public static final MatchPhaseFilter IDLE = new MatchPhaseFilter(MatchPhase.IDLE);
public static final Filter STARTED =
AnyFilter.of(
new MatchPhaseFilter(MatchPhase.RUNNING), new MatchPhaseFilter(MatchPhase.FINISHED));

private final MatchPhase matchPhase;

public MatchPhaseFilter(MatchPhase matchPhase) {
this.matchPhase = matchPhase;
}

@Override
public Class<? extends MatchQuery> getQueryType() {
return MatchQuery.class;
}

@Override
protected QueryResponse queryTyped(MatchQuery query) {
MatchPhase current = query.getMatch().getPhase();
return QueryResponse.fromBoolean(matchPhase == current);
}
}