Or
See javadoc - uk.gov.gchq.koryphe.impl.predicate.Or
Available since Koryphe version 1.0.0
Returns true if any of the predicates are true
Examples
Is less than 2 equal to 5 or is more than 10
When using an Or predicate with a single selected value you can just use the constructor new Or(predicates))'
final Or function = new Or<>(
new IsLessThan(2),
new IsEqual(5),
new IsMoreThan(10)
);
{
"class" : "uk.gov.gchq.koryphe.impl.predicate.Or",
"predicates" : [ {
"class" : "IsLessThan",
"orEqualTo" : false,
"value" : 2
}, {
"class" : "IsEqual",
"value" : 5
}, {
"class" : "IsMoreThan",
"orEqualTo" : false,
"value" : 10
} ]
}
{
"class" : "uk.gov.gchq.koryphe.impl.predicate.Or",
"predicates" : [ {
"class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan",
"orEqualTo" : false,
"value" : 2
}, {
"class" : "uk.gov.gchq.koryphe.impl.predicate.IsEqual",
"value" : 5
}, {
"class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan",
"orEqualTo" : false,
"value" : 10
} ]
}
g.Or(
predicates=[
g.IsLessThan(
value=2,
or_equal_to=False
),
g.IsEqual(
value=5
),
g.IsMoreThan(
value=10,
or_equal_to=False
)
]
)
Input type:
uk.gov.gchq.koryphe.signature.Signature$UnknownGenericType
Example inputs:
Input Type | Input | Result |
---|---|---|
java.lang.Integer | 1 | true |
java.lang.Integer | 2 | false |
java.lang.Integer | 3 | false |
java.lang.Integer | 5 | true |
java.lang.Integer | 15 | true |
java.lang.Long | 1 | false |
java.lang.Long | 3 | false |
java.lang.Long | 5 | false |
Is less than 2 equal to 5 or is more than 10
When using an Or predicate with a single selected value you can just use the constructor new Or(predicates))'
final Or function = new Or<>(
new IsLessThan(2),
new IsEqual(5),
new IsMoreThan(10)
);
{
"class" : "uk.gov.gchq.koryphe.impl.predicate.Or",
"predicates" : [ {
"class" : "IsLessThan",
"orEqualTo" : false,
"value" : 2
}, {
"class" : "IsEqual",
"value" : 5
}, {
"class" : "IsMoreThan",
"orEqualTo" : false,
"value" : 10
} ]
}
{
"class" : "uk.gov.gchq.koryphe.impl.predicate.Or",
"predicates" : [ {
"class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan",
"orEqualTo" : false,
"value" : 2
}, {
"class" : "uk.gov.gchq.koryphe.impl.predicate.IsEqual",
"value" : 5
}, {
"class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan",
"orEqualTo" : false,
"value" : 10
} ]
}
g.Or(
predicates=[
g.IsLessThan(
value=2,
or_equal_to=False
),
g.IsEqual(
value=5
),
g.IsMoreThan(
value=10,
or_equal_to=False
)
]
)
Input type:
uk.gov.gchq.koryphe.signature.Signature$UnknownGenericType
Example inputs:
Input Type | Input | Result |
---|---|---|
java.lang.Integer | 1 | true |
java.lang.Integer | 2 | false |
java.lang.Integer | 3 | false |
java.lang.Integer | 5 | true |
java.lang.Integer | 15 | true |
java.lang.Long | 1 | false |
java.lang.Long | 3 | false |
java.lang.Long | 5 | false |
First item is less than 2 or second item is more than 10
When using an Or predicate with multiple selected values, you need to use the Or.Builder to build your Or predicate, using .select() then .execute(). When selecting values in the Or.Builder you need to refer to the position in the input array. I.e to use the first value use position 0 - select(0).You can select multiple values to give to a predicate like isXLessThanY, this is achieved by passing 2 positions to the select method - select(0, 1)
final Or function = new Or.Builder()
.select(0)
.execute(new IsLessThan(2))
.select(1)
.execute(new IsMoreThan(10))
.build();
{
"class" : "uk.gov.gchq.koryphe.impl.predicate.Or",
"predicates" : [ {
"class" : "IntegerTupleAdaptedPredicate",
"selection" : [ 0 ],
"predicate" : {
"class" : "IsLessThan",
"orEqualTo" : false,
"value" : 2
}
}, {
"class" : "IntegerTupleAdaptedPredicate",
"selection" : [ 1 ],
"predicate" : {
"class" : "IsMoreThan",
"orEqualTo" : false,
"value" : 10
}
} ]
}
{
"class" : "uk.gov.gchq.koryphe.impl.predicate.Or",
"predicates" : [ {
"class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate",
"selection" : [ 0 ],
"predicate" : {
"class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan",
"orEqualTo" : false,
"value" : 2
}
}, {
"class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate",
"selection" : [ 1 ],
"predicate" : {
"class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan",
"orEqualTo" : false,
"value" : 10
}
} ]
}
g.Or(
predicates=[
g.NestedPredicate(
selection=[
0
],
predicate=g.IsLessThan(
value=2,
or_equal_to=False
)
),
g.NestedPredicate(
selection=[
1
],
predicate=g.IsMoreThan(
value=10,
or_equal_to=False
)
)
]
)
Input type:
uk.gov.gchq.koryphe.signature.Signature$UnknownGenericType
Example inputs:
Input Type | Input | Result |
---|---|---|
[java.lang.Integer, java.lang.Integer] | [1, 15] | true |
[java.lang.Integer, java.lang.Integer] | [1, 1] | true |
[java.lang.Integer, java.lang.Integer] | [15, 15] | true |
[java.lang.Integer, java.lang.Integer] | [15, 1] | false |
[java.lang.Long, java.lang.Long] | [1, 15] | false |
[java.lang.Integer] | [1] | true |