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 class
The"PropertyIsBetween"
filter.(package private) static final class
The"PropertyIsEqualTo"
(=) filter.(package private) static final class
The"PropertyIsGreaterThan"
(>) filter.(package private) static final class
The"PropertyIsGreaterThanOrEqualTo"
(≥) filter.(package private) static final class
The"PropertyIsLessThan"
(<) filter.(package private) static final class
The"PropertyIsLessThanOrEqualTo"
(≤) filter.(package private) static final class
The"PropertyIsNotEqualTo"
(≠) filter. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final boolean
Specifies whether comparisons are case sensitive.protected final MatchAction
Specifies how the comparisons shall be evaluated for a collection of values.private static final long
For 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 Number
applyAsDecimal
(BigDecimal left, BigDecimal right) Delegates toBigDecimal.compareTo(BigDecimal)
and interprets the result withfromCompareTo(int)
.protected final Number
applyAsFraction
(Fraction left, Fraction right) Calculates this function using given operands ofFraction
type.protected final Number
applyAsInteger
(BigInteger left, BigInteger right) Calculates this function using given operands ofBigInteger
type.protected abstract boolean
compare
(ChronoLocalDate left, ChronoLocalDate right) Compares two dates without time-of-day and time-zone information.protected abstract boolean
compare
(ChronoLocalDateTime<?> left, ChronoLocalDateTime<?> right) Compares two dates without time-zone information.protected abstract boolean
compare
(ChronoZonedDateTime<?> left, ChronoZonedDateTime<?> right) Compares two dates with time-zone information.protected abstract boolean
compare
(OffsetDateTime left, OffsetDateTime right) Compares two dates with time-zone information.protected abstract boolean
compare
(OffsetTime left, OffsetTime right) Compares two times with time-zone information.final boolean
Takes in account the additional properties in object comparison.private boolean
Compares the given objects.protected abstract boolean
fromCompareTo
(int result) Converts the result ofComparable.compareTo(Object)
.private static Temporal
fromLegacy
(Date value) Converts a legacyDate
object to an object from thejava.time
package.final MatchAction
Returns 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 int
hashCode()
Takes in account the additional properties in hash code calculation.private static void
ignoringField
(ChronoField field) Invoked when a conversion cause a field to be ignored.final boolean
Returns whether comparisons are case sensitive.private static Number
number
(boolean result) Converts the boolean result as an integer for use as a return value of theapplyAs…
methods.final boolean
Determines if the test(s) represented by this filter passes with the given operands.(package private) static Instant
Converts the given object to anInstant
, or returnsnull
if unconvertible.private static ChronoLocalDate
toLocalDate
(Object value) Converts the given object to aChronoLocalDate
, or returnsnull
if unconvertible.private static ChronoLocalDateTime
<?> toLocalDateTime
(Object value) Converts the given object to aChronoLocalDateTime
, or returnsnull
if unconvertible.private static LocalTime
toLocalTime
(Object value) Converts the given object to aLocalTime
, or returnsnull
if unconvertible.private static OffsetDateTime
toOffsetDateTime
(Object value) Converts the given object to anOffsetDateTime
, or returnsnull
if unconvertible.Methods inherited from class org.apache.sis.filter.BinaryFunction
apply, applyAsDouble, applyAsLong, getChildren, getExpressions, getParameters
Methods inherited from class org.apache.sis.internal.filter.Node
createName, createType, getGeometryLibrary, symbol, toGeometryWrapper, toString, unwrap, warning
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:
getOperand1
in 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:
getOperand2
in interfaceBinaryComparisonOperator<R>
-
isMatchingCase
public final boolean isMatchingCase()Returns whether comparisons are case sensitive.- Specified by:
isMatchingCase
in interfaceBinaryComparisonOperator<R>
-
getMatchAction
Returns how the comparisons are evaluated for a collection of values.- Specified by:
getMatchAction
in 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.expression1
andBinaryFunction.expression2
can 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 legacyDate
object to an object from thejava.time
package. We performs this conversion before to compare toDate
instances 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 returnsnull
if unconvertible. -
toLocalDateTime
Converts the given object to aChronoLocalDateTime
, or returnsnull
if unconvertible. This method handles the case of legacy SQLTimestamp
objects. Conversion may lost timezone information. -
toLocalDate
Converts the given object to aChronoLocalDate
, or returnsnull
if unconvertible. This method handles the case of legacy SQLDate
objects. 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:
applyAsDecimal
in classBinaryFunction<R,
Object, Object>
-
applyAsInteger
Description copied from class:BinaryFunction
Calculates this function using given operands ofBigInteger
type. If this function is a filter, then this method should returns anInteger
value 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 returnnull
if the operation cannot apply on numbers.- Overrides:
applyAsInteger
in classBinaryFunction<R,
Object, Object>
-
applyAsFraction
Description copied from class:BinaryFunction
Calculates this function using given operands ofFraction
type. If this function is a filter, then this method should returns anInteger
value 0 or 1 for false or true respectively. Otherwise the result is usually aFraction
. This method may returnnull
if the operation cannot apply on numbers.- Overrides:
applyAsFraction
in classBinaryFunction<R,
Object, Object>
-