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.sdnplatform.sync.internal.store.StoreUtils.java

public static <V> List<IVersion> getVersions(List<Versioned<V>> versioneds) {
    List<IVersion> versions = Lists.newArrayListWithCapacity(versioneds.size());
    for (Versioned<?> versioned : versioneds)
        versions.add(versioned.getVersion());
    return versions;
}

From source file:com.tinspx.util.io.ErrorIOException.java

/**
 * If {@code t} is an {@code ErrorIOException}, then its errors are returned
 * with {@code t} added as an error as well. If {@code t} is not an
 * {@code ErrorIOException}, {@code t} is returned as the sole error.
 *//*from  w  w w .j a  va2  s. c o  m*/
public static List<BasicError> split(@NonNull Throwable t) {
    if (t instanceof ErrorIOException) {
        List<BasicError> errors = ((ErrorIOException) t).errors;
        List<BasicError> el = Lists.newArrayListWithCapacity(errors.size() + 1);
        el.addAll(errors);
        el.add(Errors.create(t));
        return el;
    } else {
        return Lists.newArrayList(Errors.create(t));
    }
}

From source file:com.isotrol.impe3.palette.content.loader.ManyByFieldComponent.java

@Override
void load(ContentCriteria criteria) {
    final List<Content> list = Lists.newArrayListWithCapacity(10);
    if (config != null) {
        for (String v : Iterables.filter(
                Arrays.asList(config.fieldValue(), config.fieldValue2(), config.fieldValue3(),
                        config.fieldValue4(), config.fieldValue5(), config.fieldValue6(), config.fieldValue7(),
                        config.fieldValue8(), config.fieldValue9(), config.fieldValue10()),
                Predicates.notNull())) {
            final Content c = loadContent(criteria, v);
            if (c != null) {
                list.add(c);/*from w  ww . j a v  a2s  . com*/
            }

        }
    }
    contents = new ContentListingPage(list.size(), null, list);
}

From source file:com.mgmtp.jfunk.data.generator.constraint.FromTo.java

/**
 * @return always null - only affects the values of the sub-constraints.
 *//*from w ww.j a v a 2 s .c  om*/
@Override
public String initValues(final FieldCase c) {
    List<String> lastValues = Lists.newArrayListWithCapacity(constraints.size());
    List<String> values = Lists.newArrayListWithCapacity(constraints.size());
    List<String> sortedValues = Lists.newArrayListWithCapacity(constraints.size());
    int generate = 10000;
    int equalsCount = 0;
    while (generate > 0) {
        super.initValues(c);
        for (Constraint constraint : constraints) {
            String s = constraint.initValues(c);
            if (s != null) {
                values.add(s);
            }
        }
        if (values.isEmpty()) {
            break;
        }
        sortedValues.addAll(values);
        Collections.sort(sortedValues);
        if (values.equals(sortedValues)) {
            break;
        }
        if (values.equals(lastValues)) {
            equalsCount++;
        } else {
            equalsCount = 0;
        }
        if (equalsCount == 5) {
            log.debug("Generated values were equal in a row for five times und thus can be assumed as fixed");
            break;
        }
        lastValues.clear();
        lastValues.addAll(values);
        values.clear();
        sortedValues.clear();
        resetValues();
        generate--;
    }
    if (generate == 0) {
        throw new IllegalStateException("Could not generate values in ascending order after 10000 tries");
    }
    return null;
}

From source file:org.apache.kylin.cube.cli.CubeSignatureRefresher.java

public void update() {
    logger.info("Reloading Cube Metadata from store: "
            + store.getReadableResourcePath(ResourceStore.CUBE_DESC_RESOURCE_ROOT));
    CubeDescManager cubeDescManager = CubeDescManager.getInstance(config);
    List<CubeDesc> cubeDescs;
    if (ArrayUtils.isEmpty(cubeNames)) {
        cubeDescs = cubeDescManager.listAllDesc();
    } else {/*w  ww .j  av  a  2s . c o m*/
        String[] names = cubeNames[0].split(",");
        if (ArrayUtils.isEmpty(names))
            return;
        cubeDescs = Lists.newArrayListWithCapacity(names.length);
        for (String name : names) {
            cubeDescs.add(cubeDescManager.getCubeDesc(name));
        }
    }
    for (CubeDesc cubeDesc : cubeDescs) {
        updateCubeDesc(cubeDesc);
    }

    verify();
}

From source file:kr.debop4j.timeperiod.timerange.MonthRangeCollection.java

/**
 * Gets months.//w  ww .  j  a  v a 2s  .com
 *
 * @return the months
 */
public List<MonthRange> getMonths() {
    DateTime startTime = this.getStart();
    List<MonthRange> months = Lists.newArrayListWithCapacity(getMonthCount());

    for (int m = 0; m < getMonthCount(); m++) {
        months.add(new MonthRange(startTime.plusMonths(m), getTimeCalendar()));
    }
    return months;
}

From source file:org.grouplens.lenskit.eval.metrics.AbstractTestUserMetric.java

/**
 * Make a final aggregate result row. This expands it to the length of the columns, inserting
 * {@code null}s as needed./*from   w ww.  j  a  v  a  2  s .  c om*/
 * @return The result row, the same length as {@link #getColumnLabels()}.
 */
protected List<Object> finalRow(Object... results) {
    int len = getColumnLabels().size();
    Preconditions.checkArgument(results.length <= len, "too many results");
    ;
    List<Object> row = Lists.newArrayListWithCapacity(len);
    Collections.addAll(row, results);
    while (row.size() < len) {
        row.add(null);
    }
    return row;
}

From source file:org.codelibs.elasticsearch.taste.recommender.TopItems.java

public static List<RecommendedItem> getTopItems(final int howMany, final LongPrimitiveIterator possibleItemIDs,
        final IDRescorer rescorer, final Estimator<Long> estimator) {
    Preconditions.checkArgument(possibleItemIDs != null, "possibleItemIDs is null");
    Preconditions.checkArgument(estimator != null, "estimator is null");

    final Queue<RecommendedItem> topItems = new PriorityQueue<RecommendedItem>(howMany + 1,
            Collections.reverseOrder(ByValueRecommendedItemComparator.getInstance()));
    boolean full = false;
    double lowestTopValue = Double.NEGATIVE_INFINITY;
    while (possibleItemIDs.hasNext()) {
        final long itemID = possibleItemIDs.next();
        if (rescorer == null || !rescorer.isFiltered(itemID)) {
            double preference;
            try {
                preference = estimator.estimate(itemID);
            } catch (final NoSuchItemException nsie) {
                continue;
            }//from w  w w . j  a  v  a 2s. com
            final double rescoredPref = rescorer == null ? preference : rescorer.rescore(itemID, preference);
            if (!Double.isNaN(rescoredPref) && (!full || rescoredPref > lowestTopValue)) {
                topItems.add(new GenericRecommendedItem(itemID, (float) rescoredPref));
                if (full) {
                    topItems.poll();
                } else if (topItems.size() > howMany) {
                    full = true;
                    topItems.poll();
                }
                lowestTopValue = topItems.peek().getValue();
            }
        }
    }
    final int size = topItems.size();
    if (size == 0) {
        return Collections.emptyList();
    }
    final List<RecommendedItem> result = Lists.newArrayListWithCapacity(size);
    result.addAll(topItems);
    Collections.sort(result, ByValueRecommendedItemComparator.getInstance());
    return result;
}

From source file:org.terasology.persistence.typeHandling.coreTypes.EnumTypeHandler.java

@Override
public PersistedData serializeCollection(Collection<T> value, SerializationContext context) {
    List<String> values = Lists.newArrayListWithCapacity(value.size());
    for (T item : value) {
        values.add(item.toString());//from  w ww  .ja v a2 s.  c  o  m
    }
    return context.createStrings(values);
}

From source file:org.apache.tez.dag.history.events.VertexDataMovementEventsGeneratedEvent.java

public VertexDataMovementEventsGeneratedEvent(TezVertexID vertexID, List<TezEvent> events) {
    this.vertexID = vertexID;
    this.events = Lists.newArrayListWithCapacity(events.size());
    for (TezEvent event : events) {
        if (EnumSet.of(EventType.DATA_MOVEMENT_EVENT, EventType.COMPOSITE_DATA_MOVEMENT_EVENT,
                EventType.ROOT_INPUT_DATA_INFORMATION_EVENT).contains(event.getEventType())) {
            this.events.add(event);
        }/*from w  w w  .  jav a 2  s  . co m*/
    }
    if (events.isEmpty()) {
        throw new RuntimeException("Invalid creation of VertexDataMovementEventsGeneratedEvent"
                + ", no data movement/information events provided");
    }
}