Package org.exist.xquery.value

Examples of org.exist.xquery.value.NumericValue


        if (getSignature().getArgumentCount() > 1) {
          precision = (IntegerValue) getArgument(1).eval(contextSequence, contextItem).itemAt(0).convertTo(Type.INTEGER);
        }
           
          final Item item = seq.itemAt(0);
          NumericValue value;
          if (item instanceof NumericValue) {
        value = (NumericValue) item;
      } else {
        value = (NumericValue) item.convertTo(Type.NUMBER);
      }
         
      result = value.round(precision);
        }
       
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
       
View Full Code Here


        final Sequence seq = getArgument(0).eval(contextSequence, contextItem);
        if (seq.isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
        else {
          final Item item = seq.itemAt(0);
          NumericValue value;
          if (item instanceof NumericValue) {
        value = (NumericValue) item;
      } else {
        value = (NumericValue) item.convertTo(Type.NUMBER);
      }
            result = value.abs();
        }
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
        return result;
    }
View Full Code Here

    } else {
      //get the string to substring
          final String sourceString = seqSourceString.getStringValue();
       
          //check for a valid start position for the substring
          final NumericValue startingLoc = ((NumericValue)(argStartingLoc.eval(contextSequence).itemAt(0).convertTo(Type.NUMBER))).round();
          if(!validStartPosition(startingLoc, sourceString.length())) {
            //invalid start position
            result = StringValue.EMPTY_STRING;
          } else {
        //are there 2 or 3 arguments to this function?
        if(getArgumentCount() > 2) {
          argLength = getArgument(2);
                    NumericValue length = new IntegerValue(sourceString.length());
                    length = ((NumericValue)(argLength.eval(contextSequence).itemAt(0).convertTo(Type.NUMBER))).round();

                    // Relocate length to position according to spec:
                    // fn:round($startingLoc) <=
                    // $p
                    // < fn:round($startingLoc) + fn:round($length)
                    NumericValue endingLoc;
                    if (!length.isInfinite()) {
                        endingLoc = (NumericValue) new IntegerValue(startingLoc.getInt() + length.getInt());
                    } else {
                        endingLoc = length;
                    }
          //check for a valid end position for the substring
          if(!validEndPosition(endingLoc, startingLoc)) {
            //invalid length
            result = StringValue.EMPTY_STRING;
          } else {
            if(endingLoc.getInt() > sourceString.length()
                           || endingLoc.isInfinite()) {
              //fallback to fn:substring(string, start)
              result = substring(sourceString, startingLoc);
            } else {
              //three arguments fn:substring(string, start, end)
              result = substring(sourceString, startingLoc, endingLoc);
View Full Code Here

        final Sequence seq = getArgument(0).eval(contextSequence, contextItem);
    if (seq.isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
        else {
          final Item item = seq.itemAt(0);
          NumericValue value;
          if (item instanceof NumericValue) {
        value = (NumericValue) item;
      } else {
        value = (NumericValue) item.convertTo(Type.NUMBER);
      }
        result = value.floor();
        }
       
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
       
View Full Code Here

      throws XPathException {

        if (args[0].isEmpty())
            return Sequence.EMPTY_SEQUENCE;
       
        NumericValue numericValue = (NumericValue)args[0].itemAt(0);

        try {
            String value = new DecimalFormat(args[1].getStringValue()).format(numericValue.getDouble());
            return new StringValue(value);
        } catch (java.lang.IllegalArgumentException e) {
            throw new XPathException(e.getMessage());
        }
  }
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)) {
View Full Code Here

            }
        }
       
        Sequence result;
        Sequence seq = args[0].convertTo(Type.DOUBLE);
        NumericValue value = (NumericValue)seq.itemAt(0).convertTo(Type.DOUBLE);

        if(seq.isEmpty())
            result = Sequence.EMPTY_SEQUENCE;
        else {         
            double calcValue=0;
            String functionName = getSignature().getName().getLocalName();
            if("abs".equals(functionName)) {
                calcValue=Math.abs(value.getDouble());
               
            } else if("acos".equals(functionName)) {
                calcValue=Math.acos(value.getDouble());
               
            } else if("asin".equals(functionName)) {
                calcValue=Math.asin(value.getDouble());
               
            } else if("atan".equals(functionName)) {
                calcValue=Math.atan(value.getDouble());
               
            } else if("ceil".equals(functionName)) {
                calcValue=Math.ceil(value.getDouble());
               
            } else if("cos".equals(functionName)) {
                calcValue=Math.cos(value.getDouble());
               
            } else if("exp".equals(functionName)) {
                calcValue=Math.exp(value.getDouble());
               
            } else if("floor".equals(functionName)) {
                calcValue=Math.floor(value.getDouble());
               
            } else if("log".equals(functionName)) {
                calcValue=Math.log(value.getDouble());
               
            } else if("round".equals(functionName)) {
                calcValue=Math.rint(value.getDouble());
               
            } else if("sin".equals(functionName)) {
                calcValue=Math.sin(value.getDouble());
               
            } else if("sqrt".equals(functionName)) {
                calcValue=Math.sqrt(value.getDouble());
               
            } else if("tan".equals(functionName)) {
                calcValue=Math.tan(value.getDouble());
               
            } else if("degrees".equals(functionName)) {
                calcValue=Math.toDegrees(value.getDouble());
               
            } else if("radians".equals(functionName)) {
                calcValue=Math.toRadians(value.getDouble());
               
            } else {
                throw new XPathException(this, "Function "+functionName+" not found.");
            }
            result=new DoubleValue(calcValue);
View Full Code Here

        Sequence result;
        double calcValue=0;
        String functionName = getSignature().getName().getLocalName();
       
        Sequence seqA = args[0].convertTo(Type.DOUBLE);
        NumericValue valueA = (NumericValue)seqA.itemAt(0).convertTo(Type.DOUBLE);
       
        Sequence seqB = args[1].convertTo(Type.DOUBLE);
        NumericValue valueB = (NumericValue)seqB.itemAt(0).convertTo(Type.DOUBLE);
       
        if("atan2".equals(functionName)) {
            calcValue = Math.atan2(valueA.getDouble(), valueB.getDouble());
           
        } else if("power".equals(functionName)) {
            calcValue=Math.pow(valueA.getDouble(), valueB.getDouble());
           
        } else {
            throw new XPathException(this, "Function "+functionName+" not found.");
        }
        result=new DoubleValue(calcValue);
View Full Code Here

      {throw new XPathException(this, ErrorCodes.XPTY0004, "The first operand must have at most one item", startSeq);}
    else if (endSeq.hasMany())
      {throw new XPathException(this, ErrorCodes.XPTY0004, "The second operand must have at most one item", endSeq);}
        else {
          if (context.isBackwardsCompatible()) {
            NumericValue valueStart;
            try {
              //Currently breaks 1e3 to 3
              valueStart = (NumericValue)startSeq.itemAt(0).convertTo(Type.NUMBER);
            } catch (final XPathException e) {
          throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +
              Type.getTypeName(Type.INTEGER) + " but got '" + Type.getTypeName(startSeq.itemAt(0).getType()) + "(" +
              startSeq.itemAt(0).getStringValue() + ")'", startSeq);
            }
            NumericValue valueEnd;
            try {
              //Currently breaks 3 to 1e3
              valueEnd = (NumericValue)endSeq.itemAt(0).convertTo(Type.NUMBER);
            } catch (final XPathException e) {
          throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +
              Type.getTypeName(Type.INTEGER) + " but got '" + Type.getTypeName(endSeq.itemAt(0).getType()) + "(" +
              endSeq.itemAt(0).getStringValue() + ")'", endSeq);
            }
            //Implied by previous conversion
            if (valueStart.hasFractionalPart()) {
          throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +
              Type.getTypeName(Type.INTEGER) + " but got '" + Type.getTypeName(startSeq.itemAt(0).getType()) + "(" +
              startSeq.itemAt(0).getStringValue() + ")'", startSeq);
        }
            //Implied by previous conversion
            if (valueEnd.hasFractionalPart()) {
          throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +
              Type.getTypeName(Type.INTEGER) + " but got '" + Type.getTypeName(endSeq.itemAt(0).getType()) + "(" +
              startSeq.itemAt(0).getStringValue() + ")'", endSeq);
            }         
//            result = new ValueSequence();
//        for(long i = ((IntegerValue)valueStart.convertTo(Type.INTEGER)).getLong();
//          i <= ((IntegerValue)valueEnd.convertTo(Type.INTEGER)).getLong(); i++) {
//          result.add(new IntegerValue(i));
//        }
        result = new RangeSequence((IntegerValue)valueStart.convertTo(Type.INTEGER),
              (IntegerValue)valueEnd.convertTo(Type.INTEGER));
          } else {
            //Quite unusual test : we accept integers but no other *typed* type
            if (!Type.subTypeOf(startSeq.itemAt(0).atomize().getType(), Type.INTEGER) &&
              !Type.subTypeOf(startSeq.itemAt(0).atomize().getType(), Type.UNTYPED_ATOMIC))
          {throw new XPathException(this, ErrorCodes.FORG0006, "Required type is " +
View Full Code Here

        Sequence result;
        if (seq.isEmpty()) {
            result = Sequence.EMPTY_SEQUENCE;
        } else {
          final Item item = seq.itemAt(0);
          NumericValue value;
          if (item instanceof NumericValue) {
        value = (NumericValue) item;
      } else {
        value = (NumericValue) item.convertTo(Type.NUMBER);
      }
            result = value.ceiling();
        }
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
        return result;
    }
View Full Code Here

TOP

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

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.