/* (non-Javadoc)
  * @see org.exist.xquery.value.AtomicValue#min(org.exist.xquery.value.AtomicValue)
  */
 public AtomicValue min(Collator collator, AtomicValue other) throws XPathException {
   if (Type.subTypeOf(other.getType(), Type.UNTYPED_ATOMIC))
     return Collations.compare(collator, value, ((UntypedAtomicValue) other).value) < 0
         ? this
         : other;
   else return Collations.compare(collator, value, other.getStringValue()) < 0 ? this : other;
 }
 /* (non-Javadoc)
  * @see org.exist.xquery.value.AtomicValue#compareTo(int, org.exist.xquery.value.AtomicValue)
  */
 public boolean compareTo(Collator collator, int operator, AtomicValue other)
     throws XPathException {
   if (other.isEmpty()) return false;
   if (Type.subTypeOf(other.getType(), Type.STRING)
       || Type.subTypeOf(other.getType(), Type.UNTYPED_ATOMIC)) {
     int cmp = Collations.compare(collator, value, other.getStringValue());
     switch (operator) {
       case Constants.EQ:
         return cmp == 0;
       case Constants.NEQ:
         return cmp != 0;
       case Constants.LT:
         return cmp < 0;
       case Constants.LTEQ:
         return cmp <= 0;
       case Constants.GT:
         return cmp > 0;
       case Constants.GTEQ:
         return cmp >= 0;
       default:
         throw new XPathException("Type error: cannot apply operand to string value");
     }
   }
   throw new XPathException(
       "Type error: operands are not comparable; expected xdt:untypedAtomic; got "
           + Type.getTypeName(other.getType()));
 }
Exemple #3
0
  public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
    if (context.getProfiler().isEnabled()) {
      context.getProfiler().start(this);
      context
          .getProfiler()
          .message(
              this,
              Profiler.DEPENDENCIES,
              "DEPENDENCIES",
              Dependency.getDependenciesName(this.getDependencies()));
      if (contextSequence != null) {
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
      }
      if (contextItem != null) {
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
      }
    }

    if (contextItem != null) {
      contextSequence = contextItem.toSequence();
    }

    Sequence result;
    final String s1 = getArgument(0).eval(contextSequence).getStringValue();
    final String s2 = getArgument(1).eval(contextSequence).getStringValue();
    if (s1.length() == 0 || s2.length() == 0) {
      result = Sequence.EMPTY_SEQUENCE;
    } else {
      final Collator collator = getCollator(contextSequence, contextItem, 3);
      if (Collations.startsWith(collator, s1, s2)) {
        result = BooleanValue.TRUE;
      } else {
        result = BooleanValue.FALSE;
      }
    }

    if (context.getProfiler().isEnabled()) {
      context.getProfiler().end(this, "", result);
    }

    return result;
  }
 /* (non-Javadoc)
  * @see org.exist.xquery.value.AtomicValue#contains(org.exist.xquery.value.AtomicValue)
  */
 public boolean contains(Collator collator, AtomicValue other) throws XPathException {
   return Collations.indexOf(collator, value, other.getStringValue())
       != Constants.STRING_NOT_FOUND;
 }
 /* (non-Javadoc)
  * @see org.exist.xquery.value.AtomicValue#endsWith(org.exist.xquery.value.AtomicValue)
  */
 public boolean endsWith(Collator collator, AtomicValue other) throws XPathException {
   return Collations.endsWith(collator, value, other.getStringValue());
 }
 /* (non-Javadoc)
  * @see org.exist.xquery.value.AtomicValue#compareTo(org.exist.xquery.value.AtomicValue)
  */
 public int compareTo(Collator collator, AtomicValue other) throws XPathException {
   return Collations.compare(collator, value, other.getStringValue());
 }