Example usage for com.google.common.collect Lists newArrayListWithExpectedSize

List of usage examples for com.google.common.collect Lists newArrayListWithExpectedSize

Introduction

In this page you can find the example usage for com.google.common.collect Lists newArrayListWithExpectedSize.

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize) 

Source Link

Document

Creates an ArrayList instance to hold estimatedSize elements, plus an unspecified amount of padding; you almost certainly mean to call #newArrayListWithCapacity (see that method for further advice on usage).

Usage

From source file:info.magnolia.ui.admincentral.shellapp.pulse.PulseMatchers.java

/**
 * Checks whether the provided list of Vaadin items is of expected size and contains valid task items
 * (i.e. contain properties described in {@link TaskConstants}).
 *//*from   w  w w  .j av  a 2 s  . co m*/
public static Matcher<Iterable<? extends Item>> containsAmountOfTaskItems(int size) {
    final List<Matcher<? super Item>> matchers = Lists.newArrayListWithExpectedSize(size);
    for (int i = 0; i < size; ++i) {
        matchers.add(isTaskItem());
    }
    return new IsIterableContainingInOrder<Item>(matchers);
}

From source file:org.apache.phoenix.iterate.UnionResultIterators.java

public UnionResultIterators(List<QueryPlan> plans, StatementContext parentStmtCtx) throws SQLException {
    this.parentStmtCtx = parentStmtCtx;
    this.plans = plans;
    int nPlans = plans.size();
    iterators = Lists.newArrayListWithExpectedSize(nPlans);
    splits = Lists.newArrayListWithExpectedSize(nPlans * 30);
    scans = Lists.newArrayListWithExpectedSize(nPlans * 10);
    readMetricsList = Lists.newArrayListWithCapacity(nPlans);
    overAllQueryMetricsList = Lists.newArrayListWithCapacity(nPlans);
    for (QueryPlan plan : this.plans) {
        readMetricsList.add(plan.getContext().getReadMetricsQueue());
        overAllQueryMetricsList.add(plan.getContext().getOverallQueryMetrics());
        iterators.add(LookAheadResultIterator.wrap(plan.iterator()));
        splits.addAll(plan.getSplits());
        scans.addAll(plan.getScans());//from  www  . ja va 2  s  . co  m
    }
}

From source file:org.impressivecode.depress.scm.common.SCMInputTransformer.java

@Override
public List<SCMDataType> transform(final DataTable inTable) {
    checkNotNull(this.minimalTableSpec, "Minimal DataTableSpec hat to be set");
    checkNotNull(this.inputTableSpec, "Input DataTableSpec hat to be set");
    checkNotNull(inTable, "InTable has to be set");
    List<SCMDataType> scmData = Lists.newArrayListWithExpectedSize(1000);
    RowIterator iterator = inTable.iterator();
    while (iterator.hasNext()) {
        scmData.add(transformRow(iterator.next()));
    }/*from w w  w.ja  va 2s .c  o  m*/
    return scmData;
}

From source file:com.cloudera.oryx.kmeans.computation.local.Summarize.java

@Override
public Summary call() throws IOException {
    File[] inputFiles = inputDir.listFiles(IOUtils.CSV_COMPRESSED_FILTER);
    if (inputFiles == null || inputFiles.length == 0) {
        log.warn("No .csv or .gz input files found in input directory");
        return null;
    }/* ww  w. java 2 s  .  c  om*/

    InboundSettings inboundSettings = InboundSettings.create(ConfigUtils.getDefaultConfig());
    int numFeatures = inboundSettings.getColumnNames().size();
    List<InternalStats> internalStats = Lists.newArrayListWithExpectedSize(numFeatures);
    for (int col = 0; col < numFeatures; col++) {
        if (inboundSettings.isCategorical(col) || inboundSettings.isNumeric(col)) {
            internalStats.add(new InternalStats());
        } else {
            internalStats.add(null);
        }
    }
    int totalRecords = 0;

    for (File inputFile : inputFiles) {
        log.info("Summarizing input from {}", inputFile.getName());
        for (String line : new FileLineIterable(inputFile)) {
            if (line.isEmpty()) {
                continue;
            }
            totalRecords++;
            String[] tokens = DelimitedDataUtils.decode(line);
            for (int col = 0; col < numFeatures; col++) {
                if (!inboundSettings.isIgnored(col)) {
                    if (inboundSettings.isCategorical(col)) {
                        internalStats.get(col).addCategorical(tokens[col]);
                    } else if (inboundSettings.isNumeric(col)) {
                        internalStats.get(col).addNumeric(Double.valueOf(tokens[col]));
                    }
                }
            }
        }
    }

    List<SummaryStats> stats = Lists.newArrayListWithExpectedSize(numFeatures);
    for (int col = 0; col < numFeatures; col++) {
        InternalStats internal = internalStats.get(col);
        if (internal != null) {
            stats.add(internal.toSummaryStats(inboundSettings.getColumnNames().get(col), totalRecords));
        } else {
            stats.add(null);
        }
    }

    return new Summary(totalRecords, numFeatures, stats);
}

From source file:com.yahoo.yqlplus.engine.internal.source.IndexedMethod.java

protected StreamValue createKeyCursor(ContextPlanner planner, Location location,
        List<IndexedSourceType.IndexQuery> todo) {
    if (todo.size() == 1) {
        return todo.get(0).keyCursor(planner);
    } else {/*from w  ww. j  av a 2s  .  c  om*/
        List<OperatorNode<PhysicalExprOperator>> cursors = Lists.newArrayListWithExpectedSize(todo.size());
        for (IndexedSourceType.IndexQuery q : todo) {
            cursors.add(q.keyCursor(planner).materializeValue());
        }
        StreamValue val = StreamValue.iterate(planner,
                OperatorNode.create(location, PhysicalExprOperator.CONCAT, cursors));
        val.add(Location.NONE, StreamOperator.DISTINCT);
        return val;
    }
}

From source file:org.apache.phoenix.expression.function.CeilTimestampExpression.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();
    if (TimeUnit.MILLISECOND.toString().equalsIgnoreCase(timeUnit)) {
        return new CeilTimestampExpression(children);
    }// ww  w.  ja v a 2s.co  m
    // 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 CeilDateExpression.create(newChildren);
}

From source file:org.zalando.logbook.DefaultHttpLogFormatter.java

private <H extends HttpMessage> String format(final H message, final Function<H, String> lineCreator)
        throws IOException {
    final List<String> lines = Lists.newArrayListWithExpectedSize(4);

    lines.add(lineCreator.apply(message));
    lines.addAll(formatHeaders(message));

    final String body = message.getBodyAsString();

    if (!body.isEmpty()) {
        lines.add("");
        lines.add(body);//from  w  w w .  j av a2 s.  c  om
    }

    return join(lines);
}

From source file:com.cloudera.exhibit.hive.HiveStructObsDescriptor.java

@Override
public Object[] convert(Object rawObs) {
    List v = Lists.newArrayListWithExpectedSize(obji.getAllStructFieldRefs().size());
    ObjectInspectorUtils.copyToStandardObject(v, rawObs, obji,
            ObjectInspectorUtils.ObjectInspectorCopyOption.JAVA);
    for (int i = 0; i < v.size(); i++) {
        v.set(i, HiveUtils.asJavaType(v.get(i)));
    }//from w  w  w  .  ja  v a  2 s. c om
    return v.toArray();
}

From source file:ru.codeinside.gses.webui.declarant.ProcedureQuery.java

@Override
public List<Item> loadItems(final int start, final int count) {
    final List<Procedure> procs;
    if (showActive) {
        procs = Flash.flash().getDeclarantService().selectActiveProcedures(type, serviceId, start, count);
    } else {/*from  w  w w .j ava2 s. c o m*/
        procs = sublist(filtered, start, count);
    }
    final List<Item> items = Lists.newArrayListWithExpectedSize(procs.size());
    for (Procedure p : procs) {
        final PropertysetItem item = new PropertysetItem();
        item.addItemProperty("id", new ObjectProperty<Long>(Long.valueOf(p.getId())));
        item.addItemProperty("name", new ObjectProperty<String>(p.getName()));
        items.add(item);
    }
    return items;
}

From source file:org.elasticsearch.indices.recovery.RecoveryTranslogOperationsRequest.java

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    recoveryId = in.readLong();//  ww w  .  ja va  2 s .c o  m
    shardId = ShardId.readShardId(in);
    int size = in.readVInt();
    operations = Lists.newArrayListWithExpectedSize(size);
    for (int i = 0; i < size; i++) {
        operations.add(TranslogStreams.readTranslogOperation(in));
    }
}