NB5 Docs► Reference Section► Binding Functions▼ conversion functions 🖺

Conversion functions simply allow values of one type to be converted to another type in an obvious way.


Create a ByteBuffer from a long input based on a provided size function. As a 'Sized' function, the first argument is a function which determines the size of the resulting ByteBuffer. As a 'Hashed' function, the input value is hashed again before being used as value.


Convert the contents of the input ByteBuffer to a String as hexadecimal. This function is retained to avoid breaking previous workload definitions, but you should use {@link ToHexString} instead.


Combiner - a combinatoric toolkit for NoSQLBench


Combiner is the core implementation of a combinatoric toolkit which is used by other NoSQLBench functions in a more type-specific way. It allows for a common approach to encoding unique values across a range of dimensions (which can be non-uniform) with an affine mapping between different forms of data.


The specifier required by the constructor is a way to specify a range of character sets, each representing both the per-value labeling as well as the radix of each position in the associated index, value, or character position. Each position is delimited from the others with commas or semicolons. Each position can be either a single printable character or a range of characters separated by '-'. Optionally, you can repeat a position with a multiplier in the form of '*n' where n is any valid number.


The specifier is parsed into a non-uniform radix model, where the characters for each position represent a numerical encoding. As such, the cardinalities of each position are multiplied together to determine the total cardinality of the specified pattern. Any total cardinality below Long.MAX_VALUE, or 9,223,372,036,854,775,807 is allowed, and any combinations which would overflow this value will throw an error.

Value Function

The function provided in the constructor is used to symbolically map the characters in the encoding string to a value of any type. The value function will be called with number of distinct values up the the cardinality of the largest position in the radix model. For example, a specifier of `A-Za-z0-9` would provide an input range from 0 to 61 inclusive to the value function. It is the combination of positions and unique values which provides the overall cardinality, although the value function itself is responsible for the relatively lower cardinality elements which are combined together to create higher-cardinality value arrays.

Types and Forms

Each form represents one way of seeing the data for a given cycle:

  1. ordinal (long) - also known as the cycle, or input. This is an enumeration of all distinct combinations.
  2. indexes (int[]) - an array of indexes, one for each position in the specifier and thus each element in the array or character in the encoding.
  3. encoding (String) - a string which encodes the ordinal and the indexes in a convenient label which is unique within the range of possible values.
  4. (values) array (T[]) - An array of the type T which can be provided via a mapping function. This is a mapping from the indexes through the provided value function.

Mapping between forms

The array value can be derived with {@link #apply(long)}, {@link #getArray(int[])} (int[])}, and {@link #getArray(String)}, given ordinal, indexes, or encoding as a starting point, respectively. This all ultimately use the one-way function which you provide, thus you can't go from array form to the others.

Mapping between the other three is fairly trivial:

This makes it easy to derive textual identifiers for specific combinations of elements such as a vector, use them for cross-checks such as with correctness testing, and represent specific test values in a very convenient form within deterministic testing harnesses like NoSQLBench.

@param The generic type of the value which is mapped into each array position

@param spec The string specifier, as explained in {@link Combiner} docs. @param elementFunction The function that indexes into a unique population of T elements @param elementClazz The component type for the values array which are produced by {@link #apply(long)}


Formats a floating point value to a string using the java.text.DecimalFormat


Computes the digest of the ByteBuffer on input and stores it in the output ByteBuffer. The digestTypes available are: MD2 MD5 SHA-1 SHA-224 SHA-256 SHA-384 SHA-512 SHA3-224 SHA3-256 SHA3-384 SHA3-512


For comprehensive docs on how this works, please see the javadocs for {@link Combiner}<T>. This class is merely a primitive specialization.

@param spec The string specifier, as explained in {@link DoubleCombiner} docs. @param elementFunction The function that indexes into a unique population of T elements


Convert the input double value to the closest float value.


Escape all special characters which are required to be escaped when found within JSON content according to the JSON spec

\b  Backspace (ascii code 08)
\f  Form feed (ascii code 0C)
\n  New line
\r  Carriage return
\t  Tab
\"  Double quote
\\  Backslash character
\/  Forward slash


Combine functions into one.

This function allows you to combine multiple other functions into one. This is often useful for constructing more sophisticated recipes, when you don't have the ability to use control flow or non-functional forms.

The functions will be stitched together using the same logic that VirtData uses when combining flows outside functions. That said, if the functions selected are not the right ones, then it is possible to end up with the wrong data type at the end. To remedy this, be sure to add input and output qualifiers, like long-> or ->String where appropriate, to ensure that VirtData selects the right functions within the flow.


Apply the Java String.format method to an incoming object. @see Java 8 String.format(...) javadoc Note: This function can often be quite slow, so more direct methods are generally preferrable.


encode HTML Entities


encode HTML Entities


Convert the input long value to a byte, with negative values masked away.


Convert the input value from long to short.



Return a {@code BigDecimal} value as the result of modulo division with the specified divisor.


Return a {@code BigInteger} value as the result of modulo division with the specified divisor.


Return a boolean value as the result of modulo division with the specified divisor.


Return a byte value as the result of modulo division with the specified divisor.


Return a boolean value as the result of modulo division with the specified divisor.


Compress the input using snappy compression


This function wraps an epoch time in milliseconds into a String as specified in the format. The valid formatters are documented at @see DateTimeFormat API Docs


Computes the Base64 representation of the byte image of the input long.


Convert values to BigDecimals at configurable scale or precision.

ToBigDecimal(...) functions which take whole-numbered inputs may have a scale parameter or a custom MathContext, but not both. The scale parameter is not supported for String or Double input forms.


Convert the input value to a {@code BigInteger}


Convert the input value to a {@code boolean}


Convert the input value to a {@code Byte}.


Convert the input value to a {@code ByteBuffer}


Convert the input string to a character buffer


Convert the input value into a {@link CqlDuration} by reading the input as total nanoseconds, assuming 30-month days.


Create a double by converting values. This function works in the following modes:


Convert the input value into a float. Create a float by converting values. This function works in the following modes:


Converts the input ByteBuffer to a hexadecimal String.


Convert the input value to a {@code InetAddress}


Convert the input value to an int with long modulus remainder. If the scale is chosen, then the value is wrapped at this value. Otherwise, {@link Integer#MAX_VALUE} is used.


Convert the input object to a JSON string with Gson.


Convert the input object to a JSON string with Gson, with pretty printing enabled.


Convert the input value to a long.


Converts the byte image of the input long to a MD5 digest in ByteBuffer form. Deprecated usage due to unsafe MD5 digest. Replaced with DigestToByteBuffer with MD5 when absolutely needed for existing NB tests. However, stronger encryption algorithms (e.g. SHA-256) are recommended due to MD5's limitations.


Convert the input value to a short.


Converts the input to the most obvious string representation with String.valueOf(...). Forms which accept a function will evaluate that function first and then apply String.valueOf() to the result.


This function creates a non-random UUID in the type 4 version (Random). It always puts the same value in the MSB position of the UUID format. The input value is put in the LSB position. This function is suitable for deterministic testing of scenarios which depend on type 4 UUIDs, but without the mandated randomness that makes testing difficult. Just be aware that the MSB will always contain value 0x0123456789ABCDEFL unless you specify a different long value to pre-fill it with.


URLDecode string data

@param charset A valid character set name from {@link Charset}


URLEncode string data

@param charset A valid character set name from {@link Charset}

Back to top