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.hadoop.hive.druid.QTestDruidQueryBasedInputFormatToAddFaultyHost.java

@Override
protected HiveDruidSplit[] getInputSplits(Configuration conf) throws IOException {
    HiveDruidSplit[] inputSplits = super.getInputSplits(conf);
    List<HiveDruidSplit> list = new ArrayList<>();
    for (HiveDruidSplit split : inputSplits) {
        String[] locations = split.getLocations();
        List<String> locationsWithFaultyHost = Lists.newArrayListWithCapacity(locations.length + 1);
        // A non-queryable host location.
        locationsWithFaultyHost.add("localhost:8081");
        locationsWithFaultyHost.addAll(Arrays.asList(locations));
        HiveDruidSplit hiveDruidSplit = new HiveDruidSplit(split.getDruidQuery(), split.getPath(),
                locationsWithFaultyHost.toArray(new String[0]));
        list.add(hiveDruidSplit);/*from  w ww .  j a  v a2s  .com*/
    }
    return list.toArray(new HiveDruidSplit[0]);
}

From source file:net.sf.lucis.core.impl.MultiSearcherProvider.java

public LucisSearcher get() {
    try {/* w  ww  . j a va  2 s .  com*/
        List<IndexReader> readers = Lists.newArrayListWithCapacity(providers.size());
        for (DirectoryProvider p : providers) {
            Directory d = p.getDirectory();
            if (d != null && IndexReader.indexExists(d)) {
                readers.add(IndexReader.open(d));
            }
        }
        if (readers.isEmpty()) {
            final IndexReader reader = IndexReader.open(EmptyDirectory.get());
            readers.add(reader);
        }
        return new DefaultLucisSearcher(new MultiReader(readers.toArray(new IndexReader[readers.size()])));
    } catch (Exception e) {
        throw new IndexNotAvailableException(e);
    }
}

From source file:de.cosmocode.palava.ipc.cache.analyzer.CaseCacheAnalyzer.java

@Override
protected CacheDecision decide(CaseCached annotation, IpcCall call, IpcCommand command) {
    final Class<? extends CachePredicate>[] predicates = annotation.predicates();
    final List<CachePredicate> filters = Lists.newArrayListWithCapacity(predicates.length);

    for (Class<? extends CachePredicate> predicateClass : predicates) {
        filters.add(injector.getInstance(predicateClass));
    }/*from w  w  w.  j av  a  2s .  c om*/

    final boolean shouldCache = annotation.mode().apply(filters, call, command);
    final CacheKeyFactory keyFactory;

    if (annotation.keyFactory() == DefaultCacheKeyFactory.class) {
        keyFactory = DefaultCacheKeyFactory.INSTANCE;
    } else {
        keyFactory = injector.getInstance(annotation.keyFactory());
    }

    return new CaseCacheDecision(shouldCache, annotation, keyFactory);
}

From source file:com.opengamma.integration.viewer.status.impl.SimpleViewStatusModel.java

private List<List<Object>> deepCopyRows(List<List<Object>> rows) {
    List<List<Object>> result = Lists.newArrayListWithCapacity(rows.size());
    for (List<Object> row : rows) {
        result.add(Lists.newArrayList(row));
    }/*from  www .j  a  v a  2s .co m*/
    return result;
}

From source file:com.github.steveash.jg2p.aligntag.AlignTagModel.java

@Override
public List<Alignment> inferAlignments(Word x, int nBest) {
    Instance instance = new Instance(x.getValue(), null, null, null);
    instance = crf.getInputPipe().instanceFrom(instance);

    Sequence inSeq = (Sequence) instance.getData();
    List<Sequence<Object>> outSeqs = crf.getMaxLatticeFactory().newMaxLattice(crf, inSeq)
            .bestOutputSequences(nBest);

    ArrayList<Alignment> results = Lists.newArrayListWithCapacity(outSeqs.size());
    double z = crf.getSumLatticeFactory().newSumLattice(crf, inSeq).getTotalWeight();
    for (Sequence<Object> outSeq : outSeqs) {
        double score = crf.getSumLatticeFactory().newSumLattice(crf, inSeq, outSeq).getTotalWeight();
        List<Pair<String, String>> graphemes = makeGraphemes(x, outSeq);
        if (!resultsContain(graphemes, results)) {
            results.add(new Alignment(x, graphemes, score - z));
        }/*from   w w  w  .  j a va  2s . com*/
    }
    return results;
}

From source file:com.netflix.staash.mesh.endpoints.ChordEndpointPolicy.java

@Override
public List<InstanceInfo> getEndpoints(InstanceInfo current, List<InstanceInfo> instances) {
    int position = Collections.binarySearch(instances, current, comparator);
    int size = instances.size();
    int count = (int) Math.ceil(Math.log(size) / LOG_2);

    List<InstanceInfo> endpoints = Lists.newArrayListWithCapacity(count);

    int offset = 1;
    for (int i = 0; i < count; i++) {
        endpoints.add(instances.get((position + offset) % size));
        offset *= 2;//from  w ww. j  a  v a2 s  .c om
    }
    return endpoints;
}

From source file:com.android.build.gradle.internal.model.SourceProviderImpl.java

@NonNull
static Collection<SourceProvider> cloneCollection(@NonNull Collection<SourceProvider> sourceProviders) {
    Collection<SourceProvider> results = Lists.newArrayListWithCapacity(sourceProviders.size());
    for (SourceProvider sourceProvider : sourceProviders) {
        results.add(SourceProviderImpl.cloneProvider(sourceProvider));
    }//from w  w  w.j a  va  2  s.c  o  m

    return results;
}

From source file:net.sourceforge.cilib.coevolution.competitive.PopulationCompetitorList.java

public PopulationCompetitorList(PopulationCompetitorList other) {
    competitors = Lists.newArrayListWithCapacity(other.size());

    for (Competitor c : other.competitors) {
        competitors.add(c.getClone());/*from w  ww. j a  v a2  s  . c om*/
    }
}

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

@Override
public synchronized List<MultiGetItemResponseWrapper> getMultiGetItemResponses() {
    if (_objects == null) {
        MultiGetItemResponse[] reps = _response.getResponses();
        _objects = Lists.newArrayListWithCapacity(reps.length);
        for (int i = 0; i < reps.length; i++) {
            _objects.add(new DefaultMultiGetItemResponseWrapper(reps[i], _reader));
        }//from ww  w  .  j ava2 s.co m
    }
    return _objects;
}

From source file:com.googlesource.gerrit.plugins.gitiles.MenuFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    CurrentUser user = userProvider.get();
    List<Object> entries = Lists.newArrayListWithCapacity(3);
    entries.add(BaseServlet.menuEntry("Code Review", urls.getBaseGerritUrl(req)));
    if (user instanceof IdentifiedUser) {
        entries.add(BaseServlet.menuEntry(((IdentifiedUser) user).getName(), null));
        entries.add(BaseServlet.menuEntry("Sign Out", urls.getBaseGerritUrl(req) + "logout"));
    } else {/* www .j av  a  2 s.  co m*/
        entries.add(BaseServlet.menuEntry("Sign In", urls.getBaseGerritUrl(req) + "login"));
    }
    BaseServlet.putSoyData(req, "menuEntries", entries);
    chain.doFilter(request, response);
}