Beispiel #1
0
 private static RefEval EvaluateRef(Eval arg)
 {
     if (arg is RefEval)
     {
         return (RefEval)arg;
     }
     if (arg is ErrorEval)
     {
         throw new EvaluationException((ErrorEval)arg);
     }
     throw new ArgumentException("Unexpected ref arg class (" + arg.GetType().Name + ")");
 }
Beispiel #2
0
 private static void CollectValue(Eval arg, IList temp, bool mustBeNumber)
 {
     if (arg is ErrorEval)
     {
         throw new EvaluationException((ErrorEval)arg);
     }
     if (arg == BlankEval.INSTANCE || arg is BoolEval || arg is StringEval)
     {
         if (mustBeNumber)
         {
             throw EvaluationException.InvalidValue();
         }
         return;
     }
     if (arg is NumberEval)
     {
         temp.Add(((NumberEval)arg).NumberValue);
         return;
     }
     throw new InvalidOperationException("Unexpected value type (" + arg.GetType().Name + ")");
 }
Beispiel #3
0
        public static I_MatchPredicate CreateCriteriaPredicate(Eval evaluatedCriteriaArg)
        {
            if (evaluatedCriteriaArg is NumberEval)
            {
                return new NumberMatcher(((NumberEval)evaluatedCriteriaArg).NumberValue, CmpOp.OP_NONE);
            }
            if (evaluatedCriteriaArg is BoolEval)
            {
                return new BooleanMatcher(((BoolEval)evaluatedCriteriaArg).BooleanValue, CmpOp.OP_NONE);
            }

            if (evaluatedCriteriaArg is StringEval)
            {
                return CreateGeneralMatchPredicate((StringEval)evaluatedCriteriaArg);
            }
            if (evaluatedCriteriaArg == BlankEval.INSTANCE)
            {
                return null;
            }
            throw new Exception("Unexpected type for criteria ("
                    + evaluatedCriteriaArg.GetType().Name + ")");
        }
Beispiel #4
0
 /**
  * @return the number of Evaluated cells in the range that match the specified criteria
  */
 private Eval CountMatchingCellsInArea(Eval rangeArg, I_MatchPredicate criteriaPredicate)
 {
     int result;
     if (rangeArg is RefEval)
     {
         result = CountUtils.CountMatchingCell((RefEval)rangeArg, criteriaPredicate);
     }
     else if (rangeArg is AreaEval)
     {
         result = CountUtils.CountMatchingCellsInArea((AreaEval)rangeArg, criteriaPredicate);
     }
     else
     {
         throw new ArgumentException("Bad range arg type (" + rangeArg.GetType().Name + ")");
     }
     return new NumberEval(result);
 }
Beispiel #5
0
        private static ValueVector EvaluateLookupRange(Eval eval)
        {
            if (eval is RefEval)
            {
                RefEval re = (RefEval)eval;
                return new SingleValueVector(re.InnerValueEval);
            }
            if (eval is AreaEval)
            {
                ValueVector result = LookupUtils.CreateVector((AreaEval)eval);
                if (result == null)
                {
                    throw new EvaluationException(ErrorEval.NA);
                }
                return result;
            }

            // Error handling for lookup_range arg Is also Unusual
            if (eval is NumericValueEval)
            {
                throw new EvaluationException(ErrorEval.NA);
            }
            if (eval is StringEval)
            {
                StringEval se = (StringEval)eval;
                double d = OperandResolver.ParseDouble(se.StringValue);
                if (double.IsNaN(d))
                {
                    // plain string
                    throw new EvaluationException(ErrorEval.VALUE_INVALID);
                }
                // else looks like a number
                throw new EvaluationException(ErrorEval.NA);
            }
            throw new Exception("Unexpected eval type (" + eval.GetType().Name + ")");
        }
 private static ValueVector CreateValueVector(Eval arg)
 {
     if (arg is ErrorEval)
     {
         throw new EvaluationException((ErrorEval)arg);
     }
     if (arg is AreaEval)
     {
         return new AreaValueArray((AreaEval)arg);
     }
     if (arg is RefEval)
     {
         return new RefValueArray((RefEval)arg);
     }
     if (arg is ValueEval)
     {
         return new SingleCellValueArray((ValueEval)arg);
     }
     throw new InvalidOperationException("Unexpected eval class (" + arg.GetType().Name + ")");
 }