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, wait
add, 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, toString
protected Object content
protected Ancestor ancestor
public void attach(String key, Object value)
Tuple
Tuple.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)
Tuple
getAttachment
in interface Tuple
key
- the attachment keypublic boolean asBoolean()
Tuple
public Boolean tryBoolean()
Tuple
tryBoolean
in interface Tuple
public boolean tryBoolean(boolean b)
Tuple
tryBoolean
in interface Tuple
b
- the default value@SafeVarargs protected static <T> T[] toArray(T... items)
public double[] asDoubleArray()
Tuple
Longs 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 Tuple
public long[] asLongArray()
Tuple
Longs 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 Tuple
public String[] asStringArray()
Tuple
Longs 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 Tuple
public double asDouble()
Tuple
public Double tryDouble()
Tuple
public double tryDouble(double d)
Tuple
public float asFloat()
Tuple
public int asInt()
Tuple
public long asLong()
Tuple
public Long tryLong()
Tuple
public long tryLong(long l)
Tuple
public String tryIpv4()
Tuple
This 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)
Tuple
This 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()
Tuple
This 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)
Tuple
This 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()
Tuple
This 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)
Tuple
This 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()
Tuple
public String asString(String fmt, Object... values)
Tuple
The 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)
Tuple
If 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)
Tuple
public Tuple getDeepEs(String key)
Tuple
public Tuple get(Tuple key)
Tuple
This 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()
Tuple
public boolean hasKey(String key)
public int indexOf(char ch)
Tuple
public int indexOf(char ch, int fromIndex)
Tuple
public int indexOf(String str)
Tuple
public int indexOf(String str, int fromIndex)
Tuple
public boolean isArray()
Tuple
public boolean isBooleanLeaf()
Tuple
isBooleanLeaf
in interface Tuple
public boolean isDoubleLeaf()
Tuple
isDoubleLeaf
in interface Tuple
public boolean isEquals(Object o)
Tuple
public boolean isLongLeaf()
Tuple
isLongLeaf
in interface Tuple
public boolean isRoot()
Tuple
public boolean isSet()
Tuple
public boolean isStringLeaf()
Tuple
isStringLeaf
in interface Tuple
public boolean isBytesLeaf()
Tuple
isBytesLeaf
in interface Tuple
public boolean isTuple()
Tuple
public int length()
Tuple
public boolean matches(String regex)
Tuple
public boolean remove(Tuple element)
Tuple
public String replace(char oldChar, char newChar)
Tuple
If 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)
Tuple
regex
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 Tuple
regex
- the regular expressionreplacement
- the replacement Stringpublic Tuple replaceAllValues(String regex, String replacement)
Tuple
replaceAllValues
in interface Tuple
regex
- the regular expressionreplacement
- the replacement Stringpublic String replaceFirst(String regex, String replacement)
Tuple
replaceFirst
in interface Tuple
regex
- the regular expressionreplacement
- the replacement Stringpublic String substring(int beginIndex)
public String substring(int beginIndex, int endIndex)
public Tuple toLowerCase()
toLowerCase
in interface Tuple
public Tuple cutPrefix(String s)
Tuple
public Tuple cutSuffix(String s)
Tuple
public boolean startsWith(String s)
Tuple
startsWith
in interface Tuple
s
- the string valuepublic String[] split(String s)
Tuple
public boolean endsWith(String s)
Tuple
public Tuple toUpperCase()
toUpperCase
in interface Tuple
public String trim()
Tuple
See String.trim()
.
public String get(String key, String defaultValue)
Tuple
public long get(String key, long defaultValue)
Tuple
public Collection<Tuple> asCollection()
Tuple
asCollection
in interface Tuple
public String getType()
Tuple
public boolean containsOneOf(String[] strs)
Tuple
Here 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 Tuple
strs
- the list of String to check forpublic boolean containsOneOf(Tuple resource)
Tuple
Please 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 Tuple
resource
- 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()
Tuple
public byte[] tryBytes()
Tuple
Copyright © 2022. All rights reserved.