Move match() and matchOrNull() to MatchCache
It was a bit weird to have these on the PredicateCache, only to be
effectively mirrored in MatchCache, move them to MatchCache to simplify
the code and make it a bit more intuitive.
Change-Id: I6c97569948c675d366ae576e2b633f4a9ccbee7c
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/MatchCache.java b/src/main/java/com/googlesource/gerrit/plugins/task/MatchCache.java
index 53c41e1..f802720 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/MatchCache.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/MatchCache.java
@@ -31,25 +31,28 @@
this.changeData = changeData;
}
- protected boolean match(String query) throws OrmException, QueryParseException {
+ public boolean match(String query) throws OrmException, QueryParseException {
if (query == null) {
return true;
}
Boolean isMatched = matchResultByQuery.get(query);
if (isMatched == null) {
- isMatched = predicateCache.match(changeData, query);
+ isMatched = predicateCache.matchWithExceptions(changeData, query);
matchResultByQuery.put(query, isMatched);
}
return isMatched;
}
- protected Boolean matchOrNull(String query) {
+ public Boolean matchOrNull(String query) {
if (query == null) {
return null;
}
Boolean isMatched = matchResultByQuery.get(query);
if (isMatched == null) {
- isMatched = predicateCache.matchOrNull(changeData, query);
+ try {
+ isMatched = predicateCache.matchWithExceptions(changeData, query);
+ } catch (OrmException | QueryParseException | RuntimeException e) {
+ }
matchResultByQuery.put(query, isMatched);
}
return isMatched;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/PredicateCache.java b/src/main/java/com/googlesource/gerrit/plugins/task/PredicateCache.java
index f6d6259..4da59e4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/PredicateCache.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/PredicateCache.java
@@ -60,24 +60,7 @@
config.getStringList(pluginName, "cacheable-predicates", "byBranch-className")));
}
- public boolean match(ChangeData c, String query) throws OrmException, QueryParseException {
- if (query == null) {
- return true;
- }
- return matchWithExceptions(c, query);
- }
-
- public Boolean matchOrNull(ChangeData c, String query) {
- if (query != null) {
- try {
- return matchWithExceptions(c, query);
- } catch (OrmException | QueryParseException | RuntimeException e) {
- }
- }
- return null;
- }
-
- protected boolean matchWithExceptions(ChangeData c, String query)
+ public boolean matchWithExceptions(ChangeData c, String query)
throws QueryParseException, OrmException {
if ("true".equalsIgnoreCase(query)) {
return true;