Ejemplo n.º 1
0
 @Override
 public final int diff(final Item it, final Collation coll, final InputInfo ii)
     throws QueryException {
   return it.type.isUntyped()
       ? coll == null ? Token.diff(string(), it.string(ii)) : coll.compare(string(), it.string(ii))
       : -it.diff(this, coll, ii);
 }
Ejemplo n.º 2
0
  /**
   * Checks two keys for equality.
   *
   * @param its1 first keys
   * @param its2 second keys
   * @param coll collations
   * @return {@code true} if the compare as equal, {@code false} otherwise
   * @throws QueryException query exception
   */
  private boolean eq(final Item[] its1, final Item[] its2, final Collation[] coll)
      throws QueryException {

    final int il = its1.length;
    for (int i = 0; i < il; i++) {
      final Item it1 = its1[i], it2 = its2[i];
      if (it1 == null ^ it2 == null || it1 != null && !it1.equiv(it2, coll[i], info)) return false;
    }
    return true;
  }
Ejemplo n.º 3
0
 @Override
 public final boolean eq(
     final Item it, final Collation coll, final StaticContext sc, final InputInfo ii)
     throws QueryException {
   return it.type.isUntyped()
       ? coll == null
           ? Token.eq(string(), it.string(ii))
           : coll.compare(string(), it.string(ii)) == 0
       : it.eq(this, coll, sc, ii);
 }
Ejemplo n.º 4
0
  /**
   * Returns a minimum or maximum item.
   *
   * @param cmp comparator
   * @param qc query context
   * @return resulting item
   * @throws QueryException query exception
   */
  Item minmax(final OpV cmp, final QueryContext qc) throws QueryException {
    final Collation coll = toCollation(1, qc);

    final Iter iter = exprs[0].atomIter(qc, info);
    Item curr = iter.next();
    if (curr == null) return null;

    // check if first item is comparable
    cmp.eval(curr, curr, coll, sc, info);

    // strings
    if (curr instanceof AStr) {
      for (Item it; (it = iter.next()) != null; ) {
        if (!(it instanceof AStr)) throw EXPTYPE_X_X_X.get(info, curr.type, it.type, it);
        final Type rt = curr.type, ri = it.type;
        if (cmp.eval(curr, it, coll, sc, info)) curr = it;
        if (rt != ri && curr.type == URI) curr = STR.cast(curr, qc, sc, info);
      }
      return curr;
    }
    // dates, durations, booleans, binary values
    if (curr instanceof ADate || curr instanceof Dur || curr instanceof Bin || curr.type == BLN) {
      for (Item it; (it = iter.next()) != null; ) {
        if (curr.type != it.type) throw EXPTYPE_X_X_X.get(info, curr.type, it.type, it);
        if (cmp.eval(curr, it, coll, sc, info)) curr = it;
      }
      return curr;
    }
    // numbers
    if (curr.type.isUntyped()) curr = DBL.cast(curr, qc, sc, info);
    for (Item it; (it = iter.next()) != null; ) {
      final Type type = numType(curr, it);
      if (cmp.eval(curr, it, coll, sc, info) || Double.isNaN(it.dbl(info))) curr = it;
      if (type != null) curr = (Item) type.cast(curr, qc, sc, info);
    }
    return curr;
  }