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.novelang.common.tree.TreeTools.java

/**
 * Returns a copy of a {@code Tree} with the {@code newChild} added as last child.
 *
 * @param tree a non-null object that may implement {@link StorageTypeProvider}.
 * @param newChild a non-null object.//ww  w.  j  a  v a  2 s  .  c  o m
 * @return a non-null object.
 */
public static <T extends Tree<T>> T addLast(final T tree, final T newChild) {
    final List<T> newChildList = Lists.newArrayListWithCapacity(tree.getChildCount() + 1);
    for (int i = 0; i < tree.getChildCount(); i++) {
        newChildList.add(i, tree.getChildAt(i));
    }
    newChildList.add(Preconditions.checkNotNull(newChild));
    return tree.adopt(newChildList);
}

From source file:com.lastcalc.TokenList.java

public CompositeTokenList append(final TokenList... toAppend) {
    final ArrayList<TokenList> tls = Lists.newArrayListWithCapacity(toAppend.length + 1);
    tls.add(this);
    for (int x = 0; x < toAppend.length; x++) {
        tls.add(toAppend[x]);//from   ww  w .j  a  va 2s .  co  m
    }
    return new CompositeTokenList(tls);
}

From source file:org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider.java

@Override
@CheckForNull/*from w ww .  j av a  2s  . c  o  m*/
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info)
        throws CommitFailedException {
    List<Editor> list = Lists.newArrayListWithCapacity(providers.size());
    for (EditorProvider provider : providers) {
        Editor editor = provider.getRootEditor(before, after, builder, info);
        if (editor != null) {
            list.add(editor);
        }
    }
    return CompositeEditor.compose(list);
}

From source file:net.myrrix.online.MultiRescorerProvider.java

@Override
public IDRescorer getRecommendToAnonymousRescorer(long[] itemIDs, MyrrixRecommender recommender,
        String... args) {// ww w . j  a  va2  s.c  o m
    List<IDRescorer> rescorers = Lists.newArrayListWithCapacity(providers.length);
    for (RescorerProvider provider : providers) {
        IDRescorer rescorer = provider.getRecommendToAnonymousRescorer(itemIDs, recommender, args);
        if (rescorer != null) {
            rescorers.add(rescorer);
        }
    }
    return buildRescorer(rescorers);
}

From source file:org.elasticsearch.action.support.AbstractListenableActionFuture.java

public void internalAddListener(Object listener) {
    boolean executeImmediate = false;
    synchronized (this) {
        if (executedListeners) {
            executeImmediate = true;//  w  w  w.  j ava2  s  .  c om
        } else {
            Object listeners = this.listeners;
            if (listeners == null) {
                listeners = listener;
            } else if (listeners instanceof List) {
                ((List) this.listeners).add(listener);
            } else {
                Object orig = listeners;
                listeners = Lists.newArrayListWithCapacity(2);
                ((List) listeners).add(orig);
                ((List) listeners).add(listener);
            }
            this.listeners = listeners;
        }
    }
    if (executeImmediate) {
        executeListener(listener);
    }
}

From source file:at.molindo.esi4j.action.impl.DefaultMultiSearchResponseWrapper.java

@Override
public <T> List<T> getObjects(Class<T> type) {
    List<MultiSearchItemResponseWrapper> resps = getMultiSearchItemResponses();

    int size = 0;
    for (MultiSearchItemResponseWrapper response : resps) {
        size += response.getSearchHits().size();
    }/*from   ww w  .ja  v a 2  s  .  co  m*/

    List<T> objects = Lists.newArrayListWithCapacity(size);

    for (MultiSearchItemResponseWrapper response : resps) {
        objects.addAll(response.getObjects(type));
    }

    return objects;
}

From source file:org.apache.impala.analysis.RangePartition.java

/**
 * Constructs a range partition. The range is specified in the CREATE TABLE statement
 * using the 'PARTITION <expr> OP VALUES OP <expr>' clause. 'lower' corresponds to
 * the '<expr> OP' pair which defines an optional lower bound. 'upper' corresponds to
 * the 'OP <expr>' pair which defines an optional upper bound. Since only '<' and
 * '<=' operators are allowed, operators are represented with boolean values that
 * indicate inclusive or exclusive bounds.
 *//*from w  w w  .j a  v  a 2 s.c  o m*/
public static RangePartition createFromRange(Pair<Expr, Boolean> lower, Pair<Expr, Boolean> upper) {
    List<Expr> lowerBoundExprs = Lists.newArrayListWithCapacity(1);
    boolean lowerBoundInclusive = false;
    List<Expr> upperBoundExprs = Lists.newArrayListWithCapacity(1);
    boolean upperBoundInclusive = false;
    if (lower != null) {
        lowerBoundExprs.add(lower.first);
        lowerBoundInclusive = lower.second;
    }
    if (upper != null) {
        upperBoundExprs.add(upper.first);
        upperBoundInclusive = upper.second;
    }
    return new RangePartition(lowerBoundExprs, lowerBoundInclusive, upperBoundExprs, upperBoundInclusive);
}

From source file:com.isotrol.impe3.palette.freemarker.model.ListingModelComponent.java

private Listing<Content> loadSampleListing() {
    final Content sample = loadSample();
    if (sample == null) {
        return ContentListingPage.EMPTY;
    }//from w w  w . j a v  a2 s  .c  om
    int n = Math.max(10, moduleConfig.sampleCount());
    final List<Content> list = Lists.newArrayListWithCapacity(n);
    for (int i = 0; i < n; i++) {
        list.add(sample);
    }
    return new ContentListingPage(null, context.getPagination(), list);

}

From source file:org.geogit.metrics.CallStack.java

private CallStack add(final String name) {
    CallStack cs = new CallStack(name, false);
    if (this.children == null) {
        this.children = Lists.newArrayListWithCapacity(4);
    }/*from  w w w . j a  v  a2s . co  m*/
    this.children.add(cs);
    return cs;
}

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

public VertexRecoverableEventsGeneratedEvent(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, EventType.ROOT_INPUT_INITIALIZER_EVENT)
                .contains(event.getEventType())) {
            this.events.add(event);
        }//from w  w w. j av  a 2s . c  o m
    }
    if (events.isEmpty()) {
        throw new RuntimeException("Invalid creation of VertexDataMovementEventsGeneratedEvent"
                + ", no data movement/information events provided");
    }
}