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:com.google.gcloud.datastore.BaseDatastoreBatchWriter.java

@SuppressWarnings("unchecked")
@Override//from ww w. ja  v  a 2s .  c  o m
public final List<Entity> add(FullEntity<?>... entities) {
    validateActive();
    List<IncompleteKey> incompleteKeys = Lists.newArrayListWithExpectedSize(entities.length);
    for (FullEntity<?> entity : entities) {
        IncompleteKey key = entity.key();
        Preconditions.checkArgument(key != null, "Entity must have a key");
        if (key instanceof Key) {
            addInternal((FullEntity<Key>) entity);
        } else {
            incompleteKeys.add(key);
        }
    }
    Iterator<Key> allocated;
    if (!incompleteKeys.isEmpty()) {
        IncompleteKey[] toAllocate = Iterables.toArray(incompleteKeys, IncompleteKey.class);
        allocated = datastore().allocateId(toAllocate).iterator();
    } else {
        allocated = Collections.emptyIterator();
    }
    List<Entity> answer = Lists.newArrayListWithExpectedSize(entities.length);
    for (FullEntity<?> entity : entities) {
        if (entity.key() instanceof Key) {
            answer.add(Entity.convert((FullEntity<Key>) entity));
        } else {
            Entity entityWithAllocatedId = Entity.builder(allocated.next(), entity).build();
            addInternal(entityWithAllocatedId);
            answer.add(entityWithAllocatedId);
        }
    }
    return answer;
}

From source file:com.arpnetworking.tsdcore.sinks.ServiceNameFilteringSink.java

private static List<Pattern> compileExpressions(final List<String> expressions) {
    final List<Pattern> patterns = Lists.newArrayListWithExpectedSize(expressions.size());
    for (final String expression : expressions) {
        patterns.add(Pattern.compile(expression));
    }/*from  w w  w .jav  a 2  s . c o  m*/
    return patterns;
}

From source file:org.apache.shindig.common.servlet.HttpUtil.java

public static List<Pair<String, String>> getCachingHeadersToSet(int ttl, boolean noProxy) {
    List<Pair<String, String>> cachingHeaders = Lists.newArrayListWithExpectedSize(3);
    cachingHeaders.add(//from ww  w  . jav  a 2s  .  c  om
            Pair.of("Expires", DateUtil.formatRfc1123Date(timeSource.currentTimeMillis() + (1000L * ttl))));

    if (ttl <= 0) {
        cachingHeaders.add(Pair.of("Pragma", "no-cache"));
        cachingHeaders.add(Pair.of("Cache-Control", "no-cache"));
    } else {
        if (noProxy) {
            cachingHeaders.add(Pair.of("Cache-Control", "private,max-age=" + Integer.toString(ttl)));
        } else {
            cachingHeaders.add(Pair.of("Cache-Control", "public,max-age=" + Integer.toString(ttl)));
        }
    }

    return cachingHeaders;
}

From source file:org.elasticsearch.common.lucene.index.FilterableTermsEnum.java

public FilterableTermsEnum(IndexReader reader, String field, int docsEnumFlag, @Nullable Filter filter)
        throws IOException {
    if ((docsEnumFlag != DocsEnum.FLAG_FREQS) && (docsEnumFlag != DocsEnum.FLAG_NONE)) {
        throw new ElasticsearchIllegalArgumentException("invalid docsEnumFlag of " + docsEnumFlag);
    }//from  w  w w  .jav  a2 s . c  o  m
    this.docsEnumFlag = docsEnumFlag;
    if (filter == null) {
        numDocs = reader.numDocs();
    }

    List<AtomicReaderContext> leaves = reader.leaves();
    List<Holder> enums = Lists.newArrayListWithExpectedSize(leaves.size());
    for (AtomicReaderContext context : leaves) {
        Terms terms = context.reader().terms(field);
        if (terms == null) {
            continue;
        }
        TermsEnum termsEnum = terms.iterator(null);
        if (termsEnum == null) {
            continue;
        }
        Bits bits = null;
        if (filter != null) {
            if (filter == Queries.MATCH_ALL_FILTER) {
                bits = context.reader().getLiveDocs();
            } else {
                // we want to force apply deleted docs
                filter = new ApplyAcceptedDocsFilter(filter);
                DocIdSet docIdSet = filter.getDocIdSet(context, context.reader().getLiveDocs());
                if (DocIdSets.isEmpty(docIdSet)) {
                    // fully filtered, none matching, no need to iterate on this
                    continue;
                }
                bits = DocIdSets.toSafeBits(context.reader(), docIdSet);
                // Count how many docs are in our filtered set
                // TODO make this lazy-loaded only for those that need it?
                DocIdSetIterator iterator = docIdSet.iterator();
                if (iterator != null) {
                    while (iterator.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
                        numDocs++;
                    }
                }
            }
        }
        enums.add(new Holder(termsEnum, bits));
    }
    this.enums = enums.toArray(new Holder[enums.size()]);
}

From source file:org.attribyte.api.http.Header.java

/**
 * Parses ';' separated parameters in a header value.
 * @param headerValue The header value.// w  w  w  .j ava 2s  .  c om
 * @return A list of parameters.
 */
public static List<Parameter> parseParameters(final String headerValue) {
    if (headerValue == null) {
        return Collections.emptyList();
    }

    int start = headerValue.indexOf(';');
    if (start < 2) {
        return Collections.emptyList();
    }

    List<Parameter> parameters = Lists.newArrayListWithExpectedSize(4);

    try {
        Map<String, String> parameterMap = parameterSplitter.split(headerValue.substring(start));
        for (Map.Entry<String, String> kv : parameterMap.entrySet()) {
            parameters.add(new Parameter(kv.getKey(), kv.getValue()));
        }

        return parameters;
    } catch (IllegalArgumentException iae) { //Invalid parameters...
        return Collections.emptyList();
    }
}

From source file:org.jclouds.profitbricks.compute.function.ServerToNodeMetadata.java

@Inject
ServerToNodeMetadata(Function<Storage, Volume> fnVolume, @Memoized Supplier<Set<? extends Location>> locations,
        ProfitBricksApi api, GroupNamingConvention.Factory groupNamingConvention) {
    this.fnVolume = fnVolume;
    this.locations = locations;
    this.api = api;
    this.groupNamingConvention = groupNamingConvention.createWithoutPrefix();
    this.fnCollectIps = new Function<List<Nic>, List<String>>() {
        @Override//from  w w  w.  java 2s .  c  o m
        public List<String> apply(List<Nic> in) {
            List<String> ips = Lists.newArrayListWithExpectedSize(in.size());
            for (Nic nic : in)
                ips.addAll(nic.ips());
            return ips;
        }
    };
}

From source file:org.envirocar.server.rest.schema.GuiceRunner.java

protected List<Module> getModulesFromAnnotation(Class<?> clazz) throws InitializationError {
    Modules annotation = clazz.getAnnotation(Modules.class);
    if (annotation != null) {
        Class<? extends Module>[] classes = annotation.value();
        List<Module> modules = Lists.newArrayListWithExpectedSize(classes.length);
        for (Class<? extends Module> c : classes) {
            modules.add(instantiate(c));
        }//from   w w  w .  j  a va 2 s  .  c  o  m
        return modules;
    } else {
        return Collections.emptyList();
    }
}

From source file:org.apache.phoenix.end2end.index.IndexTestUtil.java

public static List<Mutation> generateIndexData(PTable index, PTable table, List<Mutation> dataMutations,
        ImmutableBytesWritable ptr, KeyValueBuilder builder) throws SQLException {
    List<Mutation> indexMutations = Lists.newArrayListWithExpectedSize(dataMutations.size());
    for (Mutation dataMutation : dataMutations) {
        indexMutations.addAll(generateIndexData(index, table, dataMutation, ptr, builder));
    }/*from  w w w .j  a  v  a 2 s.co  m*/
    return indexMutations;
}

From source file:be.nbb.jackcess.JackcessStatement.java

private static List<Column> getAllByName(Table table, Collection<String> columnNames) {
    List<Column> result = Lists.newArrayListWithExpectedSize(columnNames.size());
    for (String o : columnNames) {
        result.add(table.getColumn(o));/*from w w  w.  jav a  2s.  c  o m*/
    }
    return result;
}

From source file:io.atomix.utils.concurrent.AbstractAccumulator.java

/**
 * Creates an item accumulator capable of triggering on the specified
 * thresholds./*from  w w  w . j ava  2  s .  c  o m*/
 *
 * @param timer          timer to use for scheduling check-points
 * @param maxItems       maximum number of items to accumulate before
 *                       processing is triggered
 *                       <p>
 *                       NB: It is possible that processItems will contain
 *                       more than maxItems under high load or if isReady()
 *                       can return false.
 *                       </p>
 * @param maxBatchMillis maximum number of millis allowed since the first
 *                       item before processing is triggered
 * @param maxIdleMillis  maximum number millis between items before
 *                       processing is triggered
 */
protected AbstractAccumulator(Timer timer, int maxItems, int maxBatchMillis, int maxIdleMillis) {
    this.timer = checkNotNull(timer, "Timer cannot be null");

    checkArgument(maxItems > 1, "Maximum number of items must be > 1");
    checkArgument(maxBatchMillis > 0, "Maximum millis must be positive");
    checkArgument(maxIdleMillis > 0, "Maximum idle millis must be positive");

    this.maxItems = maxItems;
    this.maxBatchMillis = maxBatchMillis;
    this.maxIdleMillis = maxIdleMillis;

    items = Lists.newArrayListWithExpectedSize(maxItems);
}