Class ComparisonFilter<R>
- Type Parameters:
R- the type of resources (e.g.Feature) used as inputs.
- All Implemented Interfaces:
Serializable,Predicate<R>,Filter<R>,Optimization.OnFilter<R>,BinaryComparisonOperator<R>
- Direct Known Subclasses:
ComparisonFilter.EqualTo,ComparisonFilter.GreaterThan,ComparisonFilter.GreaterThanOrEqualTo,ComparisonFilter.LessThan,ComparisonFilter.LessThanOrEqualTo,ComparisonFilter.NotEqualTo
Integer to Double). If values cannot be compared because they cannot
be converted to a common type, or because a value is null or NaN, then the comparison result if false.
A consequence of this rule is that the conditions A < B and A ≥ B may be false at the same time.
If one operand is a collection, all collection elements may be compared to the other value.
Null elements in the collection (not to be confused with null operands) are ignored.
If both operands are collections, current implementation returns false.
Comparisons between temporal objects are done with isBefore(…) or isAfter(…) methods when they
have a different semantic than the compareTo(…) methods. If the two temporal objects are not of the same
type, only the fields that are common two both types are compared. For example, comparison between LocalDate
and LocalDateTime ignores the time fields.
Comparisons of numerical types shall be done by overriding one of the applyAs… methods and
returning 0 if false or 1 if true. Comparisons of other types is done by overriding
the compare(…) methods.
- Since:
- 1.1
- Version:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classThe"PropertyIsBetween"filter.(package private) static final classThe"PropertyIsEqualTo"(=) filter.(package private) static final classThe"PropertyIsGreaterThan"(>) filter.(package private) static final classThe"PropertyIsGreaterThanOrEqualTo"(≥) filter.(package private) static final classThe"PropertyIsLessThan"(<) filter.(package private) static final classThe"PropertyIsLessThanOrEqualTo"(≤) filter.(package private) static final classThe"PropertyIsNotEqualTo"(≠) filter. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanSpecifies whether comparisons are case sensitive.protected final MatchActionSpecifies how the comparisons shall be evaluated for a collection of values.private static final longFor cross-version compatibility.Fields inherited from class org.apache.sis.filter.BinaryFunction
expression1, expression2 -
Constructor Summary
ConstructorsConstructorDescriptionComparisonFilter(Expression<? super R, ?> expression1, Expression<? super R, ?> expression2, boolean isMatchingCase, MatchAction matchAction) Creates a new comparator. -
Method Summary
Modifier and TypeMethodDescriptionprotected final NumberapplyAsDecimal(BigDecimal left, BigDecimal right) Delegates toBigDecimal.compareTo(BigDecimal)and interprets the result withfromCompareTo(int).protected final NumberapplyAsFraction(Fraction left, Fraction right) Calculates this function using given operands ofFractiontype.protected final NumberapplyAsInteger(BigInteger left, BigInteger right) Calculates this function using given operands ofBigIntegertype.protected abstract booleancompare(ChronoLocalDate left, ChronoLocalDate right) Compares two dates without time-of-day and time-zone information.protected abstract booleancompare(ChronoLocalDateTime<?> left, ChronoLocalDateTime<?> right) Compares two dates without time-zone information.protected abstract booleancompare(ChronoZonedDateTime<?> left, ChronoZonedDateTime<?> right) Compares two dates with time-zone information.protected abstract booleancompare(OffsetDateTime left, OffsetDateTime right) Compares two dates with time-zone information.protected abstract booleancompare(OffsetTime left, OffsetTime right) Compares two times with time-zone information.final booleanTakes in account the additional properties in object comparison.private booleanCompares the given objects.protected abstract booleanfromCompareTo(int result) Converts the result ofComparable.compareTo(Object).private static TemporalfromLegacy(Date value) Converts a legacyDateobject to an object from thejava.timepackage.final MatchActionReturns how the comparisons are evaluated for a collection of values.final Expression<? super R,?> Returns the element on the left side of the comparison expression.final Expression<? super R,?> Returns the element on the right side of the comparison expression.final inthashCode()Takes in account the additional properties in hash code calculation.private static voidignoringField(ChronoField field) Invoked when a conversion cause a field to be ignored.final booleanReturns whether comparisons are case sensitive.private static Numbernumber(boolean result) Converts the boolean result as an integer for use as a return value of theapplyAs…methods.final booleanDetermines if the test(s) represented by this filter passes with the given operands.(package private) static InstantConverts the given object to anInstant, or returnsnullif unconvertible.private static ChronoLocalDatetoLocalDate(Object value) Converts the given object to aChronoLocalDate, or returnsnullif unconvertible.private static ChronoLocalDateTime<?>toLocalDateTime(Object value) Converts the given object to aChronoLocalDateTime, or returnsnullif unconvertible.private static LocalTimetoLocalTime(Object value) Converts the given object to aLocalTime, or returnsnullif unconvertible.private static OffsetDateTimetoOffsetDateTime(Object value) Converts the given object to anOffsetDateTime, or returnsnullif unconvertible.Methods inherited from class org.apache.sis.filter.BinaryFunction
apply, applyAsDouble, applyAsLong, getChildren, getExpressions, getParametersMethods inherited from class org.apache.sis.internal.filter.Node
createName, createType, getGeometryLibrary, symbol, toGeometryWrapper, toString, unwrap, warningMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sis.filter.Filter
getExpressions, getOperatorType
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
isMatchingCase
protected final boolean isMatchingCaseSpecifies whether comparisons are case sensitive. -
matchAction
Specifies how the comparisons shall be evaluated for a collection of values. Values can be ALL, ANY or ONE.
-
-
Constructor Details
-
ComparisonFilter
ComparisonFilter(Expression<? super R, ?> expression1, Expression<? super R, ?> expression2, boolean isMatchingCase, MatchAction matchAction) Creates a new comparator.- Parameters:
expression1- the first of the two expressions to be used by this comparator.expression2- the second of the two expressions to be used by this comparator.isMatchingCase- specifies whether comparisons are case sensitive.matchAction- specifies how the comparisons shall be evaluated for a collection of values.
-
-
Method Details
-
getOperand1
Returns the element on the left side of the comparison expression. This is the element at index 0 in the list of expressions.- Specified by:
getOperand1in interfaceBinaryComparisonOperator<R>
-
getOperand2
Returns the element on the right side of the comparison expression. This is the element at index 1 in the list of expressions.- Specified by:
getOperand2in interfaceBinaryComparisonOperator<R>
-
isMatchingCase
public final boolean isMatchingCase()Returns whether comparisons are case sensitive.- Specified by:
isMatchingCasein interfaceBinaryComparisonOperator<R>
-
getMatchAction
Returns how the comparisons are evaluated for a collection of values.- Specified by:
getMatchActionin interfaceBinaryComparisonOperator<R>
-
hashCode
public final int hashCode()Takes in account the additional properties in hash code calculation. -
equals
Takes in account the additional properties in object comparison. -
test
Determines if the test(s) represented by this filter passes with the given operands. Values ofBinaryFunction.expression1andBinaryFunction.expression2can be two single values, or at most one expression can produce a collection. -
evaluate
Compares the given objects. If both values are numerical, then this method delegates to anapplyAs…method. For other kind of objects, this method delegates to acompare(…)method. If the two objects are not of the same type, then the less accurate one is converted to the most accurate type if possible.- Parameters:
left- the first object to compare. Must be non-null.right- the second object to compare. Must be non-null.
-
fromLegacy
Converts a legacyDateobject to an object from thejava.timepackage. We performs this conversion before to compare toDateinstances that are not of the same class, because theDate.compareTo(Date)method in such case is not well defined. -
toInstant
-
toOffsetDateTime
Converts the given object to anOffsetDateTime, or returnsnullif unconvertible. -
toLocalDateTime
Converts the given object to aChronoLocalDateTime, or returnsnullif unconvertible. This method handles the case of legacy SQLTimestampobjects. Conversion may lost timezone information. -
toLocalDate
Converts the given object to aChronoLocalDate, or returnsnullif unconvertible. This method handles the case of legacy SQLDateobjects. Conversion may lost timezone information and time fields. -
toLocalTime
-
ignoringField
Invoked when a conversion cause a field to be ignored. For example if a "date+time" object is compared with a "date" object, the "time" field is ignored. Expected values are:ChronoField.OFFSET_SECONDS: time zone is ignored.ChronoField.SECOND_OF_DAY: time of dat and time zone are ignored.
- Parameters:
field- the field which is ignored.- See Also:
-
number
Converts the boolean result as an integer for use as a return value of theapplyAs…methods. This is a helper class for subclasses. -
fromCompareTo
protected abstract boolean fromCompareTo(int result) Converts the result ofComparable.compareTo(Object). -
compare
Compares two times with time-zone information. Implementations shall not usecompareTo(…)because that method compares more information than desired in order to ensure consistency withequals(…). -
compare
Compares two dates with time-zone information. Implementations shall not usecompareTo(…)because that method compares more information than desired in order to ensure consistency withequals(…). -
compare
Compares two dates without time-of-day and time-zone information. Implementations shall not usecompareTo(…)because that method also compares chronology, which is not desired for the purpose of "is before" or "is after" comparison functions. -
compare
Compares two dates without time-zone information. Implementations shall not usecompareTo(…)because that method also compares chronology, which is not desired for the purpose of "is before" or "is after" comparison functions. -
compare
Compares two dates with time-zone information. Implementations shall not usecompareTo(…)because that method also compares chronology, which is not desired for the purpose of "is before" or "is after" comparison functions. -
applyAsDecimal
Delegates toBigDecimal.compareTo(BigDecimal)and interprets the result withfromCompareTo(int).- Overrides:
applyAsDecimalin classBinaryFunction<R,Object, Object>
-
applyAsInteger
Description copied from class:BinaryFunctionCalculates this function using given operands ofBigIntegertype. If this function is a filter, then this method should returns anIntegervalue 0 or 1 for false or true respectively. Otherwise the result is usually aBigInteger, except for division which may produce other types. This method may returnnullif the operation cannot apply on numbers.- Overrides:
applyAsIntegerin classBinaryFunction<R,Object, Object>
-
applyAsFraction
Description copied from class:BinaryFunctionCalculates this function using given operands ofFractiontype. If this function is a filter, then this method should returns anIntegervalue 0 or 1 for false or true respectively. Otherwise the result is usually aFraction. This method may returnnullif the operation cannot apply on numbers.- Overrides:
applyAsFractionin classBinaryFunction<R,Object, Object>
-