public class FindByIntervalOperator extends Object
[
{ "user" : "bob", "min" : 0, "max" : 10 },
{ "user" : ["ted", "bob"], "min" : 5, "max" : 7 },
{ "user" : "dimi", "min" : 11, "max" : 20 },
{ "user" : "flo", "min" : 8, "max" : 12 }
]
Running
Tuple result;
findByInterval("intervals").on(6).into(result);
print(result);
produces
[
{"min":5,"color":"blue","user":["ted","bob"],"max":7},
{"min":0,"color":"red","user":"bob","max":10}
]
I.e. what you get is a list of all elements whose interval (here guessed from the min and max
fields) surrounds
the value (6 in this example, matching two elements in this example).
Just like the FindByKeyOperator
operator, you can request the result be reorganised as unions.
Running
Tuple result;
findByInterval(intervals).union().on(6).into(result);
print(result);
produces
{
"color":["red","blue"],
"user":["ted","bob"]
}
Note that with the union, the interval boundaries are not part of the result.
This example is available here : finding.punch. To run it,
use the json files from json.Constructor and Description |
---|
FindByIntervalOperator(Tuple sourceTuple)
Create a
FindByIntervalOperator operator expecting ranges of min max values given either
as arrays of 2 values, i.e. |
FindByIntervalOperator(Tuple sourceTuple,
String intervalKey)
Create a FindInterval operator expecting ranges of min max given in arrays of 2 value, i.e.
|
FindByIntervalOperator(Tuple sourceTuple,
String minKey,
String maxKey)
Create a
FindByIntervalOperator operator expecting ranges of min max, i.e. |
Modifier and Type | Method and Description |
---|---|
FindByIntervalOperator |
between(Tuple tuple)
Look for all Json elements whose interval encloses the value contained in
this tuple.
|
FindByIntervalOperator |
defaultMatch(String defaultMatch)
Set a default value if no match is found.
|
boolean |
into(Tuple into)
Actually perform the query and put the result into 'into'
|
FindByIntervalOperator |
largestFirst()
Request the largest first
|
FindByIntervalOperator |
on(long input)
Set the search value.
|
FindByIntervalOperator |
on(String input)
Set the search value.
|
FindByIntervalOperator |
on(Tuple tuple)
Fire the operator on the provided tuple.
|
FindByIntervalOperator |
smallestFirst()
Request the smallest first
|
FindByIntervalOperator |
union()
Request a unioned result.
|
public FindByIntervalOperator(Tuple sourceTuple, String intervalKey)
{ "interval" : [10, 100] "otherstuffs" : ... }By default the key used to identify the array is "interval". This constructor lets you change that to another field.
sourceTuple
- the input json representing an interval treeintervalKey
- the name of the property providing the intervalpublic FindByIntervalOperator(Tuple sourceTuple, String minKey, String maxKey)
FindByIntervalOperator
operator expecting ranges of min max, i.e.
{ "min" : 10, "max" : 100, "otherstuffs" : ... }By default, the expected property keys are "min" and "max". You can change that to other values with this constructor.
sourceTuple
- the input map representing an interval treeminKey
- the name of the property providing the start intervalmaxKey
- the name of the property providing the start intervalpublic FindByIntervalOperator(Tuple sourceTuple)
FindByIntervalOperator
operator expecting ranges of min max values given either
as arrays of 2 values, i.e.
* { "interval" : [10, 100] "otherstuffs" : ... }or as named fields :
{ "min" : 10, "max" : 100, "otherstuffs" : ... }By default, the expected property keys are "interval", "min" and "max". You can change that using other constructors.
sourceTuple
- the input map representing an interval treepublic FindByIntervalOperator smallestFirst()
public FindByIntervalOperator largestFirst()
public FindByIntervalOperator defaultMatch(String defaultMatch)
defaultMatch
- the default valuepublic FindByIntervalOperator between(Tuple tuple)
tuple
- the tuple holding the long valuepublic FindByIntervalOperator on(Tuple tuple)
tuple
- the value for looking your intervalspublic FindByIntervalOperator on(long input)
input
- the long inputpublic FindByIntervalOperator on(String input)
input
- the long input as a String.public FindByIntervalOperator union()
public boolean into(Tuple into)
into
- the destination tupleCopyright © 2023. All rights reserved.