1 6 7 package com.hp.hpl.jena.graph.query.test; 8 9 import java.util.List ; 10 11 import com.hp.hpl.jena.graph.Node; 12 import com.hp.hpl.jena.graph.query.*; 13 import com.hp.hpl.jena.graph.test.GraphTestBase; 14 import com.hp.hpl.jena.util.iterator.Map1; 15 16 22 public abstract class QueryTestBase extends GraphTestBase 23 { 24 public QueryTestBase( String name ) 25 { super( name ); } 26 27 31 protected Expression notEqual( Node x, Node y ) 32 { 33 return new Dyadic( asExpression( x ), "http://jena.hpl.hp.com/constraints/NE", asExpression( y ) ) 34 { 35 public boolean evalBool( Object x, Object y ) 36 { return !x.equals( y ); } 37 }; 38 } 39 40 44 protected Expression areEqual( Node x, Node y ) 45 { 46 return new Dyadic( asExpression( x ), "http://jena.hpl.hp.com/constraints/EQ", asExpression( y ) ) 47 { 48 public boolean evalBool( Object x, Object y ) 49 { return x.equals( y ); } 50 }; 51 } 52 53 58 protected Expression matches( Node x, Node y ) 59 { 60 return new Dyadic( asExpression( x ), "http://jena.hpl.hp.com/constraints/MATCHES", asExpression( y ) ) 61 { 62 public boolean evalBool( Object L, Object R ) 63 { 64 Node l = (Node) L, r = (Node) R; 65 return l.toString( false ).indexOf( r.toString( false ) ) > -1; 66 } 67 }; 68 } 69 70 75 public static Expression asExpression( final Node x ) 76 { 77 if( x.isVariable()) return new Expression.Variable() 78 { 79 public String getName() 80 { return x.getName(); } 81 82 public Valuator prepare( VariableIndexes vi ) 83 { return new SlotValuator( vi.indexOf( x.getName() ) ); } 84 }; 85 return new Expression.Fixed( x ); 86 } 87 88 92 protected static Map1 getFirst = new Map1() 93 { public Object map1( Object x ) { return ((List ) x).get(0); } }; 94 95 98 protected static final IndexValues noIVs = new IndexValues() 99 { public Object get( int i ) { return null; } }; 100 101 104 protected static final Mapping emptyMapping = new Mapping( new Node[0] ); 105 106 110 protected VariableIndexes noVariables = new VariableIndexes() 111 { public int indexOf( String name ) { return -1; } }; 112 113 116 protected static final Node X = Query.X; 117 118 121 protected static final Node Y = Query.Y; 122 123 126 protected static final Node Z = Query.Z; 127 128 131 protected static final Node ANY = Node.ANY; 132 133 136 protected final Node [] justX = new Node [] {X}; 137 } 138 139 140 | Popular Tags |