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:jp.tricreo.schemagenerator.infrastructure.utils.CloneUtil.java

/**
 * ?? {@link Collection} ???{@link Object#clone() }??
 * ??????? {@link ArrayList} ?//w w  w  .  ja v a 2  s. com
 * 
 * @param <E> ??
 * @param collection ???
 * @return {@link ArrayList}
 */
public static <E extends Entity<E, ?>> ArrayList<E> cloneEntityArrayList(Collection<E> collection) {
    ArrayList<E> cloneCollection = Lists.newArrayListWithExpectedSize(collection.size());
    for (E element : collection) {
        // Entity(?)?clone?
        E cloneElement = element.clone();
        cloneCollection.add(cloneElement);
    }
    return cloneCollection;
}

From source file:net.sourceforge.cilib.util.selection.WeightedSelection.java

private static <T> WeightedObject[] copyOfInternal(Iterable<T> iterable) {
    checkArgument(Iterables.size(iterable) >= 1,
            "Attempting to create a " + "selection on an empty collection is not valid.");
    List<T> list = Lists.newArrayList(iterable);
    List<WeightedObject> result = Lists.newArrayListWithExpectedSize(list.size());
    for (T t : list) {
        result.add(new WeightedObject(t, 0.0));
    }/*  w ww .  ja  v a  2  s  . c o m*/
    return result.toArray(new WeightedObject[] {});
}

From source file:com.google.visualization.datasource.query.parser.GenericsHelper.java

/**
 * Transforms a typed List from a raw array.
 *
 * @param array The array to transform.//  w w w  .j a  v  a2 s  .co m
 *
 * @return The new List<T> containing all the elements in array.
 */
/* package */ static <T> List<T> makeAbstractColumnList(T[] array) {
    List<T> result = Lists.newArrayListWithExpectedSize(array.length);
    result.addAll(Arrays.asList(array));
    return result;
}

From source file:ru.codeinside.gses.webui.executor.DeclarantTypeQuery.java

@Override
public List<Item> loadItems(int startIndex, int count) {
    List<Item> items = Lists.newArrayListWithExpectedSize(size());
    Map<String, String> declarantTypes = DirectoryBeanProvider.get()
            .getValues(DeclarantServiceImpl.DECLARANT_TYPES);
    for (Map.Entry<String, String> dt : declarantTypes.entrySet()) {
        PropertysetItem item = new PropertysetItem();
        item.addItemProperty("name", new ObjectProperty<String>(dt.getKey()));
        item.addItemProperty("value", new ObjectProperty<String>(dt.getValue()));
        items.add(item);/*from   www.j av  a 2 s.  c o m*/
    }
    return items;
}

From source file:com.cloudera.exhibit.avro.AvroFrame.java

private static SimpleObs createObs(ObsDescriptor desc, GenericRecord rec) {
    AvroObs aobs = new AvroObs(desc, rec);
    List<Object> values = Lists.newArrayListWithExpectedSize(desc.size());
    for (int i = 0; i < desc.size(); i++) {
        values.add(aobs.get(i));/*  w w w. jav a 2  s  . com*/
    }
    return new SimpleObs(desc, values);
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.AnyTypeWidget.java

static BytecodeExpression invokeDynamic(final String operationName, final TypeWidget expectedReturnType,
        BytecodeExpression target, List<BytecodeExpression> arguments) {
    List<BytecodeExpression> invokeArguments = Lists.newArrayListWithExpectedSize(arguments.size() + 1);
    invokeArguments.add(target);/*  w w  w .  j  a  va2 s  .com*/
    invokeArguments.addAll(arguments);
    return new InvokeDynamicExpression(Dynamic.H_BOOTSTRAP, operationName, expectedReturnType, invokeArguments);
}

From source file:org.apache.aurora.scheduler.storage.durability.Recovery.java

/**
 * Copies all state from one persistence to another, batching into calls to
 * {@link Persistence#persist(Stream)}.//from   w  ww.  j  av a 2  s.  co  m
 *
 * @param from Source.
 * @param to Destination.
 * @param batchSize Maximum number of entries to include in any given persist.
 */
static void copy(Persistence from, Persistence to, int batchSize) {
    requireEmpty(to);

    long start = System.nanoTime();
    AtomicLong count = new AtomicLong();
    AtomicInteger batchNumber = new AtomicInteger();
    List<Op> batch = Lists.newArrayListWithExpectedSize(batchSize);
    Runnable saveBatch = () -> {
        LOG.info("Saving batch " + batchNumber.incrementAndGet());
        try {
            to.persist(batch.stream());
        } catch (PersistenceException e) {
            throw new RuntimeException(e);
        }
        batch.clear();
    };

    AtomicBoolean dataBegin = new AtomicBoolean(false);
    try {
        from.recover().filter(edit -> {
            if (edit.isDeleteAll()) {
                // Suppress any storage reset instructions.
                // Persistence implementations may recover with these, but do not support persisting
                // them.  As a result, we require that the recovery source produces a reset
                // instruction at the beginning of the stream, if at all.

                if (dataBegin.get()) {
                    throw new IllegalStateException(
                            "A storage reset instruction arrived after the beginning of data");
                }
                return false;
            } else {
                dataBegin.set(true);
            }
            return true;
        }).forEach(edit -> {
            count.incrementAndGet();
            batch.add(edit.getOp());
            if (batch.size() == batchSize) {
                saveBatch.run();
                LOG.info("Fetching batch");
            }
        });
    } catch (PersistenceException e) {
        throw new RuntimeException(e);
    }

    if (!batch.isEmpty()) {
        saveBatch.run();
    }
    long end = System.nanoTime();
    LOG.info("Recovery finished");
    LOG.info("Copied " + count.get() + " ops in "
            + Amount.of(end - start, Time.NANOSECONDS).as(Time.MILLISECONDS) + " ms");
}

From source file:org.apache.phoenix.expression.function.FloorDateExpression.java

public static Expression create(List<Expression> children) throws SQLException {
    Expression firstChild = children.get(0);
    PDataType firstChildDataType = firstChild.getDataType();
    if (firstChildDataType == PTimestamp.INSTANCE || firstChildDataType == PUnsignedTimestamp.INSTANCE) {
        // 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()));
        children = newChildren;/*from   ww  w  .jav a 2  s .c o m*/
    }
    return new FloorDateExpression(children);
}

From source file:io.druid.server.metrics.DruidSysMonitor.java

@Inject
public DruidSysMonitor(SegmentLoaderConfig config) {
    final List<StorageLocationConfig> locs = config.getLocations();
    List<String> dirs = Lists.newArrayListWithExpectedSize(locs.size());
    for (StorageLocationConfig loc : locs) {
        dirs.add(loc.getPath().toString());
    }// ww w.j av a 2s. c om

    addDirectoriesToMonitor(dirs.toArray(new String[dirs.size()]));
}

From source file:ru.runa.wfe.extension.orgfunction.GetActorsByCodesFunction.java

@Override
protected List<Long> getActorCodes(Object... parameters) {
    List<Long> codes = Lists.newArrayListWithExpectedSize(parameters.length);
    for (int i = 0; i < parameters.length; i++) {
        codes.add(TypeConversionUtil.convertTo(Long.class, parameters[i]));
    }/*from  w  w w .  ja  v a  2s  .co m*/
    return codes;
}