@Test public void shouldFindAllKeysInString() { String trigger = String.format("%s.%s?toupper?join(-)", TRIGGER_PREFIX, KEY_VALUE); String additionalData = String.format("%s.%s.%s#%d.%s?toupper?join(-)", ADDITIONAL_DATA_PREFIX, DATA_PROVIDER_NAME, OBJECT_TYPE, OBJECT_ID, KEY_VALUE); String original = String.format("Trigger: {{%s}} Additional data: {{%s}}", trigger, additionalData); List<KeyInformation> keys = KeyInformation.parseAll(original); assertEquals(2, keys.size()); assertKeyFromTrigger(trigger, keys.get(0)); assertKeyFromAdditionalData(additionalData, keys.get(1)); }
public static List<KeyInformation> parseAll(String input) { List<KeyInformation> keys = new ArrayList<>(); Pattern pattern = Pattern.compile("\\{\\{((.*?))(\\}\\})(?![^(]*\\))"); Matcher matcher = pattern.matcher(isEmpty(input) ? "" : input); while (matcher.find()) { keys.add(KeyInformation.parse(matcher.group(1))); } return keys; }
KeyInformation { public static List<KeyInformation> parseAll(String input) { List<KeyInformation> keys = new ArrayList<>(); Pattern pattern = Pattern.compile("\\{\\{((.*?))(\\}\\})(?![^(]*\\))"); Matcher matcher = pattern.matcher(isEmpty(input) ? "" : input); while (matcher.find()) { keys.add(KeyInformation.parse(matcher.group(1))); } return keys; } }
KeyInformation { public static List<KeyInformation> parseAll(String input) { List<KeyInformation> keys = new ArrayList<>(); Pattern pattern = Pattern.compile("\\{\\{((.*?))(\\}\\})(?![^(]*\\))"); Matcher matcher = pattern.matcher(isEmpty(input) ? "" : input); while (matcher.find()) { keys.add(KeyInformation.parse(matcher.group(1))); } return keys; } private  KeyInformation(String originalKey, String prefix, String key, List<String> manipulations); private  KeyInformation(String originalKey, String prefix, Long objectId, String key, List<String> manipulations); private  KeyInformation(String originalKey, String prefix, String dataProviderName, String objectType,
                           Long objectId, String key, List<String> manipulations); }
KeyInformation { public static List<KeyInformation> parseAll(String input) { List<KeyInformation> keys = new ArrayList<>(); Pattern pattern = Pattern.compile("\\{\\{((.*?))(\\}\\})(?![^(]*\\))"); Matcher matcher = pattern.matcher(isEmpty(input) ? "" : input); while (matcher.find()) { keys.add(KeyInformation.parse(matcher.group(1))); } return keys; } private  KeyInformation(String originalKey, String prefix, String key, List<String> manipulations); private  KeyInformation(String originalKey, String prefix, Long objectId, String key, List<String> manipulations); private  KeyInformation(String originalKey, String prefix, String dataProviderName, String objectType,
                           Long objectId, String key, List<String> manipulations); static KeyInformation parse(String input); static List<KeyInformation> parseAll(String input); boolean fromTrigger(); boolean fromAdditionalData(); boolean fromPostActionParameter(); String getPrefix(); String getOriginalKey(); String getDataProviderName(); String getObjectType(); Long getObjectId(); String getKey(); boolean hasManipulations(); List<String> getManipulations(); @Override int hashCode(); @Override boolean equals(Object obj); }
KeyInformation { public static List<KeyInformation> parseAll(String input) { List<KeyInformation> keys = new ArrayList<>(); Pattern pattern = Pattern.compile("\\{\\{((.*?))(\\}\\})(?![^(]*\\))"); Matcher matcher = pattern.matcher(isEmpty(input) ? "" : input); while (matcher.find()) { keys.add(KeyInformation.parse(matcher.group(1))); } return keys; } private  KeyInformation(String originalKey, String prefix, String key, List<String> manipulations); private  KeyInformation(String originalKey, String prefix, Long objectId, String key, List<String> manipulations); private  KeyInformation(String originalKey, String prefix, String dataProviderName, String objectType,
                           Long objectId, String key, List<String> manipulations); static KeyInformation parse(String input); static List<KeyInformation> parseAll(String input); boolean fromTrigger(); boolean fromAdditionalData(); boolean fromPostActionParameter(); String getPrefix(); String getOriginalKey(); String getDataProviderName(); String getObjectType(); Long getObjectId(); String getKey(); boolean hasManipulations(); List<String> getManipulations(); @Override int hashCode(); @Override boolean equals(Object obj); static final String TRIGGER_PREFIX; static final String ADDITIONAL_DATA_PREFIX; static final String POST_ACTION_PARAMETER_PREFIX; }