1 6 package com.hp.hpl.jena.graph.query; 7 8 import com.hp.hpl.jena.graph.query.Expression.Application; 9 import com.hp.hpl.jena.shared.JenaException; 10 11 18 public abstract class Dyadic extends Application 19 { 20 protected Expression L; 21 protected Expression R; 22 protected String F; 23 24 public Dyadic( Expression L, String F, Expression R ) 25 { 26 this.L = L; 27 this.F = F; 28 this.R = R; 29 } 30 31 public int argCount() 32 { return 2; } 33 34 public Expression getArg( int i ) 35 { return i == 0 ? L : R; } 36 37 public String getFun() 38 { return F; } 39 40 46 public Object evalObject( Object l, Object r ) 47 { return evalBool( l, r ) ? Boolean.TRUE : Boolean.FALSE; } 48 49 55 public boolean evalBool( Object l, Object r ) 56 { Object x = evalObject( l, r ); 57 if (x instanceof Boolean ) return ((Boolean ) x).booleanValue(); 58 throw new JenaException( "not Boolean: " + x ); 59 } 60 61 public Valuator prepare( VariableIndexes vi ) 62 { 63 final Valuator l = L.prepare( vi ), r = R.prepare( vi ); 64 return new Valuator() 65 { 66 public boolean evalBool( IndexValues iv) 67 { 68 return ((Boolean ) evalObject( iv )).booleanValue(); 69 } 70 71 public Object evalObject( IndexValues iv ) 72 { 73 return Dyadic.this.evalObject( l.evalObject( iv ), r.evalObject( iv ) ); 74 } 75 76 }; 77 } 78 79 public String toString() 80 { return L.toString() + " " + F + " " + R.toString(); } 81 82 public static Expression and( Expression L, Expression R ) 83 { 84 return new Dyadic( L, ExpressionFunctionURIs.AND, R ) 85 { 86 public boolean evalBool( Object x, Object y ) 87 { return ((Boolean ) x).booleanValue() && ((Boolean ) y).booleanValue(); } 88 }; 89 } 90 } 91 92 | Popular Tags |