List of usage examples for com.google.common.collect Lists newArrayListWithCapacity
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize)
From source file:voldemort.store.slop.strategy.HandoffToAnyStrategy.java
public List<Node> routeHint(Node origin) { List<Node> prefList = Lists.newArrayListWithCapacity(nodes.size()); int originZoneId = origin.getZoneId(); for (Node node : nodes) { if (node.getId() != origin.getId()) { if (enableZoneRouting && zones.size() > 1) { if (originZoneId == clientZoneId) { if (node.getZoneId() != clientZoneId) continue; } else { if (node.getZoneId() == originZoneId) continue; }/*ww w. java 2 s . com*/ } prefList.add(node); } } Collections.shuffle(prefList); return prefList; }
From source file:net.sf.lucis.core.impl.ManagedMultiSearcherProvider.java
public LucisSearcher get() { try {//from www . ja v a 2 s .c om List<IndexReader> readers = Lists.newArrayListWithCapacity(providers.size()); for (DirectoryProvider p : providers) { readers.add(p.getManagedReader()); } 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:com.android.tools.lint.psi.EcjPsiExpressionList.java
@NonNull @Override// w w w. j av a2s . com public PsiType[] getExpressionTypes() { List<PsiType> types = Lists.newArrayListWithCapacity(mExpressions.length); for (PsiExpression expression : mExpressions) { PsiType type = expression.getType(); if (type != null) { types.add(type); } } return types.toArray(PsiType.EMPTY_ARRAY); }
From source file:org.jiemamy.utils.collection.ArrayMap.java
/** * ?? * * @param capacity */ public ArrayMap(int capacity) { super(capacity); valueList = Lists.newArrayListWithCapacity(capacity); }
From source file:org.lenskit.eval.crossfold.CrossfoldOutput.java
public CrossfoldOutput(Crossfolder cf, Random rng) throws IOException { random = rng;//w w w . j a v a 2s .c o m closer = Closer.create(); count = cf.getPartitionCount(); trainWriters = Lists.newArrayListWithCapacity(count); testWriters = Lists.newArrayListWithCapacity(count); try { for (Path path : cf.getTrainingFiles()) { trainWriters.add(closer.register(cf.openWriter(path))); } for (Path path : cf.getTestFiles()) { testWriters.add(closer.register(cf.openWriter(path))); } } catch (Exception ex) { // this funny logic is needed to make the closer add any close exceptions as suppressed exceptions // to the exception we're failing with try { throw closer.rethrow(ex); } finally { closer.close(); } } // the constructor has succeeded - closing will be handled by the close method }
From source file:com.google.dart.compiler.ast.NodeList.java
@Override public void add(int index, E element) { if (elements == null) { elements = Lists.newArrayListWithCapacity(2); }//from w w w . jav a 2 s .c om elements.add(element); owner.becomeParentOf(element); }
From source file:io.vitess.hadoop.RowWritable.java
@Override public void readFields(DataInput in) throws IOException { int numFields = in.readInt(); List<Field> fields = Lists.newArrayListWithCapacity(numFields); for (int i = 0; i < numFields; i++) { fields.add(Field.parseFrom(BaseEncoding.base64().decode(in.readUTF()))); }//from w ww. j a v a 2 s . com Query.Row rowProto = Query.Row.parseFrom(BaseEncoding.base64().decode(in.readUTF())); row = new Row(fields, rowProto); }
From source file:org.apache.druid.segment.filter.AndFilter.java
private static <T> T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory<T> bitmapResultFactory, List<Filter> filters) { if (filters.size() == 1) { return filters.get(0).getBitmapResult(selector, bitmapResultFactory); }//from w w w .jav a 2s . co m final List<T> bitmapResults = Lists.newArrayListWithCapacity(filters.size()); for (final Filter filter : filters) { Preconditions.checkArgument(filter.supportsBitmapIndex(selector), "Filter[%s] does not support bitmap index", filter); final T bitmapResult = filter.getBitmapResult(selector, bitmapResultFactory); if (bitmapResultFactory.isEmpty(bitmapResult)) { // Short-circuit. return bitmapResultFactory.wrapAllFalse(Filters.allFalse(selector)); } bitmapResults.add(bitmapResult); } return bitmapResultFactory.intersection(bitmapResults); }
From source file:org.eclipse.xtext.builder.trace.DebugTraceBasedRegion.java
@Override public List<ILocationData> getAssociatedLocations() { List<ILocationData> result = Lists.newArrayListWithCapacity(delegate.getAssociations().size()); for (DebugLocationData data : delegate.getAssociations()) result.add(convert(data));/* www . j a v a 2s .co m*/ return result; }
From source file:com.lastcalc.parsers.PreParser.java
public static TokenList flatten(final TokenList input) { boolean willFlatten = false; for (final Object o : input) { if (o instanceof TokenList) { willFlatten = true;/*from w w w .jav a2 s . c o m*/ break; } if (o instanceof List) { willFlatten = true; break; } if (o instanceof Map) { willFlatten = true; break; } if (o instanceof ListWithTail || o instanceof MapWithTail) { willFlatten = true; break; } } if (!willFlatten) return input; final List<Object> ret = Lists.newArrayListWithCapacity(input.size() * 4); flattenTo(input, ret); return TokenList.create(ret); }