@Test public void testSubStringBefore() { SubStringBefore action = new SubStringBefore(); action.setStartIndex(3); action.setEndIndex(null); action.setMatch("blah"); assertNull(StringComplexFieldActions.subStringBefore(action, null)); assertEquals("", StringComplexFieldActions.subStringBefore(action, "")); assertEquals("bar", StringComplexFieldActions.subStringBefore(action, "foobarblah")); assertEquals("foobar", StringComplexFieldActions.subStringBefore(action, "foofoobarblahfoo")); assertEquals("", StringComplexFieldActions.subStringBefore(action, "barblah")); action.setEndIndex(5); assertEquals("ba", StringComplexFieldActions.subStringBefore(action, "foobarblah")); action.setEndIndex(3); assertEquals("", StringComplexFieldActions.subStringBefore(action, "foobarblah")); try { StringComplexFieldActions.subStringBefore(null, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertTrue(true); } try { SubStringBefore err = new SubStringBefore(); StringComplexFieldActions.subStringBefore(err, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertTrue(true); } try { SubStringBefore err = new SubStringBefore(); err.setEndIndex(5); err.setStartIndex(0); StringComplexFieldActions.subStringBefore(err, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertTrue(true); } try { SubStringBefore err = new SubStringBefore(); err.setEndIndex(0); err.setStartIndex(5); StringComplexFieldActions.subStringBefore(err, "aa"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { assertTrue(true); } }
@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()); }
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()); } }
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()); }  }
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()); }  @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); }
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()); }  @AtlasActionProcessor static String append(Append append, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String concatenate(Concatenate concat, List<String> inputs); @AtlasActionProcessor static Boolean endsWith(EndsWith endsWith, String input); @AtlasActionProcessor static String format(Format format, List<Object> input); @AtlasActionProcessor static String genareteUUID(GenerateUUID action); @AtlasActionProcessor static Number indexOf(IndexOf indexOf, String input); @AtlasActionProcessor static Number lastIndexOf(LastIndexOf lastIndexOf, String input); @AtlasActionProcessor static String padStringRight(PadStringRight padStringRight, String input); @AtlasActionProcessor static String padStringLeft(PadStringLeft padStringLeft, String input); @AtlasActionProcessor static String prepend(Prepend action, String input); @AtlasActionProcessor static String replaceAll(ReplaceAll replaceAll, String input); @AtlasActionProcessor static String replaceFirst(ReplaceFirst replaceFirst, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] split(Split split, String input); @AtlasActionProcessor(sourceType = FieldType.ANY) static String[] repeat(Repeat repeat, String input); @AtlasActionProcessor static Boolean startsWith(StartsWith startsWith, String input); @AtlasActionProcessor static String subString(SubString subString, String input); @AtlasActionProcessor static String subStringAfter(SubStringAfter subStringAfter, String input); @AtlasActionProcessor static String subStringBefore(SubStringBefore subStringBefore, String input); static final String STRING_SEPARATOR_REGEX; static final Pattern STRING_SEPARATOR_PATTERN; }