use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class FunCompare method eval.
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
final Sequence seq1 = getArgument(0).eval(contextSequence, contextItem);
final Sequence seq2 = getArgument(1).eval(contextSequence, contextItem);
Sequence result;
if (seq1.isEmpty() || seq2.isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final Collator collator = getCollator(contextSequence, contextItem, 3);
final int comparison = Collations.compare(collator, seq1.getStringValue(), seq2.getStringValue());
if (comparison == Constants.EQUAL) {
result = new IntegerValue(Constants.EQUAL);
} else if (comparison < 0) {
result = new IntegerValue(Constants.INFERIOR);
} else {
result = new IntegerValue(Constants.SUPERIOR);
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class FunCount method eval.
@Override
public Sequence eval(Sequence contextSequence, final Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
if (contextItem != null) {
contextSequence = contextItem.toSequence();
}
final Sequence result;
if (getArgumentCount() == 0) {
result = IntegerValue.ZERO;
} else {
final Sequence seq = getArgument(0).eval(contextSequence);
result = new IntegerValue(seq.getItemCountLong());
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class FunGetDurationComponent method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
}
Sequence result;
if (args.length == 0 || args[0].isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final Sequence arg = args[0];
final DurationValue duration = new DurationValue(((DurationValue) arg.itemAt(0)).getCanonicalDuration());
if (isCalledAs("days-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.DAY));
} else if (isCalledAs("hours-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.HOUR));
} else if (isCalledAs("minutes-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.MINUTE));
} else if (isCalledAs("seconds-from-duration")) {
if (duration.getCanonicalDuration().getField(DatatypeConstants.SECONDS) == null) {
result = new DecimalValue(0);
} else {
result = new DecimalValue((BigDecimal) duration.getCanonicalDuration().getField(DatatypeConstants.SECONDS));
}
if (duration.getCanonicalDuration().getSign() < 0) {
result = ((DecimalValue) result).negate();
}
} else if (isCalledAs("months-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.MONTH));
} else if (isCalledAs("years-from-duration")) {
result = new IntegerValue(duration.getPart(DurationValue.YEAR));
} else {
logger.error("can't handle function {}", getName().getLocalPart());
throw new Error("can't handle function " + getName().getLocalPart());
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class FunGetDateComponent method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
}
Sequence result;
if (args.length == 0 || args[0].isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final Sequence arg = args[0];
final AbstractDateTimeValue date = (AbstractDateTimeValue) arg.itemAt(0);
if (isCalledAs("day-from-dateTime") || isCalledAs("day-from-date")) {
result = new IntegerValue(date.getPart(DateValue.DAY), Type.INTEGER);
} else if (isCalledAs("month-from-dateTime") || isCalledAs("month-from-date")) {
result = new IntegerValue(date.getPart(DateValue.MONTH), Type.INTEGER);
} else if (isCalledAs("year-from-dateTime") || isCalledAs("year-from-date")) {
result = new IntegerValue(date.getPart(DateValue.YEAR), Type.INTEGER);
} else if (isCalledAs("hours-from-dateTime") || isCalledAs("hours-from-time")) {
result = new IntegerValue(date.getPart(DateValue.HOUR), Type.INTEGER);
} else if (isCalledAs("minutes-from-dateTime") || isCalledAs("minutes-from-time")) {
result = new IntegerValue(date.getPart(DateValue.MINUTE), Type.INTEGER);
} else if (isCalledAs("seconds-from-dateTime") || isCalledAs("seconds-from-time")) {
result = new IntegerValue(date.calendar.getSecond()).convertTo(Type.DECIMAL);
if (date.calendar.getFractionalSecond() != null) {
result = ((DecimalValue) result).plus(new DecimalValue(date.calendar.getFractionalSecond()));
}
} else if (isCalledAs("timezone-from-dateTime") || isCalledAs("timezone-from-date") || isCalledAs("timezone-from-time")) {
result = date.getTimezone();
} else {
logger.error("can't handle function {}", getName().getLocalPart());
throw new Error("can't handle function " + getName().getLocalPart());
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class XQueryDeclareContextItemTest method declareContextItemExternal.
@Test
public void declareContextItemExternal() throws EXistException, PermissionDeniedException, XPathException {
final String query = "xquery version \"3.0\";\n" + "declare context item external; \n" + ". + 4";
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final XQuery xquery = pool.getXQueryService();
try (final DBBroker broker = pool.getBroker()) {
final Sequence result = xquery.execute(broker, query, new IntegerValue(3));
assertEquals(1, result.getItemCount());
assertEquals(7, (int) result.itemAt(0).toJavaObject(int.class));
}
}
Aggregations