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;
}
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());
}
}
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();
}
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());
}
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());
}
Aggregations