Skip to content

Commit

Permalink
WIP. Aligned atomic item map key implementations with the XPath 3.1 s…
Browse files Browse the repository at this point in the history
…pecification.
  • Loading branch information
david-waltermire committed Jan 13, 2025
1 parent 34451a5 commit 3b4ac40
Show file tree
Hide file tree
Showing 39 changed files with 623 additions and 334 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* SPDX-FileCopyrightText: none
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.core.datatype.adapter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Support for the Metaschema
* <a href= "https://pages.nist.gov/metaschema/specification/datatypes/#decimal">decimal</a> data
* type.
* Support for the Metaschema <a href=
* "https://pages.nist.gov/metaschema/specification/datatypes/#decimal">decimal</a>
* data type.
*/
public class DecimalAdapter
extends AbstractDataTypeAdapter<BigDecimal, IDecimalItem> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
* result type.
* <p>
* The arithmetic operation method
* {@link #operation(IAnyAtomicItem, IAnyAtomicItem)} must be implemented by
* extending classes to provide the evaluation logic.
* {@link #operation(IAnyAtomicItem, IAnyAtomicItem, DynamicContext)} must be
* implemented by extending classes to provide the evaluation logic.
*/
public abstract class AbstractBasicArithmeticExpression
extends AbstractArithmeticExpression<IAnyAtomicItem> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.ITimeItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IUntypedAtomicItem;
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IYearMonthDurationItem;
import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException;
Expand Down Expand Up @@ -194,6 +195,8 @@ public static IBooleanItem compare( // NOPMD - unavoidable
retval = dateTimeCompare((IDateTimeItem) left, operator, (IDateTimeItem) right);
} else if (left instanceof IDateItem && right instanceof IDateItem) {
retval = dateCompare((IDateItem) left, operator, (IDateItem) right);
} else if (left instanceof ITimeItem && right instanceof ITimeItem) {
retval = timeCompare((ITimeItem) left, operator, (ITimeItem) right);
} else if (left instanceof IDurationItem && right instanceof IDurationItem) {
retval = durationCompare((IDurationItem) left, operator, (IDurationItem) right);
} else if (left instanceof IBase64BinaryItem && right instanceof IBase64BinaryItem) {
Expand Down Expand Up @@ -440,6 +443,54 @@ public static IBooleanItem dateCompare(@NonNull IDateItem left, @NonNull Operato
return retval;
}

/**
* Perform a date-based comparison of the {@code right} item against the
* {@code left} item using the specified {@code operator}.
*
* @param left
* the value to compare against
* @param operator
* the comparison operator
* @param right
* the value to compare with
* @return the comparison result
*/
@NonNull
public static IBooleanItem timeCompare(@NonNull ITimeItem left, @NonNull Operator operator,
@NonNull ITimeItem right) {

IBooleanItem retval;
switch (operator) {
case EQ:
retval = OperationFunctions.opTimeEqual(left, right);
break;
case GE: {
IBooleanItem gt = OperationFunctions.opTimeGreaterThan(left, right);
IBooleanItem eq = OperationFunctions.opTimeEqual(left, right);
retval = IBooleanItem.valueOf(gt.toBoolean() || eq.toBoolean());
break;
}
case GT:
retval = OperationFunctions.opTimeGreaterThan(left, right);
break;
case LE: {
IBooleanItem lt = OperationFunctions.opTimeLessThan(left, right);
IBooleanItem eq = OperationFunctions.opTimeEqual(left, right);
retval = IBooleanItem.valueOf(lt.toBoolean() || eq.toBoolean());
break;
}
case LT:
retval = OperationFunctions.opTimeLessThan(left, right);
break;
case NE:
retval = FnNot.fnNot(OperationFunctions.opTimeEqual(left, right));
break;
default:
throw new IllegalArgumentException(String.format("Unsupported operator '%s'", operator.name()));
}
return retval;
}

/**
* Perform a duration-based comparison of the {@code right} item against the
* {@code left} item using the specified {@code operator}.
Expand Down
Loading

0 comments on commit 3b4ac40

Please sign in to comment.