Search in sources :

Example 6 with Operations

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;
}
Also used : ArrayList(java.util.ArrayList) Operation(uk.gov.gchq.gaffer.operation.Operation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operations(uk.gov.gchq.gaffer.operation.Operations) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)6 Operations (uk.gov.gchq.gaffer.operation.Operations)6 ArrayList (java.util.ArrayList)5 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)4 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)2 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Collections (java.util.Collections)1 List (java.util.List)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 CollectionUtils.isEmpty (org.apache.commons.collections.CollectionUtils.isEmpty)1