public abstract class AbstractTupleImpl extends Object implements Tuple
| Modifier and Type | Field and Description |
|---|---|
protected Ancestor |
ancestor |
protected Object |
content
the map for holding regular subtuples, if any
|
| Constructor and Description |
|---|
AbstractTupleImpl() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
asBoolean()
Return the leaf value as a boolean.
|
byte[] |
asBytes()
Return the leaf value as a byte array.
|
Collection<Tuple> |
asCollection()
Returns a collection of elements.
|
double |
asDouble()
Return the leaf value as a double.
|
double[] |
asDoubleArray()
Easily get an array of double.
|
float |
asFloat()
Return the leaf value as a float.
|
int |
asInt()
Return the leaf value as an integer.
|
long |
asLong()
Return the leaf value as a long.
|
long[] |
asLongArray()
Easily get an array of long.
|
String |
asString()
Return the leaf value as a String.
|
String |
asString(String fmt,
Object... values)
Return the leaf value as a String.
|
String[] |
asStringArray()
Easily get an array of long.
|
void |
attach(String key,
Object value)
Attach some opaque data to this tuple.
|
int |
compareTo(Tuple o) |
String |
concat(String str)
Concatenates the specified string to the end of this string.
|
boolean |
containsOneOf(String[] strs)
Check if this tuple contains a sub-string.
|
boolean |
containsOneOf(Tuple resource)
Check if this tuple contains one of several sub-string.
|
Tuple |
cutPrefix(String s)
Remove a matching prefix
|
Tuple |
cutSuffix(String s)
Remove a matching prefix
|
boolean |
endsWith(String s)
Return true if the String value of this tuple ends with a given suffix.
|
long |
get(String key,
long defaultValue)
Retrieve a field from a tuple, and if not there return a default.
|
String |
get(String key,
String defaultValue)
Retrieve a field from a tuple, and if not there return a default.
|
Tuple |
get(Tuple key)
Return a sub-tuple by key.
|
Object |
getAttachment(String key)
Retrieve an attachment by key.
|
protected org.ahocorasick.trie.Trie |
getCreateTrie(Tuple resourceTuple,
String key)
Retrieve the Trie attached to a resource tuple, create one if not in there.
|
Tuple |
getDeep(String key)
Return a sub-tuple by key recursively.
|
Tuple |
getDeepEs(String key)
Return a sub-tuple by key recursively.
|
List<String> |
getKeys()
Returns the list of inner property keys.
|
String |
getType()
return a String representation of the type of the value contained in a tuple.
|
boolean |
hasKey(String key) |
int |
indexOf(char ch)
String operation only.
|
int |
indexOf(char ch,
int fromIndex)
String operation only.
|
int |
indexOf(String str)
String operation only.
|
int |
indexOf(String str,
int fromIndex)
String operation only.
|
boolean |
isArray()
Return true if this tuple contains an array value
|
boolean |
isBooleanLeaf()
Check if a tuple contains a long value.
|
boolean |
isBytesLeaf()
Check if a tuple contains a Byte array value.
|
boolean |
isDoubleLeaf()
Check if a tuple contains a double value.
|
boolean |
isEquals(Object o)
Check if a tuple contains a leaf value and if it is equal to a given value
|
boolean |
isLongLeaf()
Check if a tuple contains a long value.
|
boolean |
isRoot()
Return true if this tuple is a root one.
|
boolean |
isSet()
Check if this tuple holds a set
|
boolean |
isStringLeaf()
Check if a tuple contains a String value.
|
boolean |
isTuple()
Return true if this tuple contains a tuple value
|
int |
length()
String API, returns the length of a String leaf Tuple.
|
boolean |
matches(String regex)
String API : Tells whether or not this string matches the given regular
expression.
|
boolean |
remove(Tuple element)
Set operation: remove an element from a set.
|
String |
replace(char oldChar,
char newChar)
Returns a string resulting from replacing all occurrences of oldChar in this
string with newChar.
|
String |
replaceAll(String regex,
String replacement)
Replaces each substring occurence of this string that matches the given
regular expression
regex with the given replacement. |
Tuple |
replaceAllValues(String regex,
String replacement)
For each inner String value contained in this tuple, replaces each substring
occurence that matches the given regular expression with the given
replacement.
|
String |
replaceFirst(String regex,
String replacement)
Replaces the first substring of this string that matches the given regular
expression with the given replacement.
|
String[] |
split(String s)
Splits this string around matches of the given regular expression.
|
boolean |
startsWith(String s)
Split a string tuple.
|
String |
substring(int beginIndex) |
String |
substring(int beginIndex,
int endIndex) |
protected static <T> T[] |
toArray(T... items) |
Tuple |
toLowerCase() |
Tuple |
toUpperCase() |
String |
trim()
Methods inherited from plain Strings.
|
Boolean |
tryBoolean()
Try to parse the given value as Boolean.
|
boolean |
tryBoolean(boolean b)
Try to parse as Boolean or return a default value.
|
byte[] |
tryBytes()
Try to parse the given value as Byte array.
|
byte[] |
tryBytes(byte[] d)
Try to parse as Byte array or return a default value.
|
Double |
tryDouble()
Try to parse the given value as Double.
|
double |
tryDouble(double d)
Try to parse as Double or return a default value.
|
String |
tryIp()
Efficiently check for valid ip address.
|
String |
tryIp(String defaultValue)
Efficiently check for a valid ip address.
|
String |
tryIpv4()
Efficiently check for an dot decimal ipv4 ip address.
|
String |
tryIpv4(String defaultValue)
Efficiently check for an dot decimal ipv4 ip address.
|
String |
tryIpv6()
Efficiently check for an dot decimal ipv6 ip address.
|
String |
tryIpv6(String defaultValue)
Efficiently check for an dot decimal ipv6 ip address.
|
Long |
tryLong()
Try to parse the given value as Long.
|
long |
tryLong(long l)
Try to parse as Long or return default.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitadd, append, asArray, asGeoShape, asSet, contains, decodeBase64, dump, duplicate, elements, empty, encodeBase64, equalsOneOf, exists, fromEscapedJson, get, getByKey, getElement, getElement, getEntries, getIterator, getSingleChild, getValues, isEmpty, isLeaf, leafAsString, merge, mergeWith, putAll, remove, remove, removeElement, replaceAllKeys, replaceAllKeyValues, select, set, set, size, skip, splitAsTupleArray, toAsciiJson, toEscapedJson, toFlat, toJson, toMap, toStringprotected Object content
protected Ancestor ancestor
public void attach(String key, Object value)
TupleTuple.getAttachment(String). Attachments are transient data, they survive
as long as the holding tuple survives. Besides, they will not appear in the
Tuple.toString() String representation of this tuple.public Object getAttachment(String key)
TuplegetAttachment in interface Tuplekey - the attachment keypublic boolean asBoolean()
Tuplepublic Boolean tryBoolean()
TupletryBoolean in interface Tuplepublic boolean tryBoolean(boolean b)
TupletryBoolean in interface Tupleb - the default value@SafeVarargs protected static <T> T[] toArray(T... items)
public double[] asDoubleArray()
TupleLongs are converted to doubles, String also as long as they represent a valid double number.
If your tuple contains a single value an array of size 1 will be returned.
asDoubleArray in interface Tuplepublic long[] asLongArray()
TupleLongs are converted to doubles, String also as long as they represent a valid double number.
If your tuple contains a single value an array of size 1 will be returned.
asLongArray in interface Tuplepublic String[] asStringArray()
TupleLongs are converted to doubles, String also as long as they represent a valid double number.
If your tuple contains a single value an array of size 1 will be returned.
asStringArray in interface Tuplepublic double asDouble()
Tuplepublic Double tryDouble()
Tuplepublic double tryDouble(double d)
Tuplepublic float asFloat()
Tuplepublic int asInt()
Tuplepublic long asLong()
Tuplepublic Long tryLong()
Tuplepublic long tryLong(long l)
Tuplepublic String tryIpv4()
TupleThis method will return a dotted numeric representation of convertible ip addresses.
// this statement has no effect if there is no ipv4 value in
// [message][callerIpAddress]
[logs][log][client][ip] = [message][callerIpAddress].tryIpv4();
public String tryIp(String defaultValue)
TupleThis method will return a dotted numeric representation of convertible ip addresses.
// this statement has no effect if there is no ipv4 value in
// [message][callerIpAddress]
[logs][log][client][ip] = [message][callerIpAddress].tryIp("0.0.0.0");
public String tryIp()
TupleThis method will return a dotted numeric representation of convertible ip addresses.
// this statement has no effect if there is no ipv4 value in
// [message][callerIpAddress]
[logs][log][client][ip] = [message][callerIpAddress].tryIp();
public String tryIpv4(String defaultValue)
TupleThis method will return a dotted numeric representation of convertible ip addresses.
// this statement has no effect if there is no ipv4 value in
// [message][callerIpAddress]
[logs][log][client][ip] = [message][callerIpAddress].tryIpv4("0.0.0.0");
public String tryIpv6()
TupleThis method will return a dotted numeric representation of convertible ip addresses.
// this statement has no effect if there is no ipv4 value in
// [message][callerIpAddress]
[logs][log][client][ipv6] = [message][callerIpAddress].tryIpv6();
public String tryIpv6(String defaultValue)
TupleThis method will return a dotted numeric representation of convertible ip addresses.
// this statement has no effect if there is no ipv4 value in
// [message][callerIpAddress]
[logs][log][client][ipv6] = [message][callerIpAddress].tryIpv6("::0");
public String asString()
Tuplepublic String asString(String fmt, Object... values)
TupleThe additional argument will be used to format an error message in case an exception is raised. This is handy to write log parsers that report clear errors.
public String concat(String str)
TupleIf the length of the argument string is 0, then this String object is returned. Otherwise, a String object is returned that represents a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.
public Tuple getDeep(String key)
Tuplepublic Tuple getDeepEs(String key)
Tuplepublic Tuple get(Tuple key)
TupleThis variant expect the string key to be contained in a tuple. It will convert the leaf value to a string, and fail if it is not a leaf value.
public List<String> getKeys()
Tuplepublic boolean hasKey(String key)
public int indexOf(char ch)
Tuplepublic int indexOf(char ch,
int fromIndex)
Tuplepublic int indexOf(String str)
Tuplepublic int indexOf(String str, int fromIndex)
Tuplepublic boolean isArray()
Tuplepublic boolean isBooleanLeaf()
TupleisBooleanLeaf in interface Tuplepublic boolean isDoubleLeaf()
TupleisDoubleLeaf in interface Tuplepublic boolean isEquals(Object o)
Tuplepublic boolean isLongLeaf()
TupleisLongLeaf in interface Tuplepublic boolean isRoot()
Tuplepublic boolean isSet()
Tuplepublic boolean isStringLeaf()
TupleisStringLeaf in interface Tuplepublic boolean isBytesLeaf()
TupleisBytesLeaf in interface Tuplepublic boolean isTuple()
Tuplepublic int length()
Tuplepublic boolean matches(String regex)
Tuplepublic boolean remove(Tuple element)
Tuplepublic String replace(char oldChar, char newChar)
TupleIf the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned. Otherwise, a String object is returned that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar. Examples:
"mesquite in your cellar".replace('e', 'o')
returns "mosquito in your collar"
"the war of baronets".replace('r', 'y')
returns "the way of bayonets"
"sparring with a purple porpoise".replace('p', 't')
returns "starring with a turtle tortoise"
"JonL".replace('q', 'x') returns "JonL" (no change)
public String replaceAll(String regex, String replacement)
Tupleregex with the given replacement. This
methods only acts on the Tuple String value. It has no effect if the Tuple
contains somethng else than a String.
Check the Tuple.replaceAllValues(java.lang.String, java.lang.String), Tuple.replaceAllKeys(java.lang.String, java.lang.String) or Tuple.replaceAllKeyValues(java.lang.String, java.lang.String) for recursive versions that do the job on all keys and?or values contained in a nested Tuple.
replaceAll in interface Tupleregex - the regular expressionreplacement - the replacement Stringpublic Tuple replaceAllValues(String regex, String replacement)
TuplereplaceAllValues in interface Tupleregex - the regular expressionreplacement - the replacement Stringpublic String replaceFirst(String regex, String replacement)
TuplereplaceFirst in interface Tupleregex - the regular expressionreplacement - the replacement Stringpublic String substring(int beginIndex)
public String substring(int beginIndex, int endIndex)
public Tuple toLowerCase()
toLowerCase in interface Tuplepublic Tuple cutPrefix(String s)
Tuplepublic Tuple cutSuffix(String s)
Tuplepublic boolean startsWith(String s)
TuplestartsWith in interface Tuples - the string valuepublic String[] split(String s)
Tuplepublic boolean endsWith(String s)
Tuplepublic Tuple toUpperCase()
toUpperCase in interface Tuplepublic String trim()
Tuple
See String.trim().
public String get(String key, String defaultValue)
Tuplepublic long get(String key, long defaultValue)
Tuplepublic Collection<Tuple> asCollection()
TupleasCollection in interface Tuplepublic String getType()
Tuplepublic boolean containsOneOf(String[] strs)
TupleHere is a typical usage :
if (tuple.containsOneOf("CNN", "FOX", "TF1")) {
...
}
Should you need to ignore the case :
if (tuple.toLowerCase().containsOneOf("cnn", "fox", "tf1")) {
...
}
containsOneOf in interface Tuplestrs - the list of String to check forpublic boolean containsOneOf(Tuple resource)
TuplePlease note that this tuple must be a Leaf tuple, more precisely of type String for this to work. Otherwise, you will get false.
Use this variant only if your set of substrings does never change. It is the most efficient in particular if you have many sub-strings to check for.
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 :
Tuple tuple = [host][name]
...
if (tuple.containsOneOf(getResourceTuple("my-patterns"))) {
...
}
containsOneOf in interface Tupleresource - your resource tuple, containing your string atomspublic int compareTo(Tuple o)
compareTo in interface Comparable<Tuple>protected org.ahocorasick.trie.Trie getCreateTrie(Tuple resourceTuple, String key)
resourceTuple - the resource Tuple, remember these are static and attached to a punchlet contextkey - the key for retrieving the triepublic byte[] asBytes()
Tuplepublic byte[] tryBytes()
TupleCopyright © 2022. All rights reserved.