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:org.terasology.world.block.tiles.WorldAtlasImpl.java

@Override
public void update() {
    if (!reloadQueue.isEmpty()) {
        List<BlockTile> reloadList = Lists.newArrayListWithExpectedSize(reloadQueue.size());
        reloadQueue.drainTo(reloadList);
        // TODO: does this need to be more efficient? could just reload individual block tile locations.
        buildAtlas();//from  w w  w .ja v a  2s  .c  om
    }
}

From source file:org.eclipse.xtext.xbase.scoping.SyntaxFilteredScopes.java

public List<String> getEnumeratedValues(ParserRule rule) {
    List<String> result = new XtextSwitch<List<String>>() {
        @Override/*from  w  ww  . j av a2  s . c  o m*/
        public List<String> caseKeyword(Keyword object) {
            if (GrammarUtil.isMultipleCardinality(object)) {
                return Collections.emptyList();
            }
            if (GrammarUtil.isOptionalCardinality(object)) {
                return Lists.newArrayList("", object.getValue());
            }
            return Lists.newArrayList(object.getValue());
        }

        @Override
        public List<String> caseAssignment(Assignment object) {
            if (GrammarUtil.isMultipleCardinality(object)) {
                return Collections.emptyList();
            }
            List<String> nested = doSwitch(object.getTerminal());
            if (GrammarUtil.isOptionalCardinality(object)) {
                if (nested.isEmpty()) {
                    return Collections.emptyList();
                }
                nested.add("");
            }
            return nested;
        }

        @Override
        public List<String> caseAlternatives(Alternatives object) {
            if (GrammarUtil.isMultipleCardinality(object)) {
                return Collections.emptyList();
            }
            List<String> result = Lists.newArrayList();
            if (GrammarUtil.isOptionalCardinality(object)) {
                result.add("");
            }
            for (AbstractElement element : object.getElements()) {
                List<String> nested = doSwitch(element);
                if (nested.isEmpty()) {
                    return Collections.emptyList();
                }
                result.addAll(nested);
            }
            return result;
        }

        @Override
        public List<String> caseGroup(Group object) {
            if (GrammarUtil.isMultipleCardinality(object)) {
                return Collections.emptyList();
            }
            List<String> result = Lists.newArrayList();
            for (AbstractElement element : object.getElements()) {
                List<String> nested = doSwitch(element);
                if (nested.isEmpty()) {
                    return Collections.emptyList();
                }
                if (result.isEmpty()) {
                    result.addAll(nested);
                } else if (nested.size() == 1) {
                    String addMe = nested.get(0);
                    for (int i = 0; i < result.size(); i++) {
                        result.set(i, result.get(i) + addMe);
                    }
                } else {
                    List<String> wasResult = result;
                    result = Lists.newArrayListWithExpectedSize(result.size() * nested.size());
                    for (String prefix : wasResult) {
                        for (String suffix : nested) {
                            result.add(prefix + suffix);
                        }
                    }
                }
            }
            if (GrammarUtil.isOptionalCardinality(object)) {
                result.add("");
            }
            return result;
        }

        @Override
        public List<String> caseAbstractElement(AbstractElement object) {
            return Collections.emptyList();
        }
    }.doSwitch(rule.getAlternatives());
    return result;
}

From source file:org.terasology.logic.console.commandSystem.MethodCommand.java

@Override
protected List<Parameter> constructParameters(Context context) {
    SpecificAccessibleObject<Method> specificExecutionMethod = getExecutionMethod();
    Method executionMethod = specificExecutionMethod.getAccessibleObject();
    Class<?>[] methodParameters = executionMethod.getParameterTypes();
    Annotation[][] methodParameterAnnotations = executionMethod.getParameterAnnotations();
    List<Parameter> parameters = Lists.newArrayListWithExpectedSize(methodParameters.length);

    for (int i = 0; i < methodParameters.length; i++) {
        parameters.add(getParameterTypeFor(methodParameters[i], methodParameterAnnotations[i], context));
    }//  w w  w  .ja v  a2s.  c  om

    return parameters;
}

From source file:org.envirocar.server.mongo.dao.MongoTrackDao.java

protected <T> List<Object> toIdList(List<Key<T>> keys) {
    List<Object> ids = Lists.newArrayListWithExpectedSize(keys.size());
    for (Key<T> key : keys) {
        ids.add(key.getId());//from  w w w  . j  av  a  2 s  .  co  m
    }
    return ids;
}

From source file:org.apache.phoenix.compile.OrderPreservingTracker.java

public OrderPreservingTracker(StatementContext context, GroupBy groupBy, Ordering ordering, int nNodes,
        TupleProjector projector) {//  w w w  .jav  a  2 s  . co m
    this.context = context;
    int pkPositionOffset = 0;
    PTable table = context.getResolver().getTables().get(0).getTable();
    isOrderPreserving = table.rowKeyOrderOptimizable();
    if (groupBy.isEmpty()) { // FIXME: would the below table have any of these set in the case of a GROUP BY?
        boolean isSalted = table.getBucketNum() != null;
        boolean isMultiTenant = context.getConnection().getTenantId() != null && table.isMultiTenant();
        boolean isSharedViewIndex = table.getViewIndexId() != null;
        // TODO: util for this offset, as it's computed in numerous places
        pkPositionOffset = (isSalted ? 1 : 0) + (isMultiTenant ? 1 : 0) + (isSharedViewIndex ? 1 : 0);
    }
    this.pkPositionOffset = pkPositionOffset;
    this.groupBy = groupBy;
    this.visitor = new TrackOrderPreservingExpressionVisitor(projector);
    this.orderPreservingInfos = Lists.newArrayListWithExpectedSize(nNodes);
    this.ordering = ordering;
}

From source file:co.cask.cdap.logging.read.StandaloneLogReader.java

@Override
public void getLogNext(final LoggingContext loggingContext, final long fromOffset, final int maxEvents,
        final Filter filter, final Callback callback) {
    if (fromOffset < 0) {
        getLogPrev(loggingContext, -1, maxEvents, filter, callback);
        return;/*w  w w . j  a  v a  2s.  com*/
    }

    executor.submit(new Runnable() {
        @Override
        public void run() {
            callback.init();

            try {
                Filter logFilter = new AndFilter(
                        ImmutableList.of(LoggingContextHelper.createFilter(loggingContext), filter));
                long fromTimeMs = fromOffset + 1;

                SortedMap<Long, Location> sortedFiles = fileMetaDataManager.listFiles(loggingContext);
                if (sortedFiles.isEmpty()) {
                    return;
                }

                long prevInterval = -1;
                Location prevPath = null;
                List<Location> tailFiles = Lists.newArrayListWithExpectedSize(sortedFiles.size());
                for (Map.Entry<Long, Location> entry : sortedFiles.entrySet()) {
                    if (entry.getKey() >= fromTimeMs && prevPath != null) {
                        tailFiles.add(prevPath);
                    }
                    prevInterval = entry.getKey();
                    prevPath = entry.getValue();
                }

                if (prevInterval != -1) {
                    tailFiles.add(prevPath);
                }

                AvroFileLogReader logReader = new AvroFileLogReader(schema);
                CountingCallback countingCallback = new CountingCallback(callback);
                for (Location file : tailFiles) {
                    logReader.readLog(file, logFilter, fromTimeMs, Long.MAX_VALUE,
                            maxEvents - countingCallback.getCount(), countingCallback);
                    if (countingCallback.getCount() >= maxEvents) {
                        break;
                    }
                }
            } catch (Throwable e) {
                LOG.error("Got exception: ", e);
                throw Throwables.propagate(e);
            } finally {
                callback.close();
            }
        }
    });
}

From source file:org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil.java

private static List<String> getValues(final Configuration configuration, final String VALUE_COUNT,
        final String VALUE_NAME) {
    Preconditions.checkNotNull(configuration);
    int numCols = configuration.getInt(VALUE_COUNT, 0);
    List<String> cols = Lists.newArrayListWithExpectedSize(numCols);
    for (int i = 0; i < numCols; ++i) {
        cols.add(configuration.get(String.format("%s_%d", VALUE_NAME, i)));
    }//from  w w  w .jav a 2 s.co m
    return cols;
}

From source file:org.eclipse.xtext.ide.editor.syntaxcoloring.MergingHighlightedPositionAcceptor.java

private void mergePositions(int listIdx, int exclusiveEndOffset, int timestamp, IntToStringArray[] ids) {
    int i = listIdx;
    List<LightweightPosition> newPositions = null;
    LightweightPosition prev = null;/*from w  w w. j a  v  a  2s  .  c  o m*/
    while (i < getPositions().size()) {
        LightweightPosition next = getPositions().get(i);
        if (next.getOffset() >= exclusiveEndOffset) {
            newPositions = addPendingPosition(prev, exclusiveEndOffset, timestamp, ids, newPositions);
            partialSortPositions(listIdx, exclusiveEndOffset, i, newPositions);
            return;
        }
        if (prev != null) {
            int prevEnd = prev.getOffset() + prev.getLength();
            if (prevEnd < next.getOffset()) {
                if (newPositions == null)
                    newPositions = Lists.newArrayListWithExpectedSize(4);
                newPositions.add(newPosition(prevEnd, next.getOffset() - prevEnd, timestamp, ids));
            }
        }
        if (next.getOffset() + next.getLength() <= exclusiveEndOffset) {
            next.merge(ids);
        } else {
            int oldLength = next.getLength();
            next.setLength(exclusiveEndOffset - next.getOffset());
            if (newPositions == null)
                newPositions = Lists.newArrayListWithExpectedSize(4);
            newPositions.add(newPosition(next.getOffset() + next.getLength(), oldLength - next.getLength(),
                    next.getTimestamp(), next.getIds()));
            next.merge(ids);
        }
        i++;
        prev = next;
    }
    newPositions = addPendingPosition(prev, exclusiveEndOffset, timestamp, ids, newPositions);
    partialSortPositions(listIdx, exclusiveEndOffset, i, newPositions);
}

From source file:org.axdt.avm.access.AvmLibrary.java

protected void putIntoMap(Map<QualifiedName, List<IEObjectDescription>> nameToObjects,
        IEObjectDescription description) {
    QualifiedName indexKey = description.getName().toLowerCase();
    List<IEObjectDescription> values = nameToObjects.get(indexKey);
    if (values == null) {
        values = Lists.newArrayListWithExpectedSize(2);
        nameToObjects.put(indexKey, values);
    }/*from www. ja  va 2s.c  o  m*/
    values.add(description);
}