/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any of {@code elements} is null */ public static <E> ImmutableList<E> copyOf(Iterator<? extends E> elements) { // We special-case for 0 or 1 elements, but going further is madness. if (!elements.hasNext()) { return of(); } E first = elements.next(); if (!elements.hasNext()) { return of(first); } else { return new ImmutableList.Builder<E>().add(first).addAll(elements).build(); } }
private List<Dependency> get(Map<AbstractProject, List<DependencyGroup>> map, AbstractProject src) { List<DependencyGroup> v = map.get(src); if(v==null) { return ImmutableList.of(); } else { ImmutableList.Builder<Dependency> builder = ImmutableList.builder(); for (DependencyGroup dependencyGroup : v) { builder.addAll(dependencyGroup.getGroup()); } return builder.build(); } }
public void testBuilderAddAll_iterable() { List<String> a = asList("a", "b"); List<String> b = asList("c", "d"); ImmutableList<String> list = new ImmutableList.Builder<String>().addAll(a).addAll(b).build(); assertEquals(asList("a", "b", "c", "d"), list); b.set(0, "f"); assertEquals(asList("a", "b", "c", "d"), list); }
public void testBuilderAddAll_iterator() { List<String> a = asList("a", "b"); List<String> b = asList("c", "d"); ImmutableList<String> list = new ImmutableList.Builder<String>().addAll(a.iterator()).addAll(b.iterator()).build(); assertEquals(asList("a", "b", "c", "d"), list); b.set(0, "f"); assertEquals(asList("a", "b", "c", "d"), list); }
private PhysicalOperation( OperatorFactory operatorFactory, Map<Symbol, Integer> layout, LocalExecutionPlanContext context, Optional<PhysicalOperation> source, PipelineExecutionStrategy pipelineExecutionStrategy) { requireNonNull(operatorFactory, "operatorFactory is null"); requireNonNull(layout, "layout is null"); requireNonNull(context, "context is null"); requireNonNull(source, "source is null"); requireNonNull(pipelineExecutionStrategy, "pipelineExecutionStrategy is null"); this.operatorFactories = ImmutableList.<OperatorFactory>builder() .addAll(source.map(PhysicalOperation::getOperatorFactories).orElse(ImmutableList.of())) .add(operatorFactory) .build(); this.layout = ImmutableMap.copyOf(layout); this.types = toTypes(layout, context); this.pipelineExecutionStrategy = pipelineExecutionStrategy; }
/** * Returns an immutable list containing the given elements, in order. * * @throws NullPointerException if any of {@code elements} is null */ public static <E> ImmutableList<E> copyOf(Iterator<? extends E> elements) { // We special-case for 0 or 1 elements, but going further is madness. if (!elements.hasNext()) { return of(); } E first = elements.next(); if (!elements.hasNext()) { return of(first); } else { return new ImmutableList.Builder<E>().add(first).addAll(elements).build(); } }
private static JoinNode leftOuterJoin(PlanNodeIdAllocator idAllocator, AssignUniqueId probeSide, ProjectNode buildSide, Expression joinExpression) { return new JoinNode( idAllocator.getNextId(), JoinNode.Type.LEFT, probeSide, buildSide, ImmutableList.of(), ImmutableList.<Symbol>builder() .addAll(probeSide.getOutputSymbols()) .addAll(buildSide.getOutputSymbols()) .build(), Optional.of(joinExpression), Optional.empty(), Optional.empty(), Optional.empty()); }
List<Type> types = ImmutableList.of(BIGINT, DOUBLE); GroupByHash groupByHash = createGroupByHash(ImmutableList.of(types.get(0)), ImmutableList.of(0), NOOP); GroupedTopNBuilder groupedTopNBuilder = new GroupedTopNBuilder( types, remainingRows == 0 ? Collections.nCopies(pageCount, 0) : Collections.nCopies(pageCount, rowCount), new ImmutableList.Builder<Integer>() .addAll(Collections.nCopies((remainingRows + pageCount - 1) / pageCount, pageCount)) .addAll(Collections.nCopies(rowCount - (remainingRows + pageCount - 1) / pageCount, 0)) .build(), groupedTopNBuilder.getEstimatedSizeInBytes()); outputPageCount++;
@Nullable private ImmutableList<View> findChild( View root, Predicate<View> predicate, Predicate<? super ViewGroup> shouldCheckChildren) { if (predicate.apply(root)) { return ImmutableList.of(root); } if (root instanceof ViewGroup && shouldCheckChildren.apply((ViewGroup) root)) { ViewGroup viewGroup = (ViewGroup) root; for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); ImmutableList<View> result = findChild(child, predicate, shouldCheckChildren); if (result != null) { return ImmutableList.<View>builder() .add(root) .addAll(result) .build(); } } } return null; } }
public static List<Expression> extractPredicates(LogicalBinaryExpression.Operator operator, Expression expression) { if (expression instanceof LogicalBinaryExpression && ((LogicalBinaryExpression) expression).getOperator() == operator) { LogicalBinaryExpression logicalBinaryExpression = (LogicalBinaryExpression) expression; return ImmutableList.<Expression>builder() .addAll(extractPredicates(operator, logicalBinaryExpression.getLeft())) .addAll(extractPredicates(operator, logicalBinaryExpression.getRight())) .build(); } return ImmutableList.of(expression); }
/** * Returns a list of parameters for invoking an overload of checkState, checkArgument or * checkNotNull * * @param predicateType The first parameter to the method (boolean or Object) */ private static ImmutableList<ImmutableList<Class<?>>> allSignatures(Class<?> predicateType) { ImmutableSet.Builder<ImmutableList<Class<?>>> allOverloads = ImmutableSet.builder(); // The first two are for the overloads that don't take formatting args, e.g. // checkArgument(boolean) and checkArgument(boolean, Object) allOverloads.add(ImmutableList.<Class<?>>of(predicateType)); allOverloads.add(ImmutableList.<Class<?>>of(predicateType, Object.class)); List<List<Class<?>>> typesLists = new ArrayList<>(); for (int i = 0; i < 2; i++) { typesLists.add(possibleParamTypes); for (List<Class<?>> curr : Lists.cartesianProduct(typesLists)) { allOverloads.add( ImmutableList.<Class<?>>builder() .add(predicateType) .add(String.class) // the format string .addAll(curr) .build()); } } return allOverloads.build().asList(); }