All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.event.ruler.input.SuffixParser Maven / Gradle / Ivy

Go to download

Event Ruler is a Java library that allows matching Rules to Events. An event is a list of fields, which may be given as name/value pairs or as a JSON object. A rule associates event field names with lists of possible values. There are two reasons to use Ruler: 1/ It's fast; the time it takes to match Events doesn't depend on the number of Rules. 2/ Customers like the JSON "query language" for expressing rules.

There is a newer version: 1.8.1
Show newest version
package software.amazon.event.ruler.input;

import java.nio.charset.StandardCharsets;

/**
 * A parser to be used specifically for suffix rules.
 *
 * This undoes the `reverse()` from {@code software.amazon.event.ruler.Patterns} intentionally
 * to ensure we can correctly reverse utf-8 characters with 2+ bytes like '大' and '雨'.
 */
public class SuffixParser implements StringValueParser {

    SuffixParser() { }

    @Override
    public InputCharacter[] parse(String value) {
        final byte[] utf8bytes = new StringBuilder(value).reverse()
                .toString().getBytes(StandardCharsets.UTF_8);
        final InputCharacter[] result = new InputCharacter[utf8bytes.length];
        for (int i = 0; i < utf8bytes.length; i++) {
            byte utf8byte = utf8bytes[utf8bytes.length - i - 1];
            result[i] = new InputByte(utf8byte);
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy