Example #1
0
 /**
  * Checks if the specified item is a string or binary item.
  *
  * @param it item to be checked
  * @return byte array
  * @throws QueryException query exception
  */
 protected final byte[] toBytes(final Item it) throws QueryException {
   if (checkNoEmpty(it).type.isStringOrUntyped()) return it.string(info);
   if (it instanceof Bin) return ((Bin) it).binary(info);
   throw STRBIN_X_X.get(info, it.type, it);
 }
Example #2
0
 @Override
 public final Item atomItem(final QueryContext qc, final InputInfo ii) throws QueryException {
   final Item it1 = item(qc, info);
   return it1 == null ? null : it1.atomItem(info);
 }
Example #3
0
 @Override
 public Iter iter(final QueryContext qc) throws QueryException {
   final Item it = item(qc, info);
   return it != null ? it.iter() : Empty.ITER;
 }
Example #4
0
 /**
  * Checks if the specified item yields a node or item. Returns the item or throws an exception.
  *
  * @param it item to be checked (can be {@code null})
  * @return node or atomized item
  * @throws QueryException query exception
  */
 protected final Item toNodeOrAtomItem(final Item it) throws QueryException {
   return it == null || it instanceof ANode ? it : it.atomItem(info);
 }
Example #5
0
 /**
  * Checks if the specified expression yields a float. Returns the float or throws an exception.
  *
  * @param ex expression to be evaluated
  * @param qc query context
  * @return float
  * @throws QueryException query exception
  */
 protected final float toFloat(final Expr ex, final QueryContext qc) throws QueryException {
   final Item it = ex.atomItem(qc, info);
   if (checkNoEmpty(it, AtomType.FLT).type.isNumberOrUntyped()) return it.flt(info);
   throw numberError(this, it);
 }
Example #6
0
 /**
  * Checks if the specified item is a number. Returns a token representation or throws an
  * exception.
  *
  * @param it item to be checked
  * @return number
  * @throws QueryException query exception
  */
 protected final long toLong(final Item it) throws QueryException {
   final Type ip = checkNoEmpty(it, AtomType.ITR).type;
   if (ip.instanceOf(AtomType.ITR) || ip.isUntyped()) return it.itr(info);
   throw castError(it, AtomType.ITR, info);
 }
Example #7
0
 /**
  * Checks if the specified, non-empty item is a double. Returns the double or throws an exception.
  *
  * @param it item to be checked
  * @return number
  * @throws QueryException query exception
  */
 private ANum toNumber(final Item it) throws QueryException {
   if (it.type.isUntyped()) return Dbl.get(it.dbl(info));
   if (it instanceof ANum) return (ANum) it;
   throw numberError(this, it);
 }
Example #8
0
 /**
  * Checks if the specified item is a double. Returns the double or throws an exception.
  *
  * @param it item
  * @return double
  * @throws QueryException query exception
  */
 protected final double toDouble(final Item it) throws QueryException {
   if (checkNoEmpty(it, AtomType.DBL).type.isNumberOrUntyped()) return it.dbl(info);
   throw numberError(this, it);
 }
Example #9
0
 /**
  * Checks if the specified item is a boolean. Returns the boolean or throws an exception.
  *
  * @param it item be checked
  * @return boolean
  * @throws QueryException query exception
  */
 protected final boolean toBoolean(final Item it) throws QueryException {
   final Type ip = checkNoEmpty(it, AtomType.BLN).type;
   if (ip == AtomType.BLN) return it.bool(info);
   if (ip.isUntyped()) return Bln.parse(it.string(info), info);
   throw castError(it, AtomType.BLN, info);
 }
Example #10
0
 /**
  * Checks if the specified non-empty item is a string. Returns its value as token or throws an
  * exception.
  *
  * @param it item to be checked
  * @return token
  * @throws QueryException query exception
  */
 protected final byte[] toToken(final Item it) throws QueryException {
   final Type ip = it.type;
   if (ip.isStringOrUntyped()) return it.string(info);
   throw it instanceof FItem ? FIATOM_X.get(info, it.type) : castError(it, AtomType.STR, info);
 }
Example #11
0
 @Override
 public final Item test(final QueryContext qc, final InputInfo ii) throws QueryException {
   final Item it = ebv(qc, info);
   return (it instanceof ANum ? it.dbl(info) == qc.pos : it.bool(info)) ? it : null;
 }