/// <summary> /// Tries to return the operator which applies for the given inputs /// </summary> /// <param name="type">Operator Type</param> /// <param name="op">Operator</param> /// <param name="ns">Inputs</param> /// <returns></returns> public static bool TryGetOperator(SparqlOperatorType type, out ISparqlOperator op, params IValuedNode[] ns) { if (!_init) { Init(); } op = null; List <ISparqlOperator> ops; lock (_operators) { if (_operators.TryGetValue(type, out ops)) { foreach (ISparqlOperator possOp in ops) { if (possOp.IsApplicable(ns)) { op = possOp; return(true); } } return(false); } else { return(false); } } }
private void TestApplication(SparqlOperatorType opType, IEnumerable <IValuedNode> ns, IValuedNode expected, bool shouldFail) { ISparqlOperator op = null; if (SparqlOperators.TryGetOperator(opType, out op, ns.ToArray())) { IValuedNode actual; try { actual = op.Apply(ns.ToArray()); } catch (Exception ex) { if (shouldFail) { return; } throw; } Assert.AreEqual(expected, actual); } else { if (!shouldFail) { Assert.Fail("Expected to be able to select an operator to apply to the inputs"); } } }
/// <summary> /// Gets all registered operators for the given Operator Type /// </summary> /// <param name="type">Operator Type</param> /// <returns></returns> public static IEnumerable <ISparqlOperator> GetOperators(SparqlOperatorType type) { if (!_init) { Init(); } lock (_operators) { return(_operators[type].ToList()); } }
private void TestStrictLookup(SparqlOperatorType opType, Type returnedOpInstanceType, IEnumerable <IValuedNode> ns, bool opExists) { try { Options.StrictOperators = true; this.TestLookup(opType, returnedOpInstanceType, ns, opExists); } finally { Options.StrictOperators = false; } }
private void TestStrictApplication(SparqlOperatorType opType, IEnumerable <IValuedNode> ns, IValuedNode expected, bool shouldFail) { try { Options.StrictOperators = true; this.TestApplication(opType, ns, expected, shouldFail); } finally { Options.StrictOperators = false; } }
private void TestLookup(SparqlOperatorType opType, Type returnedOpInstanceType, IEnumerable <IValuedNode> ns, bool opExists) { ISparqlOperator op = null; if (SparqlOperators.TryGetOperator(opType, out op, ns.ToArray())) { Assert.True(opExists, "Operator returned when no operator was expected for the given inputs"); Assert.Equal(returnedOpInstanceType, op.GetType()); } else { Assert.False(opExists, "No Operator returned when an operator was expected for the given inputs"); } }