DataSourceUtils { public static void addToDataSource(DataSource parent, DataSource child) { if (!parent.getLeftDataSource().isPresent()) { parent.setLeftDataSource(child); } else if (!parent.getRightDataSource().isPresent()) { parent.setRightDataSource(child); } else { DataSource newLeftDataSource = new DataSource(parent.getLeftDataSource().get()); newLeftDataSource.setRightDataSource(parent.getRightDataSource().get()); parent.setLeftDataSource(newLeftDataSource); parent.setRightDataSource(child); } }  static DataSource getTail(DataSource dataSource); static void addToDataSource(DataSource parent, DataSource child); static void checkLeftDataSource(DataSource dataSource); static void checkLeftDataSource(DataSource dataSource, boolean conditionRequired); static void checkRightDataSource(DataSource dataSource); static void checkRightDataSource(DataSource dataSource, boolean conditionRequired); static Set<T> intersection(Set<T> first, Set<T> second); static Set<T> difference(Set<T> first, Set<T> second); static Optional<BooleanExpression> intersectConditions(Optional<BooleanExpression> left, Optional<BooleanExpression> right); static void iterateDataSource(DataSource dataSource, DataSourceAction action); static void crossProduct(List<I> left, List<I> right, Function<I, List<O>> transformer, BiConsumer<Pair<Integer, Integer>, List<O>> rowConsumer); static List<List<T>> crossProduct(List<Collection<T>> lists);  }
@Test public void testAddToDataSource() { DataSource parentDataSource = new DataSource(); DataSource firstChildDataSource = new DataSource("first"); addToDataSource(parentDataSource, firstChildDataSource); assertThat(parentDataSource.getLeftDataSource(), equalTo(Optional.of(firstChildDataSource))); DataSource secondChildDataSource = new DataSource("second"); addToDataSource(parentDataSource, secondChildDataSource); assertThat(parentDataSource.getRightDataSource(), equalTo(Optional.of(secondChildDataSource))); DataSource thirdChildDataSource = new DataSource("third"); addToDataSource(parentDataSource, thirdChildDataSource); DataSource correctLeftDataSource = new DataSource(); correctLeftDataSource.setLeftDataSource(firstChildDataSource); correctLeftDataSource.setRightDataSource(secondChildDataSource); assertThat(parentDataSource.getLeftDataSource(), equalTo(Optional.of(correctLeftDataSource))); assertThat(parentDataSource.getRightDataSource(), equalTo(Optional.of(thirdChildDataSource))); }