use of uk.gov.gchq.gaffer.operation.Operations in project Gaffer by gchq.
the class DefaultScoreResolver method getScore.
@Override
public Integer getScore(final Operation operation) {
if (null == operation) {
return 0;
}
// Named operations should use their custom resolver despite implementing Operations
if (operation instanceof Operations && !(operation instanceof NamedOperation)) {
int score = 0;
for (final Operation op : ((Operations<?>) operation).getOperations()) {
score += getScore(op);
}
return score;
} else {
final Class<? extends Operation> opClass = operation.getClass();
// Check the operation is not the same instance
if (null == skipResolvingOperation || skipResolvingOperation != operation) {
ScoreResolver resolver = scoreResolvers.get(opClass);
if (null != resolver) {
// Create a delegate resolver with the current resolver skipped to prevent an infinite loop
final DefaultScoreResolver delegateResolver = new DefaultScoreResolver(opScores, scoreResolvers, operation);
Integer opScore = resolver.getScore(operation, delegateResolver);
if (null != opScore) {
return opScore;
}
}
}
// Use the operation scores map to get the score.
final List<Class<? extends Operation>> keys = new ArrayList<>(opScores.keySet());
for (int i = keys.size() - 1; i >= 0; i--) {
final Class<? extends Operation> key = keys.get(i);
if (key.isAssignableFrom(opClass)) {
return opScores.get(key);
}
}
}
return DEFAULT_OPERATION_SCORE;
}
Aggregations