/** * Returns whether all types in a collection have the same family, as * determined by {@link #isSameFamily(RelDataType, RelDataType)}. * * @param types Types to check * @return true if all types are of the same family */ public static boolean areSameFamily(Iterable<RelDataType> types) { final List<RelDataType> typeList = ImmutableList.copyOf(types); if (Sets.newHashSet(RexUtil.families(typeList)).size() < 2) { return true; } for (Pair<RelDataType, RelDataType> adjacent : Pair.adjacents(typeList)) { if (!isSameFamily(adjacent.left, adjacent.right)) { return false; } } return true; }
/** * Returns whether all types in a collection have the same family, as * determined by {@link #isSameFamily(RelDataType, RelDataType)}. * * @param types Types to check * @return true if all types are of the same family */ public static boolean areSameFamily(Iterable<RelDataType> types) { final List<RelDataType> typeList = ImmutableList.copyOf(types); if (Sets.newHashSet(RexUtil.families(typeList)).size() < 2) { return true; } for (Pair<RelDataType, RelDataType> adjacent : Pair.adjacents(typeList)) { if (!isSameFamily(adjacent.left, adjacent.right)) { return false; } } return true; }
/** * Unit test for {@link Pair#adjacents(Iterable)}. */ @Test public void testPairAdjacents() { List<String> strings = Arrays.asList("a", "b", "c"); List<String> result = new ArrayList<>(); for (Pair<String, String> pair : Pair.adjacents(strings)) { result.add(pair.toString()); } assertThat(result.toString(), equalTo("[<a, b>, <b, c>]")); // empty source yields empty result assertThat(Pair.adjacents(ImmutableList.of()).iterator().hasNext(), is(false)); // source with 1 element yields empty result assertThat(Pair.adjacents(ImmutableList.of("a")).iterator().hasNext(), is(false)); // source with 100 elements yields result with 99 elements; // null elements are ok assertThat(Iterables.size(Pair.adjacents(Collections.nCopies(100, null))), equalTo(99)); }
/** * Unit test for {@link Pair#adjacents(Iterable)}. */ @Test public void testPairAdjacents() { List<String> strings = Arrays.asList("a", "b", "c"); List<String> result = new ArrayList<>(); for (Pair<String, String> pair : Pair.adjacents(strings)) { result.add(pair.toString()); } assertThat(result.toString(), equalTo("[<a, b>, <b, c>]")); // empty source yields empty result assertThat(Pair.adjacents(ImmutableList.of()).iterator().hasNext(), is(false)); // source with 1 element yields empty result assertThat(Pair.adjacents(ImmutableList.of("a")).iterator().hasNext(), is(false)); // source with 100 elements yields result with 99 elements; // null elements are ok assertThat(Iterables.size(Pair.adjacents(Collections.nCopies(100, null))), equalTo(99)); }
for (Pair<RelDataType, RelDataType> pair : Pair.adjacents(argTypes2)) { RelDataType t0 = pair.left; RelDataType t1 = pair.right;
for (Pair<RelDataType, RelDataType> pair : Pair.adjacents(argTypes2)) { RelDataType t0 = pair.left; RelDataType t1 = pair.right;
for (Pair<RelDataType, RelDataType> pair : Pair.adjacents(argTypes2)) { RelDataType t0 = pair.left; RelDataType t1 = pair.right;