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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize) 

Source Link

Document

Creates an ArrayList instance backed by an array with the specified initial size; simply delegates to ArrayList#ArrayList(int) .

Usage

From source file:org.apache.crunch.types.CollectionDeepCopier.java

@Override
public Collection<T> deepCopy(Collection<T> source) {
    if (source == null) {
        return null;
    }/*from ww  w.  j  a  v a2  s  .  com*/
    List<T> copiedCollection = Lists.newArrayListWithCapacity(source.size());
    for (T value : source) {
        copiedCollection.add(elementType.getDetachedValue(value));
    }
    return copiedCollection;
}

From source file:org.eclipse.xtext.xbase.scoping.batch.FeatureScopeSessionWithStaticTypes.java

@Override
protected List<TypeBucket> concatTypeBuckets(List<? extends JvmType> types, List<TypeBucket> parentResult,
        Provider resolvedFeaturesProvider) {
    if (types.isEmpty()) {
        return parentResult;
    }//from   w  w  w.j ava2 s  . c  o  m
    List<TypeBucket> result = Lists.newArrayListWithCapacity(3);
    result.add(new TypeBucket(getId(), types, resolvedFeaturesProvider));
    result.addAll(parentResult);
    return result;
}

From source file:org.apache.hadoop.hdfs.server.namenode.XAttrPermissionFilter.java

static List<XAttr> filterXAttrsForApi(FSPermissionChecker pc, List<XAttr> xAttrs) {
    assert xAttrs != null : "xAttrs can not be null";
    if (xAttrs == null || xAttrs.isEmpty()) {
        return xAttrs;
    }//  w  w w .  j a  v  a 2  s  . com

    List<XAttr> filteredXAttrs = Lists.newArrayListWithCapacity(xAttrs.size());
    for (XAttr xAttr : xAttrs) {
        if (xAttr.getNameSpace() == XAttr.NameSpace.USER) {
            filteredXAttrs.add(xAttr);
        } else if (xAttr.getNameSpace() == XAttr.NameSpace.TRUSTED && pc.isSuperUser()) {
            filteredXAttrs.add(xAttr);
        }
    }

    return filteredXAttrs;
}

From source file:org.gradoop.flink.model.impl.operators.matching.common.matching.ElementMatcher.java

/**
 * Returns all query candidate ids for the given EPGM element.
 *
 * @param dbElement     EPGM element (vertices/edges)
 * @param queryElements query graph elements (vertices/edges)
 * @param <EL1>         EPGM element type
 * @param <EL2>         GDL element type
 * @param defaultLabel  default element label
 * @return all candidate ids for {@code dbElement}
 *//*ww  w.j  av  a 2s.  c  o  m*/
public static <EL1 extends Element, EL2 extends GraphElement> List<Long> getMatches(EL1 dbElement,
        Collection<EL2> queryElements, String defaultLabel) {

    List<Long> matches = Lists.newArrayListWithCapacity(queryElements.size());

    for (GraphElement queryElement : queryElements) {
        if (match(dbElement, queryElement, defaultLabel)) {
            matches.add(queryElement.getId());
        }
    }

    return matches;
}

From source file:org.stem.utils.TopologyUtils.java

public static List<Long> generateVBucketsIds(int size) {
    List<Long> ranges = Lists.newArrayListWithCapacity(size);

    for (long i = 1; i <= size; i++) {
        ranges.add(i);/*w  w  w .  j a v a  2s  .  c  om*/
    }

    return ranges;
}

From source file:org.summer.ss.core.validation.TypeErasedSignature.java

protected TypeErasedSignature(JvmExecutable executable, IRawTypeHelper rawTypeHelper) {
    this.executable = executable;
    if (executable != null) {
        erasureParameterTypes = Lists.newArrayListWithCapacity(executable.getParameters().size());
        for (JvmFormalParameter parameter : executable.getParameters()) {
            List<JvmType> rawTypes = rawTypeHelper.getAllRawTypes(parameter.getParameterType(),
                    executable.eResource());
            if (rawTypes.isEmpty()) {
                erasureParameterTypes.add(null);
            } else {
                // see comments in https://bugs.eclipse.org/bugs/show_bug.cgi?id=357958
                erasureParameterTypes.add(rawTypes.get(0));
            }// w w  w  .j  a  va  2  s  .co  m
        }
    } else {
        erasureParameterTypes = Collections.emptyList();
    }
}

From source file:com.netflix.astyanax.thrift.model.ThriftRowsSliceImpl.java

public ThriftRowsSliceImpl(List<KeySlice> rows, Serializer<K> keySer, Serializer<C> colSer) {
    this.rows = Lists.newArrayListWithCapacity(rows.size());

    for (KeySlice row : rows) {
        Row<K, C> thriftRow = new ThriftRowImpl<K, C>(keySer.fromBytes(row.getKey()),
                ByteBuffer.wrap(row.getKey()),
                new ThriftColumnOrSuperColumnListImpl<C>(row.getColumns(), colSer));
        this.rows.add(thriftRow);
    }//from w  w w  .j  av  a 2  s . com
}

From source file:org.terasology.polyworld.rp.GridRegionProvider.java

@Override
public Collection<Rect2i> getSectorRegions(Rect2i fullArea) {
    int width = fullArea.width() / divX;
    int height = fullArea.height() / divY;

    Collection<Rect2i> areas = Lists.newArrayListWithCapacity(divX * divY);

    for (int ry = 0; ry < divY; ry++) {
        for (int rx = 0; rx < divX; rx++) {
            int x = fullArea.minX() + rx * width;
            int y = fullArea.minY() + ry * height;
            areas.add(Rect2i.createFromMinAndSize(x, y, width, height));
        }//  w ww  . j  av  a  2 s. c  om
    }

    return areas;
}

From source file:org.apache.mahout.common.iterator.StableFixedSizeSamplingIterator.java

public StableFixedSizeSamplingIterator(int size, Iterator<T> source) {
    List<Pair<Integer, T>> buf = Lists.newArrayListWithCapacity(size);
    int sofar = 0;
    Random random = RandomUtils.getRandom();
    while (source.hasNext()) {
        T v = source.next();/*  w  w  w. j av  a2  s .  c  o m*/
        sofar++;
        if (buf.size() < size) {
            buf.add(new Pair<Integer, T>(sofar, v));
        } else {
            int position = random.nextInt(sofar);
            if (position < buf.size()) {
                buf.set(position, new Pair<Integer, T>(sofar, v));
            }
        }
    }

    Collections.sort(buf);
    delegate = Iterators.transform(buf.iterator(), new Function<Pair<Integer, T>, T>() {
        @Override
        public T apply(Pair<Integer, T> from) {
            return from.getSecond();
        }
    });
}

From source file:com.opengamma.web.analytics.formatting.LocalDateDoubleTimeSeriesFormatter.java

public Map<String, Object> formatExpanded(LocalDateDoubleTimeSeries value) {
    List<Object[]> data = Lists.newArrayListWithCapacity(value.size());
    for (LocalDateDoubleEntryIterator it = value.iterator(); it.hasNext();) {
        LocalDate date = it.nextTime();
        long epochMillis = date.toEpochDay() * MILLIS_PER_DAY;
        data.add(new Object[] { epochMillis, it.currentValue() });
    }//from  ww  w  . jav  a  2s. co  m
    Map<String, String> templateData = ImmutableMap.of("data_field", "Historical Time Series",
            "observation_time", "Historical Time Series");
    Map<String, Object> timeSeries = ImmutableMap.of("fieldLabels", new String[] { "Time", "Value" }, "data",
            data);
    return ImmutableMap.<String, Object>of("template_data", templateData, "timeseries", timeSeries);
}