diff options
author | Todor Boev | 2017-06-05 16:23:31 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2017-09-06 08:59:30 +0000 |
commit | 780d9bedcc73cf2daf808b1a16d68565daba871a (patch) | |
tree | e2947d69e24fcae62e0d4fb01e16c81bc6046de6 | |
parent | d2c97e4e8f866fd8233c5ed67a99907b34e00ab4 (diff) | |
download | rt.equinox.p2-780d9bedcc73cf2daf808b1a16d68565daba871a.tar.gz rt.equinox.p2-780d9bedcc73cf2daf808b1a16d68565daba871a.tar.xz rt.equinox.p2-780d9bedcc73cf2daf808b1a16d68565daba871a.zip |
Bug 313553 - Requirement: fix comparisons to match OSGi LDAP spec.I20170906-0815
The non-constant argument can be a collection in which case the
comparison operation must iterate through it testing each element.
Change-Id: I4105bc9b746c4e5767ecc77f80c93a1cbc82d65e
Signed-off-by: Todor Boev <rinsvind@gmail.com>
2 files changed, 43 insertions, 5 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Compare.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Compare.java index 7e958e41d..5ee16f77b 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Compare.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Compare.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.metadata.expression; +import java.util.Collection; import org.eclipse.equinox.p2.metadata.expression.IEvaluationContext; /** @@ -31,7 +32,30 @@ final class Compare extends Binary { } public Object evaluate(IEvaluationContext context) { - int cmpResult = CoercingComparator.coerceAndCompare(lhs.evaluate(context), rhs.evaluate(context)); + Object lhsVal = lhs.evaluate(context); + Object rhsVal = rhs.evaluate(context); + + // Handle collections as per the OSGi LDAP spec + if (lhsVal instanceof Collection<?>) { + for (Object lhsItem : (Collection<?>) lhsVal) { + int cmpResult = CoercingComparator.coerceAndCompare(lhsItem, rhsVal); + + if (cmpResult == 0) { + return equalOK; + } + + if (cmpResult < 0 && compareLess) { + return true; + } + + if (!compareLess) { + return true; + } + } + return false; + } + + int cmpResult = CoercingComparator.coerceAndCompare(lhsVal, rhsVal); return Boolean.valueOf(cmpResult == 0 ? equalOK : (cmpResult < 0 ? compareLess : !compareLess)); } diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Equals.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Equals.java index c318776d8..4992d7980 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Equals.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Equals.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.metadata.expression; +import java.util.Collection; import org.eclipse.equinox.p2.metadata.expression.IEvaluationContext; /** @@ -24,10 +25,23 @@ final class Equals extends Binary { } public Object evaluate(IEvaluationContext context) { - boolean result = CoercingComparator.coerceAndEquals(lhs.evaluate(context), rhs.evaluate(context)); - if (negate) - result = !result; - return Boolean.valueOf(result); + Object lhsVal = lhs.evaluate(context); + Object rhsVal = rhs.evaluate(context); + + // Handle collections as per the OSGi LDAP spec + if (lhsVal instanceof Collection<?>) { + for (Object lhsItem : (Collection<?>) lhsVal) { + boolean eq = CoercingComparator.coerceAndEquals(lhsItem, rhsVal); + + if (eq && !negate) { + return true; + } + } + return negate; + } + + boolean eq = CoercingComparator.coerceAndEquals(lhsVal, rhsVal); + return negate ? !eq : eq; } public int getExpressionType() { |