public class TupleImpl extends AbstractTupleImpl
Modifier and Type | Field and Description |
---|---|
static Object |
nullValue
the null value is used to hold empty values.
|
ancestor, content
Constructor and Description |
---|
TupleImpl(Object o,
Ancestor ancestor)
Return an intermediary or leaf tuple.
|
Modifier and Type | Method and Description |
---|---|
TupleImpl |
add(Object value)
Add a tuple element into a set.
|
TupleImpl |
append(Object value)
Add a abject element at the end of an array.
|
List<Tuple> |
asArray()
Returns an ordered list of elements if the tuple is an array or a set.
|
GeoFeatureTuple |
asGeoShape()
Convert the Tuple in GeoFeatureTuple if the Tuple have the attributs : type and coordinates in content
|
Set<Tuple> |
asSet()
Returns a set of elements.
|
int |
compareTo(Tuple o) |
int |
compareTo(TupleImpl o) |
boolean |
contains(Object element)
This method behaves differently depending on the tuple type.
|
String |
decodeBase64()
Decode a string Tuple already in base64
|
static Object |
dtoPunchLeafValue(Object v)
When inserting leaf values into sets or arrays,
we transform various types into the expected core punch types.
|
String |
dump()
Return a String representation of this tuple.
|
Tuple |
duplicate()
Clone a tuple.
|
Tuple[] |
elements()
Returns an array of elements.
|
void |
empty()
Make a tuple empty.
|
String |
encodeBase64()
Encode a string Tuple into a base64 String
|
boolean |
equals(Object obj)
Two tuples are equals if they are the same object or if they
have the same leaf value.
|
boolean |
equalsOneOf(Tuple resource)
Check if this tuple contains a sub-string.
|
boolean |
exists() |
Tuple |
fromEscapedJson()
This method assumes your tuple holds a string leaf value.
|
Tuple |
get(String key)
Retrieve a child.
|
Tuple |
getByKey(String key)
Return a sub-tuple by key.
|
Tuple |
getElement()
This method returns a new empty array element.
|
Tuple |
getElement(int index)
Retrieve the ith item from this tuple.
|
List<Entry> |
getEntries()
Returns the list of inner property key/values.
|
Iterator<Object> |
getIterator()
This method only works on array tuples.
|
Tuple |
getSingleChild()
Return the single child of this tuple.
|
Object |
getValue()
This method is not visible to application.
|
Collection<Tuple> |
getValues()
Returns the collection of inner property values.
|
boolean |
isEmpty()
Check if a tuple contains some value.
|
boolean |
isLeaf() |
String |
leafAsString()
Return any leaf value as a String.
|
Tuple |
merge(Tuple b)
See mergeWith().
|
Tuple |
mergeWith(Tuple b)
Return a merge of two Tuples A and B recursively.
|
Tuple |
putAll(Map<String,Object> map)
Put all the provided tuple key values in this tuple.
|
void |
remove()
Remove the content of a tuple.
|
TupleImpl |
remove(String key)
Remove an inner child node.
|
boolean |
removeElement(Object value)
Remove a set or array element
|
Tuple |
replaceAllKeys(String regex,
String replacement)
For each inner property Tuple contained in this tuple, replaces each
substring occurence of its key that matches the given regular expression with
the given replacement.
|
Tuple |
replaceAllKeyValues(String regex,
String replacement)
|
Tuple |
select(String... keys)
Given a tuple, return a selection of one or several of its child.
|
Tuple |
set(Object value)
Set a new value to a tuple
|
Tuple |
set(String key,
Object value)
Add a child object to a map tuple
|
Tuple |
setLeaf(Object o)
Deprecated.
|
int |
size()
Return the number of fields in this tuple.
|
void |
skip()
Skip a tuple value.
|
Tuple[] |
splitAsTupleArray(String regex)
Split this string into a Tuple array of the given regular expression.
|
String |
toAsciiJson()
Watchout, if you use this variant, any accent will be transformed into an
ascii unicode representation.
|
String |
toEscapedJson() |
String |
toFlat() |
String |
toJson()
This method preserves non ascii characters.
|
Map<String,Object> |
toMap()
Convert a tuple to a Map.
|
String |
toString()
Return a String representation of the content of this tuple.
|
TupleImpl |
up() |
asBoolean, asBytes, asCollection, asDouble, asDoubleArray, asFloat, asInt, asLong, asLongArray, asString, asString, asStringArray, attach, concat, containsOneOf, containsOneOf, cutPrefix, cutSuffix, endsWith, get, get, get, getAttachment, getCreateTrie, getDeep, getDeepEs, getKeys, getType, hasKey, indexOf, indexOf, indexOf, indexOf, isArray, isBooleanLeaf, isBytesLeaf, isDoubleLeaf, isEquals, isLongLeaf, isRoot, isSet, isStringLeaf, isTuple, length, matches, remove, replace, replaceAll, replaceAllValues, replaceFirst, split, startsWith, substring, substring, toArray, toLowerCase, toUpperCase, trim, tryBoolean, tryBoolean, tryBytes, tryBytes, tryDouble, tryDouble, tryIp, tryIp, tryIpv4, tryIpv4, tryIpv6, tryIpv6, tryLong, tryLong
public static final Object nullValue
public static Object dtoPunchLeafValue(Object v)
Typically ints or shorts become long. Jackson TextNode become strings, etc..
v
- an objectpublic Object getValue()
public Tuple set(String key, Object value)
key
- the new value keyvalue
- the new valuepublic Tuple get(String key)
tuple.get("a").get("b|).get("c").set("hello");Without 'a' being there.
key
- the target value keypublic Tuple set(Object value)
value
- the value to setpublic void remove()
public TupleImpl remove(String key)
key
- the child keypublic TupleImpl append(Object value)
Tuple
value
- the element to appendpublic TupleImpl add(Object value)
Tuple
As expected if you add several times the same element, it will be inserted only once.
This method erases any previous value stored inside the tuple if it was not a set.
value
- the Tuple you want to addpublic boolean removeElement(Object value)
value
- the value to removepublic void empty()
Tuple
public boolean exists()
public Tuple getElement(int index)
Tuple
index
- the index of the element to retrievepublic List<Tuple> asArray()
Tuple
Watch out, if the tuple is a set, the order will be random.
public boolean isEmpty()
Tuple
public Set<Tuple> asSet()
Tuple
@Deprecated public Tuple setLeaf(Object o)
o
- the leaf objectpublic boolean contains(Object element)
Tuple
String.contains(CharSequence)
call.
If your tuple is a set it behaves as a Set.contains(Object)
call. Watchout this method
is inneficient for large sets.
element
- the elementpublic Tuple[] elements()
Tuple
public Tuple getByKey(String key)
Tuple
key
- the sub tuple keypublic Collection<Tuple> getValues()
Tuple
public Iterator<Object> getIterator()
Tuple
public List<Entry> getEntries()
Tuple
public Tuple getElement()
Tuple
public String toString()
Tuple
Watchout : this method was originally documented as returning a JSON
representation. If you need that use instead the or
toAsciiJson()
variants. If you are outside a punchlet, prefer the
TupleFactory.getJsonFromTuple(Tuple)
method and the likes.
This method is completely different than Tuple.asString()
. Use it to
produce a Json.
public String toJson()
Tuple
public String toFlat()
public String toAsciiJson()
Tuple
public int size()
Tuple
public int compareTo(Tuple o)
compareTo
in interface Comparable<Tuple>
compareTo
in class AbstractTupleImpl
public int compareTo(TupleImpl o)
public boolean equals(Object obj)
public boolean isLeaf()
public Tuple mergeWith(Tuple b)
Tuple
TypesA/B | B Leaf | B Array or Set | B Map |
---|---|---|---|
A Leaf | B | B | B |
A Array or Set | A | Fusion A&B | Exception |
A Map | A | Exception | Recursive Merge on Keys |
b
- The Tuple to be merged.public Tuple merge(Tuple b)
Tuple
b
- The Tuple to be merged.public String leafAsString()
Tuple
public Tuple getSingleChild()
Tuple
It is handy to deal with a very common punchplatform use case : receiving logs as single stream/field value. If you know that by configuration you can only receive a root tuple from a Storm PunchBolt as a single valued [streamId][fieldId] tuple, then you can simply write :
tuple = root.getSingleChild().getSingleChild();
public Tuple[] splitAsTupleArray(String regex)
Tuple
regex
- - the delimiting regular expressionpublic Tuple duplicate()
Tuple
public String encodeBase64()
Tuple
Usage examples: String encoded = [a].encodeBase64(); [b] = [a].encodeBase64();
public String decodeBase64()
Tuple
Usage example: String decoded = [a].decodeBase64(); [b] = [a].decodeBase64();
public Tuple select(String... keys)
Tuple
// say input is a metricbeat document with tons of fields including a "metricset" part
// Executing this
Tuple t = input.select("metricset");
// produces a tuple t containing only "metricset", i.e. :
// "metricset" : {
// "module": "system",
// "name": "load",
// "rtt": 29
// }
}
keys
- the key(s) you want to selectpublic String toEscapedJson()
public Tuple fromEscapedJson()
Tuple
public void skip()
Tuple
// root : { "a" : { "b" : { "c" : 3 } } }
root:[a].skip();
// you have root == { "b" : { "c" : 3 } }
public boolean equalsOneOf(Tuple resource)
Tuple
An example will best illustrate how it works. Say you have a domain name in a tuple field, [host][name] that contains for example "www.mydomain-prod.com". Suppose you want to know if that domain name contains one of the following substring
{ "prod", "admin" }
Put your substring in a resource file (say) my-patterns.json. You can then simply write :
if (tuple.equalsOneOf(getResourceTuple("my-patterns"))) {
...
}
resource
- your resource tuple, containing your string atomspublic String dump()
Tuple
This method is completely different than Tuple.toString()
in that it will
not escape inner Strings. Use it to debug the tuple you work with.
public Map<String,Object> toMap()
Tuple
public Tuple replaceAllKeys(String regex, String replacement)
Tuple
regex
- the regular expressionreplacement
- the replacement Stringpublic Tuple replaceAllKeyValues(String regex, String replacement)
Tuple
Tuple.replaceAllKeys(java.lang.String, java.lang.String)
and Tuple.replaceAllValues(java.lang.String, java.lang.String)
in one call.regex
- the regular expressionreplacement
- the replacement Stringpublic GeoFeatureTuple asGeoShape()
Tuple
public TupleImpl up()
Copyright © 2022. All rights reserved.