Beispiel #1
0
    @Override
    public Item ev(final InputInfo ii, final Item a, final Item b) throws QueryException {

      final Type ta = a.type, tb = b.type;
      final boolean t1 = ta.isNumber() || ta.isUntyped();
      final boolean t2 = tb.isNumber() || tb.isUntyped();
      if (t1 ^ t2) errNum(ii, !t1 ? a : b);
      if (t1 && t2) {
        final Type t = type(ta, tb);
        if (t == ITR) {
          final long l1 = a.itr(ii);
          final long l2 = b.itr(ii);
          checkRange(ii, l1 + (double) l2);
          return Int.get(l1 + l2);
        }
        if (t == DBL) return Dbl.get(a.dbl(ii) + b.dbl(ii));
        if (t == FLT) return Flt.get(a.flt(ii) + b.flt(ii));
        return Dec.get(a.dec(ii).add(b.dec(ii)));
      }

      if (ta == tb) {
        if (!ta.isDuration()) errNum(ii, !t1 ? a : b);
        if (ta == YMD) return new YMd((YMd) a, (YMd) b, true);
        if (ta == DTD) return new DTd((DTd) a, (DTd) b, true);
      }
      if (ta == DTM) return new Dtm((Date) a, checkDur(ii, b), true, ii);
      if (tb == DTM) return new Dtm((Date) b, checkDur(ii, a), true, ii);
      if (ta == DAT) return new Dat((Date) a, checkDur(ii, b), true, ii);
      if (tb == DAT) return new Dat((Date) b, checkDur(ii, a), true, ii);
      if (ta == TIM) {
        if (tb != DTD) errType(ii, DTD, b);
        return new Tim((Tim) a, (DTd) b, true, ii);
      }
      if (tb == TIM) {
        if (ta != DTD) errType(ii, DTD, b);
        return new Tim((Tim) b, (DTd) a, true, ii);
      }
      errType(ii, ta, b);
      return null;
    }
Beispiel #2
0
 /**
  * Returns a duration type error.
  *
  * @param ii input info
  * @param it item
  * @return duration
  * @throws QueryException query exception
  */
 final Dur checkDur(final InputInfo ii, final Item it) throws QueryException {
   final Type ip = it.type;
   if (!ip.isDuration()) XPDUR.thrw(ii, info(), ip);
   if (ip == DUR) throw SIMPLDUR.thrw(ii, info(), it);
   return (Dur) it;
 }