Package com.hp.jena.rules.functions.jena2

Source Code of com.hp.jena.rules.functions.jena2.Min

/**
*
*/
package com.hp.jena.rules.functions.jena2;

import java.util.List;

import com.hp.jena.graph.Node;
import com.hp.jena.rules.functions.ApplyableBase;
import com.hp.jena.rules.retelike.impl.Bindings;
import com.hp.jena.rules.retelike.impl.ExecContext;

public class Min extends ApplyableBase
    {
    protected final Node A, B, min;
   
    public Min( List<Node> nargs )
        { A = nargs.get( 0 ); B = nargs.get( 1 ); min = nargs.get( 2 ); }
   
    @Override public boolean evalBool( ExecContext c, Bindings<Node, Node> item )
        {
        Node av = eval( item, A ), bv = eval( item, B );
        if (av.isLiteral() && bv.isLiteral())
            {
            Object va = av.getLiteralValue();
            Object vb = bv.getLiteralValue();
            if (va instanceof Number && vb instanceof Number)
                return ApplyableBase.bind( item, min, minOf( av, bv ) );
            else
                return false;
            }
        else
            return false;
        }
   
    private Node minOf( Node va, Node vb )
        {
        Number na = (Number) va.getLiteralValue();
        Number nb = (Number) vb.getLiteralValue();
        Node res =
            (na instanceof Float || na instanceof Double
            || nb instanceof Float || nb instanceof Double
            )
            ? na.doubleValue() > nb.doubleValue() ? va : vb
            : na.longValue() > nb.longValue() ? va : vb
            ;
        return res;
        }
   
    }
TOP

Related Classes of com.hp.jena.rules.functions.jena2.Min

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.