Package org.exist.xquery.value

Examples of org.exist.xquery.value.AtomicValue


                }
            }
        } else if( !ls.isEmpty() && rs.isEmpty() ) {

            for( final SequenceIterator i1 = ls.iterate(); i1.hasNext(); ) {
                final AtomicValue lv = i1.nextItem().atomize();

                if( compareAtomic( collator, lv, AtomicValue.EMPTY_VALUE ) ) {
                    result = BooleanValue.TRUE;
                    break;
                }
            }
        } else if( ls.hasOne() && rs.hasOne() ) {
            result = BooleanValue.valueOf( compareAtomic( collator, ls.itemAt( 0 ).atomize(), rs.itemAt( 0 ).atomize() ) );
        } else {

            for( final SequenceIterator i1 = ls.iterate(); i1.hasNext(); ) {
                final AtomicValue lv = i1.nextItem().atomize();

                if( rs.isEmpty() ) {

                    if( compareAtomic( collator, lv, AtomicValue.EMPTY_VALUE ) ) {
                        result = BooleanValue.TRUE;
View Full Code Here


                ContextItem context = item.getContext();

                if( context == null ) {
                    throw( new XPathException( this, "Internal error: context node missing" ) );
                }
                final AtomicValue lv = item.atomize();

                do {
                    final Sequence rs = getRight().eval( context.getNode().toSequence() );

                    for( final SequenceIterator i2 = rs.iterate(); i2.hasNext(); ) {
                        final AtomicValue rv = i2.nextItem().atomize();

                        if( compareAtomic( collator, lv, rv ) ) {
                            result.add( item );
                        }
                    }
                } while( ( context = context.getNextDirect() ) != null );
            }
        } else {

            for( final NodeProxy item : nodes ) {
                final AtomicValue lv = item.atomize();
                final Sequence    rs = getRight().eval( contextSequence );

                for( final SequenceIterator i2 = rs.iterate(); i2.hasNext(); ) {
                    final AtomicValue rv = i2.nextItem().atomize();

                    if( compareAtomic( collator, lv, rv ) ) {
                        result.add( item );
                    }
                }
View Full Code Here

    final Sequence ls = getLeft().eval(contextSequence, contextItem);
    final Sequence rs = getRight().eval(contextSequence, contextItem);
    if(ls.isEmpty() || rs.isEmpty())
      {return Sequence.EMPTY_SEQUENCE;}
    if (ls.hasOne() && rs.hasOne()) {
            AtomicValue lv, rv;
      lv = ls.itemAt(0).atomize();
      rv = rs.itemAt(0).atomize();
            final Collator collator = getCollator(contextSequence);
      return BooleanValue.valueOf(compareAtomic(collator, lv, rv, Constants.TRUNC_NONE, relation));
    }
View Full Code Here

                ContextItem context = current.getContext();
                if (context==null) {
                   throw new XPathException(this,"Context is missing for node set comparison");
                }
                do {
                    final AtomicValue lv = current.atomize();
                    final Sequence rs = getRight().eval(context.getNode().toSequence());                   
                    if (!rs.hasOne())
                        {throw new XPathException(this,
                                "Type error: sequence with less or more than one item is not allowed here");}                   
                    if (compareAtomic(collator, lv, rs.itemAt(0).atomize(), Constants.TRUNC_NONE, relation))
                        {result.add(current);}
                } while ((context = context.getNextDirect()) != null);
            }
        } else {
            final Sequence rs = getRight().eval(null);
            if (!rs.hasOne())
                {throw new XPathException(this,
                        "Type error: sequence with less or more than one item is not allowed here");}
            final AtomicValue rv = rs.itemAt(0).atomize();
            for (final Iterator<NodeProxy> i = nodes.iterator(); i.hasNext();) {
                final NodeProxy current = i.next();
                final AtomicValue lv = current.atomize();
                if (compareAtomic(collator, lv, rv, Constants.TRUNC_NONE, Constants.EQ))
                    {result.add(current);}
            }
        }
        return result;
View Full Code Here

       
        Sequence result;
    if (args[0].isEmpty())
      {return Sequence.EMPTY_SEQUENCE;}
        else {
        final AtomicValue srch = args[1].itemAt(0).atomize();
        Collator collator;
        if (getSignature().getArgumentCount() == 3) {
          final String collation = args[2].getStringValue();
          collator = context.getCollator(collation);
        } else
          {collator = context.getDefaultCollator();}
        result = new ValueSequence();
        int j = 1;
        for (final SequenceIterator i = args[0].iterate(); i.hasNext(); j++) {
          final AtomicValue next = i.nextItem().atomize();
          try {
            if (ValueComparison.compareAtomic(collator, next, srch, Constants.TRUNC_NONE, Constants.EQ))
              {result.add(new IntegerValue(j));}
          } catch (final XPathException e) {
            //Ignore me : values can not be compared
View Full Code Here

            final boolean bAtomic = Type.subTypeOf(b.getType(), Type.ATOMIC);
            if (aAtomic || bAtomic) {
                if (!aAtomic || !bAtomic)
                    {return false;}
                try {
                    final AtomicValue av = (AtomicValue) a;
                    final AtomicValue bv = (AtomicValue) b;
                    if (Type.subTypeOf(av.getType(), Type.NUMBER) &&
                        Type.subTypeOf(bv.getType(), Type.NUMBER)) {
                        //or if both values are NaN
                        if (((NumericValue) a).isNaN() && ((NumericValue) b).isNaN())
                            {return true;}
                    }
                    return ValueComparison.compareAtomic(collator, av, bv,
View Full Code Here

        try {
            rs = ps.executeQuery();
            if (!rs.next())
                //Nothing returned
                return AtomicValue.EMPTY_VALUE;
            AtomicValue result = null;
            if (rs.getMetaData().getColumnClassName(1).equals(Boolean.class.getName())) {
                result = new BooleanValue(rs.getBoolean(1));
            } else if (rs.getMetaData().getColumnClassName(1).equals(Double.class.getName())) {
                result = new DoubleValue(rs.getDouble(1));
            } else if (rs.getMetaData().getColumnClassName(1).equals(String.class.getName())) {
View Full Code Here

     
    Collator collator = getCollator(contextSequence, contextItem, 2);   
    TreeMap<AtomicValue, Sequence> map = new TreeMap<AtomicValue, Sequence>(new ValueComparator(collator));

    Item item;
    AtomicValue value;
    NumericValue firstNaN = null;
    for (SequenceIterator i = selected.iterate(); i.hasNext();) {
      item = i.nextItem();
      value = group_by.eval(selected, item).itemAt(0).atomize(); //UNDERSTAND: is it correct?
      if (!map.containsKey(value)) {
        if (Type.subTypeOf(value.getType(), Type.NUMBER)) {
          if (((NumericValue)value).isNaN()) {
            //although NaN does not equal itself, if $arg contains multiple NaN values a single NaN is returned.
            if (firstNaN == null) {
              Sequence seq = new ValueSequence();
              seq.add(item);
View Full Code Here

      {result = Sequence.EMPTY_SEQUENCE;}
        else {
          //TODO : test if a range index is defined *iff* it is compatible with the collator
        final Collator collator = getCollator(contextSequence, contextItem, 2);
        final SequenceIterator iter = arg.unorderedIterator();
        AtomicValue min = null;
        while (iter.hasNext()) {
                final Item item = iter.nextItem();
                if (item instanceof QNameValue)
                {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(item.getType()), arg);}
                AtomicValue value = item.atomize();

                //Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values.
            if (Type.subTypeOf(value.getType(), Type.DURATION)) {
              value = ((DurationValue)value).wrap();
              if (value.getType() == Type.YEAR_MONTH_DURATION) {
                    if (min != null && min.getType() != Type.YEAR_MONTH_DURATION)
                      {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(min.getType()) +
                          " and " + Type.getTypeName(value.getType()), value);}
               
              } else if (value.getType() == Type.DAY_TIME_DURATION) {
                    if (min != null && min.getType() != Type.DAY_TIME_DURATION)
                      {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(min.getType()) +
                          " and " + Type.getTypeName(value.getType()), value);}
               
              } else
                {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(value.getType()), value);}

          //Any value of type xdt:untypedAtomic is cast to xs:double
            } else if (value.getType() == Type.UNTYPED_ATOMIC)
                  {value = value.convertTo(Type.DOUBLE);}
               
            if (min == null)
                    {min = value;}
                else {                 
                  if (Type.getCommonSuperType(min.getType(), value.getType()) == Type.ATOMIC) {
                    throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(min.getType()) +
                        " and " + Type.getTypeName(value.getType()), value);
                  }
                    //Any value of type xdt:untypedAtomic is cast to xs:double
                    if (value.getType() == Type.ATOMIC)
                      {value = value.convertTo(Type.DOUBLE);}
                  //Numeric tests
                  if (Type.subTypeOf(value.getType(), Type.NUMBER)) {
                    //Don't mix comparisons
                    if (!Type.subTypeOf(min.getType(), Type.NUMBER))
                      {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(min.getType()) +
                          " and " + Type.getTypeName(value.getType()), min);}
                    if (((NumericValue) value).isNaN()) {
                      //Type NaN correctly
                      value = value.promote(min);                     
                           if (value.getType() == Type.FLOAT)
                               {min = FloatValue.NaN;}
                           else
                               {min = DoubleValue.NaN;}
                           //although result will be NaN, we need to continue on order to type correctly
                           continue;
                    }
                    min = min.promote(value);
                  }
                  //Ugly test
                  if (value instanceof ComputableValue) {
                        if (!(min instanceof ComputableValue))
                            {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(min.getType()) +
                                    " and " + Type.getTypeName(value.getType()), min);}
                    //Type value correctly
                    value = value.promote(min);
                      min = min.min(collator, value);
                      computableProcessing = true;
                  } else {
                    if (computableProcessing)
                      {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(min.getType()) +
                          " and " + Type.getTypeName(value.getType()), value);}
                    if (Collations.compare(collator, value.getStringValue(), min.getStringValue()) < 0)                
                      {min = value;}
                  }
                }
            }          
            result = min;
View Full Code Here

        else {
          boolean computableProcessing = false;
          //TODO : test if a range index is defined *iff* it is compatible with the collator
        final Collator collator = getCollator(contextSequence, contextItem, 2);
        final SequenceIterator iter = arg.unorderedIterator();
        AtomicValue max = null;
        while (iter.hasNext()) {
                final Item item = iter.nextItem();

                if (item instanceof QNameValue)
                {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(item.getType()), arg);}
               
                AtomicValue value = item.atomize();                

                //Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values.
            if (Type.subTypeOf(value.getType(), Type.DURATION)) {
              value = ((DurationValue)value).wrap();
              if (value.getType() == Type.YEAR_MONTH_DURATION) {
                    if (max != null && max.getType() != Type.YEAR_MONTH_DURATION)
                      {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(max.getType()) +
                          " and " + Type.getTypeName(value.getType()), value);}
               
              } else if (value.getType() == Type.DAY_TIME_DURATION) {
                    if (max != null && max.getType() != Type.DAY_TIME_DURATION)
                      {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(max.getType()) +
                          " and " + Type.getTypeName(value.getType()), value);}
               
              } else
                {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(value.getType()), value);}

            //Any value of type xdt:untypedAtomic is cast to xs:double
            } else if (value.getType() == Type.UNTYPED_ATOMIC)
                  {value = value.convertTo(Type.DOUBLE);}
               
                if (max == null)
                    {max = value;}
               
                else {
                  if (Type.getCommonSuperType(max.getType(), value.getType()) == Type.ATOMIC) {
                    throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(max.getType()) +
                        " and " + Type.getTypeName(value.getType()), max);
                  }
                    //Any value of type xdt:untypedAtomic is cast to xs:double
                    if (value.getType() == Type.UNTYPED_ATOMIC)
                      {value = value.convertTo(Type.DOUBLE);}                 

                    //Numeric tests
                  if (Type.subTypeOf(value.getType(), Type.NUMBER)) {
                    //Don't mix comparisons
                    if (!Type.subTypeOf(max.getType(), Type.NUMBER))
                      {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(max.getType()) +
                          " and " + Type.getTypeName(value.getType()), max);}
                    if (((NumericValue) value).isNaN()) {
                      //Type NaN correctly
                      value = value.promote(max);
                            if (value.getType() == Type.FLOAT)
                                   {max = FloatValue.NaN;}
                               else
                                   {max = DoubleValue.NaN;}
                            //although result will be NaN, we need to continue on order to type correctly
                            continue;
                    } else
                      {max = max.promote(value);}
                  }
                  //Ugly test
                  if (max instanceof ComputableValue && value instanceof ComputableValue) {
                    //Type value correctly
                    value = value.promote(max);
                      max = (ComputableValue) max.max(collator, value);
                      computableProcessing = true;
                  } else {
                    if (computableProcessing)
                      {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(max.getType()) +
                          " and " + Type.getTypeName(value.getType()), max);}
                    if (Collations.compare(collator, value.getStringValue(), max.getStringValue()) > 0)                
                      {max = value;}                   
                  }
                }
            }          
            result = max;
View Full Code Here

TOP

Related Classes of org.exist.xquery.value.AtomicValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.