List of usage examples for com.google.common.collect Lists newArrayListWithExpectedSize
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize)
From source file:org.eclipse.xtext.ide.editor.contentassist.antlr.internal.AbstractFollowElementFactory.java
public FollowElement createFollowElement(AbstractElement current, int lookAhead) { if (logger.isDebugEnabled()) logger.debug("Creating FollowElement for: " + current); FollowElement result = doCreateElement(); result.setLookAhead(lookAhead);/*from ww w. ja v a2 s . c o m*/ if (lookAhead != 1) { int from = parser.input.index(); int to = parser.input.size(); if (parser.marked > 0) { from = parser.firstMarker; } List<LookAheadTerminal> lookAheadTerminals = Lists.newArrayListWithExpectedSize(to - from); for (int tokenIndex = from; tokenIndex < to; tokenIndex++) { Token token = parser.input.get(tokenIndex); if (token != null) { LookAheadTerminal lookAheadTerminal = doCreateLookAheadTerminal(token); lookAheadTerminals.add(lookAheadTerminal); } } result.setLookAheadTerminals(lookAheadTerminals); result.setLookAhead(lookAheadTerminals.size() + 1); } result.setGrammarElement(current); result.setTrace( Lists.newArrayList(Iterators.filter(parser.grammarElements.iterator(), AbstractElement.class))); result.setLocalTrace( Lists.newArrayList(Iterators.filter(parser.localTrace.iterator(), AbstractElement.class))); result.setParamStack(Lists.newArrayList(parser.paramStack)); if (current instanceof UnorderedGroup) { if (parser.indexToHandledElements != null) { int index = parser.grammarElements.lastIndexOf(current); List<AbstractElement> alreadyHandled = Lists.newArrayList(Iterators .filter(parser.indexToHandledElements.get(index).iterator(), AbstractElement.class)); result.setHandledUnorderedGroupElements(alreadyHandled); } else { result.setHandledUnorderedGroupElements(Collections.<AbstractElement>emptyList()); } } if (logger.isDebugEnabled()) { logger.debug("FollowElement is: " + current); logger.debug("=================================="); } return result; }
From source file:com.torodb.torod.mongodb.commands.impl.general.update.KVArrayBuilder.java
public KVArrayBuilder(int expectedSize, DocumentBuilderFactory documentBuilderFactory) { this.documentBuilderFactory = documentBuilderFactory; built = false;// ww w .j a v a 2s . co m values = Lists.newArrayListWithExpectedSize(expectedSize); }
From source file:org.sosy_lab.cpachecker.util.predicates.interpolation.strategy.SequentialInterpolation.java
@Override public List<BooleanFormula> getInterpolants(final InterpolationManager.Interpolator<T> interpolator, final List<Triple<BooleanFormula, AbstractState, T>> formulasWithStateAndGroupId) throws InterruptedException, SolverException { final List<T> formulas = Lists.transform(formulasWithStateAndGroupId, Triple.<T>getProjectionToThird()); final List<BooleanFormula> interpolants = Lists.newArrayListWithExpectedSize(formulas.size() - 1); for (int end_of_A = 0; end_of_A < formulas.size() - 1; end_of_A++) { // last iteration is left out because B would be empty final int start_of_A = 0; interpolants.add(getInterpolantFromSublist(interpolator.itpProver, formulas, start_of_A, end_of_A)); }// w w w .j a v a 2s . co m return interpolants; }
From source file:org.eclipse.incquery.patternlanguage.emf.scoping.EMFPatternLanguageImportNamespaceProvider.java
@Override protected List<ImportNormalizer> getImportedNamespaceResolvers(XImportSection importSection, boolean ignoreCase) { List<ImportNormalizer> parentNormalizers = super.getImportedNamespaceResolvers(importSection, ignoreCase); List<PatternImport> patternImportDeclarations; if (importSection instanceof org.eclipse.incquery.patternlanguage.emf.eMFPatternLanguage.XImportSection) { patternImportDeclarations = ((org.eclipse.incquery.patternlanguage.emf.eMFPatternLanguage.XImportSection) importSection) .getPatternImport();/*from w w w . j ava 2 s .c o m*/ } else { patternImportDeclarations = Lists.newArrayList(); } List<ImportNormalizer> result = Lists .newArrayListWithExpectedSize(patternImportDeclarations.size() + parentNormalizers.size()); for (PatternImport imp : patternImportDeclarations) { ImportNormalizer resolver = createImportedNamespaceResolver( CorePatternLanguageHelper.getFullyQualifiedName(imp.getPattern()), ignoreCase); if (resolver != null) { result.add(resolver); } } result.addAll(parentNormalizers); return result; }
From source file:org.apache.phoenix.expression.InListExpression.java
public static Expression create(List<Expression> children, boolean isNegate, ImmutableBytesWritable ptr, boolean rowKeyOrderOptimizable) throws SQLException { Expression firstChild = children.get(0); if (firstChild.isStateless() && (!firstChild.evaluate(null, ptr) || ptr.getLength() == 0)) { return LiteralExpression.newConstant(null, PBoolean.INSTANCE, firstChild.getDeterminism()); }/* ww w. ja va2 s.co m*/ if (children.size() == 2) { return ComparisonExpression.create(isNegate ? CompareOp.NOT_EQUAL : CompareOp.EQUAL, children, ptr, rowKeyOrderOptimizable); } boolean addedNull = false; SQLException sqlE = null; List<Expression> coercedKeyExpressions = Lists.newArrayListWithExpectedSize(children.size()); coercedKeyExpressions.add(firstChild); for (int i = 1; i < children.size(); i++) { try { Expression rhs = BaseExpression.coerce(firstChild, children.get(i), CompareOp.EQUAL, rowKeyOrderOptimizable); coercedKeyExpressions.add(rhs); } catch (SQLException e) { // Type mismatch exception or invalid data exception. // Ignore and filter the element from the list and it means it cannot possibly // be in the list. If list is empty, we'll throw the last exception we ignored, // as this is an error condition. sqlE = e; } } if (coercedKeyExpressions.size() == 1) { throw sqlE; } if (coercedKeyExpressions.size() == 2 && addedNull) { return LiteralExpression.newConstant(null, PBoolean.INSTANCE, Determinism.ALWAYS); } Expression expression = new InListExpression(coercedKeyExpressions, rowKeyOrderOptimizable); if (isNegate) { expression = NotExpression.create(expression, ptr); } if (ExpressionUtil.isConstant(expression)) { return ExpressionUtil.getConstantExpression(expression, ptr); } return expression; }
From source file:com.yahoo.yqlplus.engine.internal.java.sequences.Sequences.java
public static <ROW> List<ROW> doMerge(List<ROW>... inputs) { int count = 0; for (List<ROW> input : inputs) { count += input.size();/*w w w . j ava 2 s. c o m*/ } List<ROW> result = Lists.newArrayListWithExpectedSize(count); for (List<ROW> input : inputs) { result.addAll(input); } return result; }
From source file:org.apache.flink.graph.examples.data.SummarizationData.java
/** * Creates a set of edges with attached {@link String} values. * * @param env execution environment/*from w ww . j a v a 2s . c o m*/ * @return edge data set with string values */ public static DataSet<Edge<Long, String>> getEdges(ExecutionEnvironment env) { List<Edge<Long, String>> edges = Lists.newArrayListWithExpectedSize(10); edges.add(new Edge<>(0L, 1L, "A")); edges.add(new Edge<>(1L, 0L, "A")); edges.add(new Edge<>(1L, 2L, "A")); edges.add(new Edge<>(2L, 1L, "A")); edges.add(new Edge<>(2L, 3L, "B")); edges.add(new Edge<>(3L, 2L, "B")); edges.add(new Edge<>(4L, 0L, "C")); edges.add(new Edge<>(4L, 1L, "C")); edges.add(new Edge<>(5L, 2L, "D")); edges.add(new Edge<>(5L, 3L, "D")); return env.fromCollection(edges); }
From source file:org.gradoop.io.impl.tlf.functions.TLFFileFormat.java
/** * Creates a TLF string representation of a given graph transaction. * * @param graphTransaction graph transaction * @return TLF string representation//from w w w . jav a 2 s.c o m */ @Override public String format(GraphTransaction<G, V, E> graphTransaction) { graphId++; Map<GradoopId, Integer> vertexIdMap = Maps .newHashMapWithExpectedSize(graphTransaction.getVertices().size()); Collection<String> lines = Lists.newArrayListWithExpectedSize( graphTransaction.getVertices().size() + graphTransaction.getEdges().size() + 1); // GRAPH HEAD lines.add(TLFGraph.SYMBOL + " # " + graphId); // VERTICES int vertexId = 0; for (V vertex : graphTransaction.getVertices()) { vertexIdMap.put(vertex.getId(), vertexId); lines.add(TLFVertex.SYMBOL + " " + vertexId + " " + vertex.getLabel()); vertexId++; } // EDGES for (E edge : graphTransaction.getEdges()) { Integer sourceId = vertexIdMap.get(edge.getSourceId()); Integer targetId = vertexIdMap.get(edge.getTargetId()); lines.add(TLFEdge.SYMBOL + " " + sourceId + " " + targetId + "" + " " + edge.getLabel()); } return StringUtils.join(lines, "\n") + "\n"; }
From source file:com.twitter.elephanttwin.lucene.indexing.HadoopSplitIndexingReducer.java
@Override protected Document buildDocument(LongWritable k, HadoopSplitDocument v) { LOG.info("Indexing document:"); LOG.info(" offset: " + v.getOffset()); LOG.info(" cnt: " + v.getCnt()); // Build the document. We simply concatenate all observed // values for key using whitespace, and use // WhitespaceAnalyzer to tokenize. // TODO: This is suboptimal and we can add more fancyness later. Document doc = new Document(); doc.add(new Field("offset", "" + v.getOffset(), LuceneUtil.getFieldType(LuceneUtil.STORED_NO_INDEX_NO_NORM_NO_TOKEN))); // Use cnt as an additional field to disambiguate in case there are multiple "fake" documents // with the same offset. doc.add(new Field("cnt", "" + v.getCnt(), LuceneUtil.getFieldType(LuceneUtil.STORED_NO_INDEX_NO_NORM_NO_TOKEN))); for (Map.Entry<String, Set<String>> entry : v.getKeyValueListMap().entrySet()) { List<String> strings = Lists.newArrayListWithExpectedSize(entry.getValue().size()); for (String s : entry.getValue()) { strings.add(s);/*w w w .j a v a2 s. co m*/ } doc.add(new Field(entry.getKey(), Joiner.on(" ").join(strings), LuceneUtil.getFieldType(LuceneUtil.NO_STORE_INDEX_NO_NORM_TOKEN))); } return doc; }
From source file:org.apache.phoenix.expression.function.RoundTimestampExpression.java
public static Expression create(List<Expression> children) throws SQLException { Expression firstChild = children.get(0); PDataType firstChildDataType = firstChild.getDataType(); String timeUnit = (String) ((LiteralExpression) children.get(1)).getValue(); LiteralExpression multiplierExpr = (LiteralExpression) children.get(2); /*/*from w w w . j av a 2 s. c o m*/ * When rounding off timestamp to milliseconds, nanos play a part only when the multiplier value * is equal to 1. This is because for cases when multiplier value is greater than 1, number of nanos/multiplier * will always be less than half the nanos in a millisecond. */ if ((timeUnit == null || TimeUnit.MILLISECOND.toString().equalsIgnoreCase(timeUnit)) && ((Number) multiplierExpr.getValue()).intValue() == 1) { return new RoundTimestampExpression(children); } // Coerce TIMESTAMP to DATE, as the nanos has no affect List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size()); newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE)); newChildren.addAll(children.subList(1, children.size())); return RoundDateExpression.create(newChildren); }