class StringComplexFieldActions implements AtlasFieldAction {

    @AtlasActionProcessor
    public static String subStringBefore(SubStringBefore subStringBefore, String input) {
        if (input == null || input.length() == 0) {
            return input;
        }

        if (subStringBefore == null || subStringBefore.getStartIndex() == null
                || subStringBefore.getStartIndex() < 0 || subStringBefore.getMatch() == null
                || (subStringBefore.getEndIndex() != null
                        && subStringBefore.getEndIndex() < subStringBefore.getStartIndex())) {
            throw new IllegalArgumentException(
                    "SubStringBefore action must be specified with a positive startIndex and a string to match");
        }

        int idx = input.indexOf(subStringBefore.getMatch());
        if (idx < 0) {
            return input;
        }

        return doSubString(input.substring(0, idx), subStringBefore.getStartIndex(), subStringBefore.getEndIndex());
    }

}