/// <summary> /// Mathematical multiplication between this duration stored and the supplied /// duration of time (of type XSYearMonthDuration) /// </summary> /// <param name="arg"> /// The duration of time to multiply by </param> /// <returns> New XSYearMonthDuration representing the resulting duration /// after the multiplication </returns> /// <exception cref="DynamicError"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence times(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual ResultSequence times(ResultSequence arg) { ResultSequence convertedRS = arg; if (arg.size() == 1) { Item argValue = arg.first(); if (argValue is XSDecimal) { convertedRS = ResultSequenceFactory.create_new(new XSDouble(argValue.StringValue)); } } XSDouble val = (XSDouble)NumericType.get_single_type(convertedRS, typeof(XSDouble)); if (val.nan()) { throw DynamicError.nan(); } if (val.infinite()) { throw DynamicError.overflowDateTime(); } int res = (int)Math.Round(monthValue() * val.double_value()); return(ResultSequenceFactory.create_new(new XSYearMonthDuration(res))); }
/// <summary> /// Unary operation on the arguments. /// </summary> /// <param name="args"> /// input arguments. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of the operation. </returns> public static ResultSequence fs_plus_unary(ICollection args) { // make sure we got only one arg if (args.Count != 1) { DynamicError.throw_type_error(); } var i = args.GetEnumerator(); i.MoveNext(); ResultSequence arg = (ResultSequence)i.Current; // make sure we got only one numeric atom if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); if (!(at is NumericType)) { DynamicError.throw_type_error(); } // no-op return(arg); }
/// <summary> /// Converts arguments to values. /// </summary> /// <param name="args"> /// Result from expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of conversion. </returns> private static ICollection value_convert_args(ICollection args) { var result = new ArrayList(args.Count); // atomize arguments for (IEnumerator i = args.GetEnumerator(); i.MoveNext();) { ResultSequence rs = (ResultSequence)i.Current; //FnData.fast_atomize(rs); rs = FnData.atomize(rs); if (rs.empty()) { return(new ArrayList()); } if (rs.size() > 1) { throw new DynamicError(TypeError.invalid_type(null)); } Item arg = rs.first(); if (arg is XSUntypedAtomic) { arg = new XSString(arg.StringValue); } result.Add(arg); } return(result); }
/// <summary> /// Deep-Equal boolean operation. /// </summary> /// <param name="one"> /// input1 xpath expression/variable. </param> /// <param name="two"> /// input2 xpath expression/variable. </param> /// <param name="context"> /// Current dynamic context </param> /// <returns> Result of fn:deep-equal operation. </returns> public static bool deep_equal(ResultSequence one, ResultSequence two, EvaluationContext context, string collationURI) { if (one.empty() && two.empty()) { return(true); } if (one.size() != two.size()) { return(false); } var onei = one.iterator(); var twoi = two.iterator(); while (onei.MoveNext()) { AnyType a = (AnyType)onei.Current; twoi.MoveNext(); AnyType b = (AnyType)twoi.Current; if (!deep_equal(a, b, context, collationURI)) { return(false); } } return(true); }
/// <summary> /// Mathematical subtraction between this time stored and the supplied /// representation. This supplied representation must be of either type /// XSTime (in which case the result is the duration of time between these /// two times) or a XSDayTimeDuration (in which case the result is the time /// when this duration is subtracted from the time stored). /// </summary> /// <param name="arg"> /// The representation to subtract (either XSTim or /// XDTDayTimeDuration) </param> /// <returns> A ResultSequence representing the result of the subtraction </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence minus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual ResultSequence minus(ResultSequence arg) { if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); if (!(at is XSTime) && !(at is XSDayTimeDuration)) { throw DynamicError.throw_type_error(); } if (at is XSTime) { return(minusXSTimeDuration(at)); } if (at is XSDayTimeDuration) { return(minusXSDayTimeDuration(at)); } return(null); // unreach }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void considerSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence sequenceToConsider) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual void considerSequence(ResultSequence sequenceToConsider) { for (int i = 0; i < sequenceToConsider.size(); ++i) { Item item = sequenceToConsider.item(i); considerValue(item); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected org.eclipse.wst.xml.xpath2.api.Item get_single_arg(org.eclipse.wst.xml.xpath2.api.ResultSequence rs) throws org.eclipse.wst.xml.xpath2.processor.DynamicError protected internal virtual Item get_single_arg(ResultSequence rs) { if (rs.size() != 1) { DynamicError.throw_type_error(); } return(rs.first()); }
// voodoo 2 /// <summary> /// Actual equality operation for fs_eq_value. /// </summary> /// <param name="args"> /// input arguments. </param> /// <param name="type"> /// type of the arguments. </param> /// <param name="mname"> /// Method name for template simulation. </param> /// <param name="dynamicContext"> /// Dynamic error. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of the operation. </returns> public static ResultSequence do_cmp_value_op(ICollection args, Type type, string mname, DynamicContext context) { // sanity check args + convert em if (args.Count != 2) { DynamicError.throw_type_error(); } ICollection cargs = value_convert_args(args); if (cargs.Count == 0) { return(ResultBuffer.EMPTY); } // make sure arugments are comparable by equality IEnumerator argi = cargs.GetEnumerator(); argi.MoveNext(); Item arg = ((ResultSequence)argi.Current).first(); argi.MoveNext(); ResultSequence arg2 = (ResultSequence)argi.Current; if (arg2.size() != 1) { DynamicError.throw_type_error(); } if (!(type.IsInstanceOfType(arg))) { DynamicError.throw_type_error(); } try { Type[] margsdef = new Type[] { type }; Type[] margsdef2 = new Type[] { typeof(AnyType), typeof(DynamicContext) }; object[] margs3 = new object[] { mname, margsdef2 }; var v1 = typeof(GenericIComparer) .GetMethod("GetComparer"); var v2 = v1.MakeGenericMethod(margsdef); var method = (MethodBase)v2.Invoke(null, margs3); object[] margs = new object[] { arg2.first(), context }; object[] real_args = new object[] { arg, margs }; bool cmpres = (bool)method.Invoke(arg, margs); return(ResultSequenceFactory.create_new(new XSBoolean(cmpres))); } catch { Debug.Assert(false); throw new Exception("cannot compare using method " + mname); } }
/// <summary> /// Mathematical addition operator between this XSDate and a supplied result /// sequence (XDTYearMonthDuration and XDTDayTimeDuration are only valid /// ones). /// </summary> /// <param name="arg"> /// The supplied ResultSequence that is on the right of the minus /// operator. If arg is an XDTYearMonthDuration or an /// XDTDayTimeDuration the result will be a XSDate of the result /// of the current date minus the duration of time supplied. </param> /// <returns> New ResultSequence consisting of the result of the mathematical /// minus operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence plus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual ResultSequence plus(ResultSequence arg) { if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); try { if (at is XSYearMonthDuration) { XSYearMonthDuration val = (XSYearMonthDuration)at; XSDate res = (XSDate)clone(); res.calendar().add(Calendar.MONTH, val.monthValue()); return(ResultSequenceFactory.create_new(res)); } else if (at is XSDayTimeDuration) { XSDayTimeDuration val = (XSDayTimeDuration)at; XSDate res = (XSDate)clone(); // We only need to add the Number of days dropping the rest. int days = val.days(); if (val.negative()) { days *= -1; } res.calendar().add(Calendar.DAY_OF_MONTH, days); res.calendar().add(Calendar.MILLISECOND, (int)(val.time_value() * 1000.0)); return(ResultSequenceFactory.create_new(res)); } else { DynamicError.throw_type_error(); return(null); // unreach } } catch { Debug.Assert(false); return(null); } }
/// <summary> /// Mathematical division between this duration stored and the supplied /// duration of time (of type XSYearMonthDuration) /// </summary> /// <param name="arg"> /// The duration of time to divide by </param> /// <returns> New XSYearMonthDuration representing the resulting duration /// after the division </returns> /// <exception cref="DynamicError"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence div(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual ResultSequence div(ResultSequence arg) { if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); if (at is XSDouble) { XSDouble dt = (XSDouble)at; int ret = 0; if (!dt.zero()) { ret = (int)Math.Round(monthValue() / dt.double_value()); } return(ResultSequenceFactory.create_new(new XSYearMonthDuration(ret))); } else if (at is XSDecimal) { XSDecimal dt = (XSDecimal)at; int ret = 0; if (!dt.zero()) { ret = (int)Math.Round(monthValue() / dt.Value); } return(ResultSequenceFactory.create_new(new XSYearMonthDuration(ret))); } else if (at is XSYearMonthDuration) { XSYearMonthDuration md = (XSYearMonthDuration)at; double res = (double)monthValue() / md.monthValue(); return(ResultSequenceFactory.create_new(new XSDecimal(new decimal(res)))); } else { DynamicError.throw_type_error(); return(null); // unreach } }
/// <summary> /// Reverse the arguments. /// </summary> /// <param name="args"> /// are reversed. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> The result of the reversal of the arguments. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence reverse(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence reverse(ICollection args) { Debug.Assert(args.Count == 1); // get args IEnumerator citer = args.GetEnumerator(); citer.MoveNext(); ResultSequence arg = (ResultSequence)citer.Current; if (arg.size() <= 1) { return(arg); } ResultBuffer rs = new ResultBuffer(); for (int i = arg.size() - 1; i >= 0; --i) { rs.add(arg.item(i)); } return(rs.Sequence); }
/// <summary> ///* /// Check whether first node in supplied ResultSequence is of the supplied /// type /// </summary> /// <param name="rs"> /// The node being tested </param> /// <param name="type"> /// The type expected </param> /// <returns> The node being tested </returns> /// <exception cref="DynamicError"> /// If node being tested is not of expected type </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static AnyType get_single_type(org.eclipse.wst.xml.xpath2.api.ResultSequence rs, Class type) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static AnyType get_single_type(ResultSequence rs, Type type) { if (rs.size() != 1) { DynamicError.throw_type_error(); } Item at = rs.first(); if (!type.IsInstanceOfType(at)) { DynamicError.throw_type_error(); } return((AnyType)at); }
// XXX IN GENRAL, I THIUNK WE NEED TO PULL SANITY CHECKING OUTSIDE! // PLUS I AM NOT ATOMIZING/ETC ETC HERE!!! BAD CODE // BUG XXX HACK DEATH /// <summary> /// Evaluate arguments. /// </summary> /// <param name="args"> /// argument expressions. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of evaluation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence evaluate(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public override ResultSequence evaluate(ICollection args, EvaluationContext ec) { Debug.Assert(args.Count >= min_arity() && args.Count <= max_arity()); var i = args.GetEnumerator(); i.MoveNext(); // sanity checks ResultSequence arg = (ResultSequence)i.Current; if (arg == null || arg.size() > 1) { DynamicError.throw_type_error(); } // do it return(_atomic_type.constructor(arg)); }
/// <summary> /// Exactly-one operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:exactly-one operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence exactly_one(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence exactly_one(ICollection args) { Debug.Assert(args.Count == 1); // get args IEnumerator citer = args.GetEnumerator(); citer.MoveNext(); ResultSequence arg = (ResultSequence)citer.Current; if (arg == null || arg.size() != 1) { throw DynamicError.not_one(null); } return(arg); }
/// <summary> /// Mathematical addition operator between this XSDateTime and a supplied /// result sequence (XDTYearMonthDuration and XDTDayTimeDuration are only /// valid ones). /// </summary> /// <param name="arg"> /// The supplied ResultSequence that is on the right of the minus /// operator. If arg is an XDTYearMonthDuration or an /// XDTDayTimeDuration the result will be a XSDateTime of the /// result of the current date minus the duration of time /// supplied. </param> /// <returns> New ResultSequence consisting of the result of the mathematical /// minus operation. </returns> public virtual ResultSequence plus(ResultSequence arg) { if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); try { if (at is XSYearMonthDuration) { XSYearMonthDuration val = (XSYearMonthDuration)at; XSDateTime res = (XSDateTime)clone(); res.calendar().add(Calendar.MONTH, val.monthValue()); return(ResultSequenceFactory.create_new(res)); } else if (at is XSDayTimeDuration) { XSDuration val = (XSDuration)at; XSDateTime res = (XSDateTime)clone(); XMLGregorianCalendar xmlCal = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)calendar()); Duration dtduration = _datatypeFactory.newDuration(val.StringValue); xmlCal.add(dtduration); res = new XSDateTime(xmlCal.toGregorianCalendar(), res.tz()); return(ResultSequenceFactory.create_new(res)); } else { DynamicError.throw_type_error(); return(null); // unreach } } catch { Debug.Assert(false); return(null); } }
/// <summary> /// Concatenate the arguments. /// </summary> /// <param name="args"> /// are concatenated. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> The result of the concatenation of the arguments. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence concat(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence concat(ICollection args) { // sanity check if (args.Count < 2) { DynamicError.throw_type_error(); } ResultBuffer rs = new ResultBuffer(); string result = ""; // go through args StringBuilder buf = new StringBuilder(); for (IEnumerator argi = args.GetEnumerator(); argi.MoveNext();) { ResultSequence arg = (ResultSequence)argi.Current; int size = arg.size(); // sanity check if (size > 1) { DynamicError.throw_type_error(); } if (size == 0) { continue; } Item at = arg.first(); buf.Append(at.StringValue); } result = buf.ToString(); rs.add(new XSString(result)); return(rs.Sequence); }
/// <summary> /// Codepoints to string operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:codepoints-to-string operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence codepoints_to_string(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence codepoints_to_string(ICollection args) { ICollection cargs = Function.convert_arguments(args, expected_args()); var j = cargs.GetEnumerator(); j.MoveNext(); ResultSequence arg1 = (ResultSequence)j.Current; if (arg1 == null || arg1.empty()) { return(new XSString("")); } int[] codePointArray = new int[arg1.size()]; int codePointIndex = 0; for (var i = arg1.iterator(); i.MoveNext();) { XSInteger code = (XSInteger)i.Current; int codepoint = (int)code.int_value(); if (codepoint < MIN_LEGAL_CODEPOINT || codepoint > MAX_LEGAL_CODEPOINT) { throw DynamicError.unsupported_codepoint("U+" + Convert.ToString(codepoint, 16).ToUpper()); } codePointArray[codePointIndex] = codepoint; codePointIndex++; } try { var c = codePointArray.Select(x => (char)x).ToArray(); string str = new string(c); return(new XSString(str)); } catch (System.ArgumentException iae) { // This should be duoble checked above, but rather safe than sorry throw DynamicError.unsupported_codepoint(iae.Message); } }
/// <summary> /// Trace operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:trace operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence trace(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence trace(ICollection args) { // sanity check args if (args.Count != 2) { DynamicError.throw_type_error(); } IEnumerator argsi = args.GetEnumerator(); argsi.MoveNext(); ResultSequence arg1 = (ResultSequence)argsi.Current; argsi.MoveNext(); ResultSequence arg2 = (ResultSequence)argsi.Current; if (arg2 == null || arg2.size() != 1) { DynamicError.throw_type_error(); } Item at = arg2.first(); if (!(at is XSString)) { DynamicError.throw_type_error(); } XSString label = (XSString)at; int index = 1; for (var i = arg1.iterator(); i.MoveNext(); index++) { at = (AnyType)i.Current; Console.WriteLine(label.value() + " [" + index + "] " + ((AnyType)at).string_type() + ":" + at.StringValue); } return(arg1); }
/// <summary> /// String operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:string operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence string(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence @string(ICollection args, EvaluationContext ec) { Debug.Assert(args.Count == 0 || args.Count == 1); ResultSequence arg1 = null; if (args.Count == 0) { // support for arity = 0 return(getResultSetForArityZero(ec)); } else { var i = args.GetEnumerator(); i.MoveNext(); arg1 = (ResultSequence)i.Current; } // sanity check args if (arg1.size() > 1) { throw new DynamicError(TypeError.invalid_type(null)); } ResultBuffer rs = new ResultBuffer(); if (arg1.empty()) { rs.add(new XSString("")); } else { Item at = arg1.first(); rs.add(new XSString(at.StringValue)); } return(rs.Sequence); }
/// <summary> /// Evaluate arguments. /// </summary> /// <param name="args"> /// argument expressions. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of evaluation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence evaluate(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public override ResultSequence evaluate(ICollection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) { IEnumerator argIterator = args.GetEnumerator(); argIterator.MoveNext(); ResultSequence argSequence = (ResultSequence)argIterator.Current; AnyAtomicType zero = ZERO; if (argIterator.MoveNext()) { ResultSequence zeroSequence = (ResultSequence)argIterator.Current; if (zeroSequence.size() != 1) { throw new DynamicError(TypeError.invalid_type(null)); } if (!(zeroSequence.first() is AnyAtomicType)) { throw new DynamicError(TypeError.invalid_type(zeroSequence.first().StringValue)); } zero = (AnyAtomicType)zeroSequence.first(); } return(sum(argSequence, zero)); }
/// <summary> /// Mathematical multiplication between this duration stored and the supplied /// duration of time (of type XSDayTimeDuration) /// </summary> /// <param name="arg"> /// The duration of time to multiply by </param> /// <returns> New XSDayTimeDuration representing the resulting duration after /// the multiplication </returns> /// <exception cref="DynamicError"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence times(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual ResultSequence times(ResultSequence arg) { ResultSequence convertedRS = arg; if (arg.size() == 1) { Item argValue = arg.first(); if (argValue is XSDecimal) { convertedRS = ResultSequenceFactory.create_new(new XSDouble(argValue.StringValue)); } } XSDouble val = (XSDouble)NumericType.get_single_type(convertedRS, typeof(XSDouble)); if (val.nan()) { throw DynamicError.nan(); } double res = value() * val.double_value(); return(ResultSequenceFactory.create_new(new XSDayTimeDuration(res))); }
/// <summary> /// Obtain numeric value from expression. /// </summary> /// <param name="arg"> /// input expression. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Resulting numeric type from the operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType get_single_numeric_arg(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static NumericType get_single_numeric_arg(ResultSequence arg) { int size = arg.size(); if (size > 1) { DynamicError.throw_type_error(); } if (size == 0) { return(null); } arg = FnData.atomize(arg); AnyType at = (AnyType)arg.item(0); if (!(at is NumericType)) { throw DynamicError.invalidType(); } return((NumericType)at); }
/// <summary> /// Convert and promote arguments for operation. /// </summary> /// <param name="args"> /// input arguments. </param> /// <param name="sc"> </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of conversion. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static java.util.Collection convert_args(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError private static ICollection convert_args(ICollection args) { var result = new ArrayList(); // Keep track of numeric types for promotion bool has_float = false; bool has_double = false; // atomize arguments for (IEnumerator i = args.GetEnumerator(); i.MoveNext();) { ResultSequence rs = FnData.atomize((ResultSequence)i.Current); if (rs.empty()) { return(new ArrayList()); } if (rs.size() > 1) { throw new DynamicError(TypeError.invalid_type(null)); } AnyType arg = (AnyType)rs.item(0); if (arg is XSUntypedAtomic) { arg = new XSDouble(arg.StringValue); } if (arg is XSDouble) { has_double = true; } if (arg is XSFloat) { has_float = true; } result.Add(ResultBuffer.wrap(arg)); } if (has_double) { has_float = false; } if (has_double || has_float) { var result2 = new ArrayList(); // promote arguments for (IEnumerator i = result.GetEnumerator(); i.MoveNext();) { ResultSequence rs = (ResultSequence)i.Current; Item arg = rs.item(0); if (has_double && (arg is XSFloat)) { arg = new XSDouble(((XSFloat)arg).float_value()); } else if (has_double && (arg is XSDecimal)) { arg = new XSDouble(((XSDecimal)arg).double_value()); } else if (has_float && (arg is XSDecimal)) { arg = new XSFloat((float)((XSDecimal)arg).double_value()); } result2.Add(arg); } return(result2); } return(result); }
/// <summary> /// Insert-Before operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:insert-before operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence insert_before(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence insert_before(ICollection args) { Debug.Assert(args.Count == 3); ResultBuffer rs = new ResultBuffer(); // get args IEnumerator citer = args.GetEnumerator(); citer.MoveNext(); ResultSequence target = (ResultSequence)citer.Current; citer.MoveNext(); ResultSequence arg2 = (ResultSequence)citer.Current; citer.MoveNext(); ResultSequence inserts = (ResultSequence)citer.Current; // sanity chex if (arg2.size() != 1) { DynamicError.throw_type_error(); } Item at = arg2.first(); if (!(at is XSInteger)) { DynamicError.throw_type_error(); } // XXX cloning! if (target.empty()) { return(inserts); } if (inserts.empty()) { return(target); } int position = (int)((XSInteger)at).int_value(); if (position < 1) { position = 1; } int target_size = target.size(); if (position > target_size) { position = target_size + 1; } int curpos = 1; for (var i = target.iterator(); i.MoveNext();) { at = (AnyType)i.Current; if (curpos == position) { rs.concat(inserts); } rs.add(at); curpos++; } if (curpos == position) { rs.concat(inserts); } return(rs.Sequence); }
/// <returns> size </returns> public override int size() { return(_size + _tail.size()); }
/// <summary> /// Number operation. /// </summary> /// <param name="arg"> /// Result from the expressions evaluation. </param> /// <param name="dc"> /// Result of dynamic context operation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:number operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble fn_number(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static XSDouble fn_number(ResultSequence arg, EvaluationContext ec) { if (arg.size() > 1) { throw new DynamicError(TypeError.invalid_type("bad argument passed to fn:number()")); } else if (arg.size() == 1) { Item at = arg.first(); /* * if (!(at instanceof AnyAtomicType)) * DynamicError.throw_type_error(); */ if (at is AnyAtomicType) { if ((at is XSDouble)) { return((XSDouble)at); } else if ((at is XSFloat)) { float value = ((XSFloat)at).float_value(); if (float.IsNaN(value)) { return(new XSDouble(double.NaN)); } else if (value == float.NegativeInfinity) { return(new XSDouble(double.NegativeInfinity)); } else if (value == float.PositiveInfinity) { return(new XSDouble(double.PositiveInfinity)); } else { return(new XSDouble((double)value)); } } else { XSDouble d = XSDouble.parse_double(at.StringValue); return(d != null ? d : new XSDouble(double.NaN)); } } else if (at is NodeType) { XSDouble d = XSDouble.parse_double((FnData.atomize(at)).StringValue); return(d != null ? d : new XSDouble(double.NaN)); } } else { return(new XSDouble(double.NaN)); } // unreach return(null); }
/// <summary> /// Count operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:count operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence count(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence count(ICollection args) { Debug.Assert(args.Count == 1); // get args IEnumerator citer = args.GetEnumerator(); citer.MoveNext(); ResultSequence arg = (ResultSequence)citer.Current; return(ResultSequenceFactory.create_new(new XSInteger(new System.Numerics.BigInteger(arg.size())))); }
/// <summary> /// Boolean operation. /// </summary> /// <param name="arg"> /// Result from the expressions evaluation. </param> /// <returns> Result of fn:boolean operation. </returns> /// <exception cref="DynamicError"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean fn_boolean(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static XSBoolean fn_boolean(ResultSequence arg) { if (arg.empty()) { return(XSBoolean.FALSE); } Item at = arg.item(0); if (at is CalendarType) { throw DynamicError.throw_type_error(); } if (at is NodeType) { return(XSBoolean.TRUE); } if (arg.size() > 1) { throw DynamicError.throw_type_error(); } // XXX ?? if (!(at is AnyAtomicType)) { return(XSBoolean.TRUE); } // ok we got 1 single atomic type element if (at is XSBoolean) { if (!((XSBoolean)at).value()) { return(XSBoolean.FALSE); } } if ((at is XSString) || (at is XSUntypedAtomic)) { if (((AnyType)at).StringValue.Equals("")) { return(XSBoolean.FALSE); } } if (at is NumericType) { if (((NumericType)at).zero()) { return(XSBoolean.FALSE); } } if ((at is XSFloat) && (((XSFloat)at).nan())) { return(XSBoolean.FALSE); } if ((at is XSDouble) && (((XSDouble)at).nan())) { return(XSBoolean.FALSE); } return(XSBoolean.TRUE); }
/// <summary> /// Index-Of operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <param name="dynamicContext"> </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:index-of operation. </returns> public static ResultSequence index_of(ICollection args, DynamicContext dc) { Function.convert_arguments(args, expected_args()); // get args IEnumerator citer = args.GetEnumerator(); citer.MoveNext(); ResultSequence arg1 = (ResultSequence)citer.Current; citer.MoveNext(); ResultSequence arg2 = (ResultSequence)citer.Current; if (arg1 == null || arg1.empty()) { return(ResultBuffer.EMPTY); } // sanity chex if (arg2 == null || arg2.size() != 1) { DynamicError.throw_type_error(); } string collationUri = dc.CollationProvider.DefaultCollation; if (citer.MoveNext()) { ResultSequence arg3 = (ResultSequence)citer.Current; if (!arg3.empty()) { XSString collation = (XSString)arg3.first(); collationUri = collation.StringValue; } } ResultBuffer rb = new ResultBuffer(); AnyAtomicType at = (AnyAtomicType)arg2.first(); get_comparable(at); int index = 1; for (var i = arg1.iterator(); i.MoveNext();) { AnyType cmptype = (AnyType)i.Current; get_comparable(cmptype); if (!(at is CmpEq)) { continue; } if (isBoolean(cmptype, at)) { XSBoolean boolat = (XSBoolean)cmptype; if (boolat.eq(at, dc)) { rb.add(new XSInteger(new System.Numerics.BigInteger(index))); } } else { if (isNumeric(cmptype, at)) { NumericType numericat = (NumericType)at; if (numericat.eq(cmptype, dc)) { rb.add(new XSInteger(new System.Numerics.BigInteger(index))); } } else { if (isDuration(cmptype, at)) { XSDuration durat = (XSDuration)at; if (durat.eq(cmptype, dc)) { rb.add(new XSInteger(new System.Numerics.BigInteger(index))); } } else { if (at is QName && cmptype is QName) { QName qname = (QName)at; if (qname.eq(cmptype, dc)) { rb.add(new XSInteger(new System.Numerics.BigInteger(index))); } } else { if (needsStringComparison(cmptype, at)) { XSString xstr1 = new XSString(cmptype.StringValue); XSString itemStr = new XSString(at.StringValue); if (FnCompare.compare_string(collationUri, xstr1, itemStr, dc).Equals(System.Numerics.BigInteger.Zero)) { rb.add(new XSInteger(new System.Numerics.BigInteger(index))); } } } } } } index++; } return(rb.Sequence); }
/// <summary> /// Mathematical division between this duration stored and the supplied /// duration of time (of type XSDayTimeDuration) /// </summary> /// <param name="arg"> /// The duration of time to divide by </param> /// <returns> New XSDayTimeDuration representing the resulting duration after /// the division </returns> /// <exception cref="DynamicError"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence div(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public virtual ResultSequence div(ResultSequence arg) { if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); if (at is XSDouble) { XSDouble dt = (XSDouble)at; double retval = 0; if (dt.nan()) { throw DynamicError.nan(); } if (!dt.zero()) { decimal ret = new decimal(0); if (dt.infinite()) { retval = value() / dt.double_value(); } else { ret = new decimal(value()); ret = decimal.Divide(ret, new decimal(dt.double_value())); var x = ret.ToString(); double.TryParse(x, out double r); retval = r; } } else { throw DynamicError.overflowUnderflow(); } return(ResultSequenceFactory.create_new(new XSDayTimeDuration(retval))); } else if (at is XSDecimal) { XSDecimal dt = (XSDecimal)at; decimal ret = new decimal(0); if (!dt.zero()) { ret = new decimal(value()); ret = decimal.Divide(ret, dt.Value); } else { throw DynamicError.overflowUnderflow(); } var x = ret.ToString(); double.TryParse(x, out double r); var i = (int)r; return(ResultSequenceFactory.create_new(new XSDayTimeDuration(i))); } else if (at is XSDayTimeDuration) { XSDuration md = (XSDuration)at; decimal res = default; res = new decimal(this.value()); decimal l = new decimal(md.value()); res = decimal.Divide(res, l); return(ResultSequenceFactory.create_new(new XSDecimal(res))); } else { DynamicError.throw_type_error(); return(null); // unreach } }