Search in sources :

Example 41 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class Function method sum.

public static boolean sum(final XdmNodeReadTrx rtx, final AbstractAxis axis, final AbstractAxis mZero) {
    Double value = 0.0;
    if (!axis.hasNext()) {
        // if is empty sequence, return values specified
        mZero.hasNext();
    // for
    // zero
    } else {
        do {
            value = value + Double.parseDouble(rtx.getValue());
        } while (axis.hasNext());
        final int itemKey = rtx.getItemList().addItem(new AtomicValue(value, Type.DOUBLE));
        rtx.moveTo(itemKey);
    }
    return true;
}
Also used : AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 42 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class NodeCompTest method testAtomize.

@Test
public void testAtomize() throws SirixXPathException {
    Axis axis = new LiteralExpr(holder.getReader(), -2);
    axis.hasNext();
    axis.next();
    AtomicValue[] value = comparator.atomize(axis);
    assertEquals(value.length, 1);
    assertEquals(holder.getReader().getNodeKey(), value[0].getNodeKey());
    assertEquals("xs:integer", value[0].getType());
    try {
        axis = new DescendantAxis(holder.getReader());
        axis.hasNext();
        comparator.atomize(axis);
    } catch (SirixXPathException e) {
        assertEquals("err:XPTY0004 The type is not appropriate the expression or" + " the typedoes not match a required type as specified by the " + "matching rules.", e.getMessage());
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Example 43 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class AndExprTest method testAnd.

@Test(expected = NoSuchElementException.class)
public void testAnd() throws SirixException {
    long iTrue = holder.getReader().getItemList().addItem(new AtomicValue(true));
    long iFalse = holder.getReader().getItemList().addItem(new AtomicValue(false));
    AbstractAxis trueLit1 = new LiteralExpr(holder.getReader(), iTrue);
    AbstractAxis trueLit2 = new LiteralExpr(holder.getReader(), iTrue);
    AbstractAxis falseLit1 = new LiteralExpr(holder.getReader(), iFalse);
    AbstractAxis falseLit2 = new LiteralExpr(holder.getReader(), iFalse);
    AbstractAxis axis1 = new AndExpr(holder.getReader(), trueLit1, trueLit2);
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis1.hasNext());
    AbstractAxis axis2 = new AndExpr(holder.getReader(), trueLit1, falseLit1);
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis2.hasNext());
    AbstractAxis axis3 = new AndExpr(holder.getReader(), falseLit1, trueLit1);
    assertEquals(true, axis3.hasNext());
    axis3.next();
    assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis3.hasNext());
    AbstractAxis axis4 = new AndExpr(holder.getReader(), falseLit1, falseLit2);
    assertEquals(true, axis4.hasNext());
    axis4.next();
    assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis4.hasNext());
    axis4.next();
}
Also used : AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Example 44 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class AbsOpAxisTest method testHasNext.

@Test
public final void testHasNext() throws SirixException {
    final AtomicValue item1 = new AtomicValue(1.0, Type.DOUBLE);
    final AtomicValue item2 = new AtomicValue(2.0, Type.DOUBLE);
    AbstractAxis op1 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item1));
    AbstractAxis op2 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item2));
    AbstractObAxis axis = new DivOpAxis(holder.getReader(), op1, op2);
    assertEquals(true, axis.hasNext());
    assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
    assertEquals(false, axis.hasNext());
    // here both operands are the empty sequence
    axis = new DivOpAxis(holder.getReader(), op1, op2);
    assertEquals(true, axis.hasNext());
    axis.next();
    assertThat(Double.NaN, is(Double.parseDouble(holder.getReader().getValue())));
    assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
    assertEquals(false, axis.hasNext());
}
Also used : AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Example 45 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class AddOpAxisTest method testOperate.

@Test
public final void testOperate() throws SirixException {
    AtomicValue item1 = new AtomicValue(1.0, Type.DOUBLE);
    AtomicValue item2 = new AtomicValue(2.0, Type.DOUBLE);
    AbstractAxis op1 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item1));
    AbstractAxis op2 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item2));
    AbstractObAxis axis = new AddOpAxis(holder.getReader(), op1, op2);
    assertEquals(true, axis.hasNext());
    axis.next();
    assertThat(3.0, is(Double.parseDouble(holder.getReader().getValue())));
    assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
    assertEquals(false, axis.hasNext());
}
Also used : AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Aggregations

AtomicValue (org.sirix.service.xml.xpath.AtomicValue)47 Test (org.junit.Test)12 AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)10 LiteralExpr (org.sirix.service.xml.xpath.expr.LiteralExpr)10 Type (org.sirix.service.xml.xpath.types.Type)7 XPathError (org.sirix.service.xml.xpath.XPathError)6 ErrorType (org.sirix.service.xml.xpath.XPathError.ErrorType)6 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)4 Axis (org.sirix.api.Axis)3 SirixXPathException (org.sirix.exception.SirixXPathException)3 ArrayList (java.util.ArrayList)1 DescendantAxis (org.sirix.axis.DescendantAxis)1 SingleType (org.sirix.service.xml.xpath.SingleType)1