### Question:
GroupingRequiredFilterFunctions { public static Collection<?> getGroupsForMatchesInGroup(Object... args) { Set<String> groups = new HashSet<>(); int positionFromRight = 0; if (args.length % 2 != 0) { Object lastArgument = args[args.length - 1]; positionFromRight = Integer.parseInt(lastArgument.toString()); } Collection<ValueTuple> leftSideMatches; Collection<ValueTuple> allMatches = new HashSet<>(); Object fieldValue1 = args[0]; String regex = args[1].toString(); if (fieldValue1 instanceof Iterable) { leftSideMatches = EvaluationPhaseFilterFunctions.getAllMatches((Iterable) fieldValue1, regex); } else { leftSideMatches = EvaluationPhaseFilterFunctions.getAllMatches(fieldValue1, regex); } for (ValueTuple currentMatch : leftSideMatches) { String matchFieldName = ValueTuple.getFieldName(currentMatch); String context = EvaluationPhaseFilterFunctions.getMatchToRightOfPeriod(matchFieldName, positionFromRight); if (context != null && !context.isEmpty()) { groups.add(context); } for (int i = 2; i < args.length; i++) { if (args[i] instanceof Iterable) { boolean contextHasMatch = false; for (Object fieldValue : (Iterable) args[i]) { if (manageGroupsForMatchesInGroupRemainingArgs(fieldValue, args[i + 1].toString(), context, allMatches, currentMatch)) { contextHasMatch = true; } } if (!contextHasMatch) { groups.remove(context); } } else if (args[i] instanceof ValueTuple) { if (!manageGroupsForMatchesInGroupRemainingArgs(args[i], args[i + 1].toString(), context, allMatches, currentMatch)) { groups.remove(context); } } } } if (args.length == 2) { allMatches.addAll(leftSideMatches); } else if (allMatches.size() < args.length / 2) { allMatches.clear(); groups.clear(); } if (log.isTraceEnabled()) { log.trace("getGroupsForMatchesInGroup(" + Arrays.toString(args) + ") returning " + groups); } return groups; }  static Collection<?> getGroupsForMatchesInGroup(Object... args); static Collection<?> matchesInGroup(Object... args); static Collection<?> matchesInGroupLeft(Object... args); static Collection<ValueTuple> atomValuesMatch(Object... fields); static Collection<ValueTuple> atomValuesMatch(Iterable<?>... fields); static final String GROUPING_REQUIRED_FUNCTION_NAMESPACE; }### Answer:
@Test public void testGetGroupsForMatchesInGroup() { Collection<?> groups = GroupingRequiredFilterFunctions.getGroupsForMatchesInGroup( makeValueTuple("ALPHA.1,BAR,bar"), "bar", makeValueTuple("GAMMA.1,BAZ,baz"), "baz"); Assert.assertTrue(groups.size() == 1); Assert.assertTrue(groups.contains("1")); groups = GroupingRequiredFilterFunctions.getGroupsForMatchesInGroup( Collections.singleton(makeValueTuple("ALPHA.1,BAR,bar")), "bar", Collections.singleton(makeValueTuple("GAMMA.1,BAZ,baz")), "baz"); Assert.assertTrue(groups.size() == 1); Assert.assertTrue(groups.contains("1")); groups = GroupingRequiredFilterFunctions.getGroupsForMatchesInGroup( Lists.newArrayList( makeValueTuple("ALPHA.1,BAR,bar"), makeValueTuple("ALPHA.2,BAR,bar")), "bar", Collections.singleton( makeValueTuple("GAMMA.1,BAZ,baz")), "baz"); Assert.assertTrue(groups.size() == 1); Assert.assertTrue(groups.contains("1")); }