char prefix = ' ';
// First going to check if the key is a primitive or a String. Otherwise, check if it's a transformable.
// If none of those conditions are satisfied, we'll throw an Exception.
Transformer tf;
if (isStringOrPrimitive(key)) {
// Using 'X' for Shorts and 'Y' for Bytes because 'S' is used for Strings and 'B' is being used for Booleans.
if (key instanceof byte[])
return "A:" + Base64.encodeBytes((byte[])key); //todo [anistor] need to profile this and check performance of base64 against raw sequence of byte values
if (key instanceof String)
prefix = 'S';
else if (key instanceof Integer)
prefix = 'I';
else if (key instanceof Boolean)
prefix = 'B';
else if (key instanceof Long)
prefix = 'L';
else if (key instanceof Float)
prefix = 'F';
else if (key instanceof Double)
prefix = 'D';
else if (key instanceof Short)
prefix = 'X';
else if (key instanceof Byte)
prefix = 'Y';
else if (key instanceof Character)
prefix = 'C';
else if (key instanceof UUID)
prefix = 'U';
return prefix + ":" + key;
} else if ((tf = getTransformer(key.getClass())) != null) {
// There is a bit more work to do for this case.
return "T:" + key.getClass().getName() + ":" + tf.toString(key);
} else
throw new IllegalArgumentException("Indexing only works with entries keyed on Strings, primitives " +
"and classes that have the @Transformable annotation - you passed in a " + key.getClass().toString() +
". Alternatively, see org.infinispan.query.SearchManager#registerKeyTransformer");
}