Java Code Examples for org.eclipse.rdf4j.query.impl.MapBindingSet#getValue()

The following examples show how to use org.eclipse.rdf4j.query.impl.MapBindingSet#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinFunction.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public void update(final AggregationElement aggregation, final AggregationState state, final VisibilityBindingSet childBindingSet) {
    checkArgument(aggregation.getAggregationType() == AggregationType.MIN, "The MinFunction only accepts MIN AggregationElements.");
    requireNonNull(state);
    requireNonNull(childBindingSet);

    // Only update the min if the child contains the binding that we are finding the min value for.
    final String aggregatedName = aggregation.getAggregatedBindingName();
    if(childBindingSet.hasBinding(aggregatedName)) {
        final MapBindingSet result = state.getBindingSet();
        final String resultName = aggregation.getResultBindingName();
        final boolean newBinding = !result.hasBinding(resultName);

        Value min;
        if(newBinding) {
            min = childBindingSet.getValue(aggregatedName);
        } else {
            final Value oldMin = result.getValue(resultName);
            final Value chidlMin = childBindingSet.getValue(aggregatedName);
            min = compare.compare(chidlMin, oldMin) < 0 ? chidlMin : oldMin;
        }

        result.addBinding(resultName, min);
    }
}
 
Example 2
Source File: MaxFunction.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public void update(final AggregationElement aggregation, final AggregationState state, final VisibilityBindingSet childBindingSet) {
    checkArgument(aggregation.getAggregationType() == AggregationType.MAX, "The MaxFunction only accepts MAX AggregationElements.");
    requireNonNull(state);
    requireNonNull(childBindingSet);

    // Only update the max if the child contains the binding that we are finding the max value for.
    final String aggregatedName = aggregation.getAggregatedBindingName();
    if(childBindingSet.hasBinding(aggregatedName)) {
        final MapBindingSet result = state.getBindingSet();
        final String resultName = aggregation.getResultBindingName();
        final boolean newBinding = !result.hasBinding(resultName);

        Value max;
        if(newBinding) {
            max = childBindingSet.getValue(aggregatedName);
        } else {
            final Value oldMax = result.getValue(resultName);
            final Value childMax = childBindingSet.getValue(aggregatedName);
            max = compare.compare(childMax, oldMax) > 0 ? childMax : oldMax;
        }

        result.addBinding(resultName, max);
    }
}
 
Example 3
Source File: CountFunction.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public void update(final AggregationElement aggregation, final AggregationState state, final VisibilityBindingSet childBindingSet) {
    checkArgument(aggregation.getAggregationType() == AggregationType.COUNT, "The CountFunction only accepts COUNT AggregationElements.");
    requireNonNull(state);
    requireNonNull(childBindingSet);

    // Only add one to the count if the child contains the binding that we are counting.
    final String aggregatedName = aggregation.getAggregatedBindingName();
    if(childBindingSet.hasBinding(aggregatedName)) {
        final MapBindingSet result = state.getBindingSet();
        final String resultName = aggregation.getResultBindingName();
        final boolean newBinding = !result.hasBinding(resultName);

        if(newBinding) {
            // Initialize the binding.
            result.addBinding(resultName, VF.createLiteral(BigInteger.ONE));
        } else {
            // Update the existing binding.
            final Literal count = (Literal) result.getValue(resultName);
            final BigInteger updatedCount = count.integerValue().add( BigInteger.ONE );
            result.addBinding(resultName, VF.createLiteral(updatedCount));
        }
    }
}