示例#1
0
 /* (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()));
 }
示例#2
0
 /* (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 java.lang.Comparable#compareTo(java.lang.Object)
  */
 public int compareTo(Object o) {
   final AtomicValue other = (AtomicValue) o;
   if (Type.subTypeOf(other.getType(), Type.DATE_TIME))
     try {
       // TODO : find something that will consume less resources
       return calendar.compare(
           TimeUtils.getInstance().newXMLGregorianCalendar(other.getStringValue()));
     } catch (XPathException e) {
       System.out.println("Failed to get string value of '" + other + "'");
       // Why not ?
       return Constants.SUPERIOR;
     }
   else return getType() > other.getType() ? Constants.SUPERIOR : Constants.INFERIOR;
 }
 public MemoryNodeSet toMemNodeSet() throws XPathException {
   if (count == 0) {
     return MemoryNodeSet.EMPTY;
   }
   if (itemType == Type.ANY_TYPE || !Type.subTypeOf(itemType, Type.NODE)) {
     throw new XPathException(
         "Type error: the sequence cannot be converted into"
             + " a node set. Item type is "
             + Type.getTypeName(itemType));
   }
   NodeValue v;
   for (int i = 0; i <= count; i++) {
     v = (NodeValue) items[i];
     if (v.getImplementationType() == NodeValue.PERSISTENT_NODE) {
       return null;
     }
   }
   return new ValueSequence(this);
 }
 /* (non-Javadoc)
  * @see org.exist.xquery.value.Sequence#toNodeSet()
  */
 public NodeSet toNodeSet() throws XPathException {
   // for this method to work, all items have to be nodes
   if (itemType != Type.ANY_TYPE && Type.subTypeOf(itemType, Type.NODE)) {
     final NodeSet set = new ExtArrayNodeSet();
     // We can't make it from an ExtArrayNodeSet (probably because it is sorted ?)
     // NodeSet set = new ArraySet(100);
     for (int i = 0; i < this.count; i++) {
       NodeValue v = null;
       final Entry temp = items[i];
       v = (NodeValue) temp.item;
       if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
         set.add((NodeProxy) v);
       } else {
         set.add((NodeProxy) v);
       }
     }
     return set;
   } else {
     throw new XPathException(
         "Type error: the sequence cannot be converted into"
             + " a node set. Item type is "
             + Type.getTypeName(itemType));
   }
 }