CartesianList(ImmutableList<List<E>> axes) { this.axes = axes; int[] axesSizeProduct = new int[axes.size() + 1]; axesSizeProduct[axes.size()] = 1; try { for (int i = axes.size() - 1; i >= 0; i--) { axesSizeProduct[i] = IntMath.checkedMultiply(axesSizeProduct[i + 1], axes.get(i).size()); } } catch (ArithmeticException e) { throw new IllegalArgumentException( "Cartesian product too large; must have size at most Integer.MAX_VALUE"); } this.axesSizeProduct = axesSizeProduct; }
if (operands.size() < minNumORClauses) { for (int i = 0; i < operands.size(); i++) { ConstraintGroup m = new ConstraintGroup(operands.get(i)); allNodes.add(m); allNodes.add(new ConstraintGroup(buildInFor(sa.getKey(), sa.getValue()))); processedNodes.addAll(sa.getValue()); List<RexNode> ops = new ArrayList<>(); for (ConstraintGroup mx : allNodes) { ops.add(mx.originalRexNode); if (ops.size() == 1) { return ops.get(0); } else {
private Builder register(RegistrationBlock block) { if (block.begin() != FLOATING_ID) { // flush pending types nextId(block.begin()); blocks.add(block); nextId(block.begin() + block.types().size()); } else { // flush pending types final int addedBlockBegin = blockHeadId + types.size(); nextId(addedBlockBegin); blocks.add(new RegistrationBlock(addedBlockBegin, block.types())); nextId(addedBlockBegin + block.types().size()); } return this; }
throws IOException rowCount += rows.size(); int columns = fieldNames.size(); for (int i = 0; i < row.size(); i++) { String s = formatValue(row.get(i)); maxWidth[i] = max(maxWidth[i], maxLineLength(s)); for (int i = 0; i < columns; i++) { String s = formatValue(row.get(i)); ImmutableList<String> lines = ImmutableList.copyOf(LINE_SPLITTER.split(s)); columnLines.add(lines); maxLines = max(maxLines, lines.size());
@Override public RelWriter explainTerms(RelWriter pw) { List<String> joinsString = new ArrayList<String>(); for (int i = 0; i < joinInputs.size(); i++) { final StringBuilder sb = new StringBuilder(); sb.append(joinInputs.get(i).left).append(" - ").append(joinInputs.get(i).right) .append(" : ").append(joinTypes.get(i).name()); joinsString.add(sb.toString()); } super.explainTerms(pw); for (Ord<RelNode> ord : Ord.zip(inputs)) { pw.input("input#" + ord.i, ord.e); } return pw.item("condition", condition) .item("joinsDescription", joinsString); }
public void test() { for (int groupNumber = 0; groupNumber < groups.size(); groupNumber++) { ImmutableList<T> group = groups.get(groupNumber); for (int itemNumber = 0; itemNumber < group.size(); itemNumber++) { // check related items in same group for (int relatedItemNumber = 0; relatedItemNumber < group.size(); relatedItemNumber++) { if (itemNumber != relatedItemNumber) { assertRelated(groupNumber, itemNumber, relatedItemNumber); } } // check unrelated items in all other groups for (int unrelatedGroupNumber = 0; unrelatedGroupNumber < groups.size(); unrelatedGroupNumber++) { if (groupNumber != unrelatedGroupNumber) { ImmutableList<T> unrelatedGroup = groups.get(unrelatedGroupNumber); for (int unrelatedItemNumber = 0; unrelatedItemNumber < unrelatedGroup.size(); unrelatedItemNumber++) { assertUnrelated(groupNumber, itemNumber, unrelatedGroupNumber, unrelatedItemNumber); } } } } } }
/** Adds the provided ancestors to the key. */ public B addAncestors(Iterable<PathElement> ancestors) { ImmutableList<PathElement> list = ImmutableList.copyOf(ancestors); Preconditions.checkState( this.ancestors.size() + list.size() < MAX_PATH, "path can have at most 100 elements"); this.ancestors.addAll(list); return self(); }
@Test public void testMultipleThreads() { config.setControlGateway(URL); config.setThreadCount(5); List<QueryPair> rewrittenQueries = rewriteQueries(parser, config, queryPairs); assertEquals(rewrittenQueries.size(), queryPairs.size()); }
@Override public void exitArrayLiteral(ArrayLiteralExpression expr) { final String listName = "arrayLiteral$" + subExpressionName(); final boolean constantList = expr.isConstant(); final ImmutableList.Builder<Object> elementsBuilder = ImmutableList.builder(); expr.children().forEach(expression -> elementsBuilder.add(blockOrMissing(codeSnippet.get(expression), expression))); final ImmutableList<Object> elements = elementsBuilder.build(); // if possible hoist decl to constructor if (constantList) { hoistedExpressionMembers.add(FieldSpec.builder(List.class, listName, Modifier.PRIVATE, Modifier.FINAL).build()); } final String assignmentFormat = "$L = $T.newArrayList(" + Stream.generate(() -> "$L").limit(elements.size()).reduce(Joiner.on(", ")::join).orElseGet(() -> "$") + ")"; // sigh java varargs List<Object> args = Lists.newArrayList(ArrayList.class, listName, Lists.class); args.addAll(elements); // if constant, initialize completely in constructor if (constantList) { hoistedConstantExpressions.addStatement(assignmentFormat, args.subList(1, args.size()).toArray()); } else { currentMethod.addStatement("$T " + assignmentFormat, args.toArray()); } codeSnippet.putIfAbsent(expr, CodeBlock.of("$L", listName)); }
parentQueryFields.add(builder.alias(builder.literal(true), indicator)); builder.project(parentQueryFields); builder.join(JoinRelType.LEFT, builder.literal(true), variablesSet); operands.add(field(builder, 1, builder.fields().size()-2)); return builder.call(SqlStdOperatorTable.CASE, operands.build()); fields.add(builder.alias(builder.literal(true), "i" + e.rel.getId())); builder.project(fields); builder.distinct(); for (Pair<RexNode, RexNode> pair : Pair.zip(e.getOperands(), builder.fields())) { conditions.add( builder.equals(pair.left, RexUtil.shift(pair.right, offset)));
@Test public void testDistributesSpillOverPaths() throws Exception { List<Type> types = ImmutableList.of(BIGINT); BlockEncodingSerde blockEncodingSerde = new BlockEncodingManager(new TypeRegistry()); List<Path> spillPaths = ImmutableList.of(spillPath1.toPath(), spillPath2.toPath()); FileSingleStreamSpillerFactory spillerFactory = new FileSingleStreamSpillerFactory( executor, // executor won't be closed, because we don't call destroy() on the spiller factory blockEncodingSerde, new SpillerStats(), spillPaths, 1.0); assertEquals(listFiles(spillPath1.toPath()).size(), 0); assertEquals(listFiles(spillPath2.toPath()).size(), 0); Page page = buildPage(); List<SingleStreamSpiller> spillers = new ArrayList<>(); for (int i = 0; i < 10; ++i) { SingleStreamSpiller singleStreamSpiller = spillerFactory.create(types, bytes -> {}, newSimpleAggregatedMemoryContext().newLocalMemoryContext("test")); getUnchecked(singleStreamSpiller.spill(page)); spillers.add(singleStreamSpiller); } assertEquals(listFiles(spillPath1.toPath()).size(), 5); assertEquals(listFiles(spillPath2.toPath()).size(), 5); spillers.forEach(SingleStreamSpiller::close); assertEquals(listFiles(spillPath1.toPath()).size(), 0); assertEquals(listFiles(spillPath2.toPath()).size(), 0); }
instructions = ImmutableList.copyOf(methodImpl.getInstructions()); methodParameters = ImmutableList.copyOf(method.getParameters()); instructionOffsetMap = new InstructionOffsetMap(instructions); int endOffset = instructionOffsetMap.getInstructionCodeOffset(instructions.size()-1) + instructions.get(instructions.size()-1).getCodeUnits(); for (int i=0; i<instructions.size(); i++) { Instruction instruction = instructions.get(i); effectiveInstructions.set(i, new ImmutableInstruction31t(opcode, ((Instruction31t)instruction).getRegisterA(), targetOffset-codeOffset)); effectiveInstructions.add(payloadInstruction); endOffset += payloadInstruction.getCodeUnits(); effectiveInstructions.set(i, new ImmutableInstruction31t(opcode, ((Instruction31t)instruction).getRegisterA(), targetOffset-codeOffset)); effectiveInstructions.add(payloadInstruction); endOffset += payloadInstruction.getCodeUnits();
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.getAll(internalCallContext)).size(), 10); Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, 100L, "record_id", "asc", internalCallContext)).size(), 10); Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(5L, 100L, "record_id", "asc", internalCallContext)).size(), 5); Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(5L, 10L, "record_id", "asc", internalCallContext)).size(), 5); Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, 5L, "record_id", "asc", internalCallContext)).size(), 5); for (int i = 0; i < 10; i++) { final List<TagDefinitionModelDao> tagDefinitions = ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, (long) i, "record_id", "asc", internalCallContext)); Assert.assertEquals(tagDefinitions.size(), i); for (int j = 0; j < tagDefinitions.size(); j++) { Assert.assertEquals(tagDefinitions.get(j).getName(), "name-" + j); Assert.assertEquals(tagDefinitions.get(j).getDescription(), "description-" + j); Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.getAll(internalCallContext)).size(), 10); Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(0L, 100L, internalCallContext)).size(), 10); Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(5L, 100L, internalCallContext)).size(), 5); Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(5L, 10L, internalCallContext)).size(), 5); Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(0L, 5L, internalCallContext)).size(), 5); for (int i = 0; i < 10; i++) { final List<TagDefinitionModelDao> tagDefinitions = ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(0L, (long) i, internalCallContext)); Assert.assertEquals(tagDefinitions.size(), i); for (int j = 0; j < tagDefinitions.size(); j++) {
Optional<Fix> deleteFix(TryTree tree, ImmutableList<CatchTree> catchBlocks, VisitorState state) { SuggestedFix.Builder fix = SuggestedFix.builder(); if (tree.getFinallyBlock() != null || catchBlocks.size() < tree.getCatches().size()) { t -> t instanceof UnionClassType ? ImmutableList.copyOf(((UnionClassType) t).getAlternativeTypes()).stream() : Stream.of(t)) .filter(t -> thrownTypes.stream().noneMatch(x -> types.isAssignable(t, x)))
private void buildInstructionList() { int registerCount = methodImpl.getRegisterCount(); ImmutableList<Instruction> instructions = ImmutableList.copyOf(methodImpl.getInstructions()); analyzedInstructions.ensureCapacity(instructions.size()); for (int i=0; i<instructions.size(); i++) { Instruction instruction = instructions.get(i); analyzedInstructions.append(currentCodeAddress, new AnalyzedInstruction(this, instruction, i, registerCount)); TryBlock currentTry = null; AnalyzedInstruction[] currentExceptionHandlers = null; AnalyzedInstruction[][] exceptionHandlers = new AnalyzedInstruction[instructions.size()][]; if (currentTry == null && triesIndex < tries.size()) { TryBlock<? extends ExceptionHandler> tryBlock = tries.get(triesIndex); if (tryBlock.getStartCodeAddress() <= currentCodeAddress) { BitSet instructionsToProcess = new BitSet(instructions.size());
@JsonCreator public static QualifiedObjectName valueOf(String name) { requireNonNull(name, "name is null"); ImmutableList<String> ids = ImmutableList.copyOf(Splitter.on('.').split(name)); checkArgument(ids.size() == 3, "Invalid name %s", name); return new QualifiedObjectName(ids.get(0), ids.get(1), ids.get(2)); }
private ArrayTable(Iterable<? extends R> rowKeys, Iterable<? extends C> columnKeys) { this.rowList = ImmutableList.copyOf(rowKeys); this.columnList = ImmutableList.copyOf(columnKeys); checkArgument(rowList.isEmpty() == columnList.isEmpty()); /* * TODO(jlevy): Support only one of rowKey / columnKey being empty? If we * do, when columnKeys is empty but rowKeys isn't, rowKeyList() can contain * elements but rowKeySet() will be empty and containsRow() won't * acknolwedge them. */ rowKeyToIndex = Maps.indexMap(rowList); columnKeyToIndex = Maps.indexMap(columnList); @SuppressWarnings("unchecked") V[][] tmpArray = (V[][]) new Object[rowList.size()][columnList.size()]; array = tmpArray; // Necessary because in GWT the arrays are initialized with "undefined" instead of null. eraseAll(); }
assertEquals(memoryContext.getBytes(), 4096); spiller.spill(page).get(); spiller.spill(Iterators.forArray(page, page, page)).get(); assertEquals(listFiles(spillPath.toPath()).size(), 1); assertEquals(memoryContext.getBytes(), FileSingleStreamSpiller.BUFFER_SIZE); ImmutableList<Page> spilledPages = ImmutableList.copyOf(spilledPagesIterator); assertEquals(4, spilledPages.size()); for (int i = 0; i < 4; ++i) { PageAssertions.assertPageEquals(TYPES, page, spilledPages.get(i)); assertEquals(listFiles(spillPath.toPath()).size(), 0); assertEquals(memoryContext.getBytes(), 0);