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.b1.pack.standard.builder.VolumeBuilder.java

public List<BuilderVolume> getVolumes() {
    if (volumeContent != null) {
        completeVolume(true);//from  w  w  w  .jav  a 2  s  .  c o  m
    }
    int volumeCount = volumeContents.size();
    List<BuilderVolume> result = Lists.newArrayListWithCapacity(volumeCount);
    for (int i = 0; i < volumeCount; i++) {
        result.add(new StandardBuilderVolume(i + 1, volumeContents.get(i)));
    }
    return result;
}

From source file:kr.debop4j.timeperiod.timerange.WeekRangeCollection.java

/**
 * Gets weeks./*  w  w  w.  jav  a  2s  .  c om*/
 *
 * @return the weeks
 */
public List<WeekRange> getWeeks() {
    DateTime startWeek = getStart();
    List<WeekRange> weeks = Lists.newArrayListWithCapacity(getWeekCount());

    for (int i = 0; i < getWeekCount(); i++) {
        weeks.add(new WeekRange(startWeek.plusWeeks(i), getTimeCalendar()));
    }
    return weeks;
}

From source file:norbert.mynemo.core.evaluation.PersonnalRecommenderEvaluator.java

/**
 * Copies the preferences of the given user, from the given data model to the given map.
 *
 * @param dataModel source of the preferences
 * @param preferences destination of the preferences
 * @param user user id/*from w w w.ja v  a 2  s .  com*/
 */
private static void copyUserPreferences(DataModel dataModel, FastByIDMap<PreferenceArray> preferences,
        long user) throws TasteException {
    List<Preference> oneUserTrainingPrefs = null;

    for (Preference preference : dataModel.getPreferencesFromUser(user)) {
        Preference newPref = new GenericPreference(user, preference.getItemID(), preference.getValue());
        if (oneUserTrainingPrefs == null) {
            oneUserTrainingPrefs = Lists.newArrayListWithCapacity(3);
        }
        oneUserTrainingPrefs.add(newPref);

    }

    preferences.put(user, new GenericUserPreferenceArray(oneUserTrainingPrefs));
}

From source file:com.ning.metrics.collector.processing.db.DatabaseFeedEventStorage.java

@Override
public List<String> insert(final Collection<FeedEvent> feedEvents) {
    return dbi.withHandle(new HandleCallback<List<String>>() {

        @Override//from   www  .  j ava2 s.c om
        public List<String> withHandle(Handle handle) throws Exception {
            final List<String> idList = Lists.newArrayListWithCapacity(feedEvents.size());
            PreparedBatch batch = handle.prepareBatch(
                    "insert into feed_events (id, channel, created_at, metadata, event, subscription_id) values (:id, :channel, :now, :metadata, :event, :subscription_id)");

            for (FeedEvent feedEvent : feedEvents) {
                String id = UUID.randomUUID().toString();
                idList.add(id);
                batch.bind("id", id).bind("channel", feedEvent.getChannel())
                        .bind("metadata", mapper.writeValueAsString(feedEvent.getMetadata()))
                        .bind("event", mapper.writeValueAsString(feedEvent.getEvent()))
                        .bind("now", DateTimeUtils.getInstantMillis(new DateTime(DateTimeZone.UTC)))
                        .bind("subscription_id", feedEvent.getSubscriptionId()).add();
            }

            batch.execute();

            return idList;
        }
    });
}

From source file:org.apache.impala.util.AvroSchemaParser.java

/**
 * Parses the Avro schema string literal, mapping the Avro types to Impala types.
 * Returns a list of ColumnDef objects with their name and type info set.
 * Throws an AnalysisException if the Avro type maps to a type that Impala
 * does not yet support.//from   ww  w .j  av  a  2  s.  co  m
 * Throws a SchemaParseException if the Avro schema was invalid.
 */
public static List<ColumnDef> parse(String schemaStr) throws SchemaParseException, AnalysisException {
    Schema.Parser avroSchemaParser = new Schema.Parser();
    Schema schema = avroSchemaParser.parse(schemaStr);
    if (!schema.getType().equals(Schema.Type.RECORD)) {
        throw new UnsupportedOperationException(
                "Schema for table must be of type " + "RECORD. Received type: " + schema.getType());
    }
    List<ColumnDef> colDefs = Lists.newArrayListWithCapacity(schema.getFields().size());
    for (Schema.Field field : schema.getFields()) {
        Map<ColumnDef.Option, Object> option = Maps.newHashMap();
        String comment = field.doc();
        if (comment != null)
            option.put(ColumnDef.Option.COMMENT, comment);
        ColumnDef colDef = new ColumnDef(field.name(), new TypeDef(getTypeInfo(field.schema(), field.name())),
                option);
        colDef.analyze(null);
        colDefs.add(colDef);
    }
    return colDefs;
}

From source file:org.terasology.persistence.typeHandling.gson.GsonPersistedDataArray.java

@Override
public List<String> getAsStringArray() {
    List<String> result = Lists.newArrayListWithCapacity(size());
    for (JsonElement element : array) {
        result.add(element.getAsString());
    }/*from w  ww . j a v a 2  s. co m*/
    return result;
}

From source file:com.github.ibole.infrastructure.persistence.pagination.model.PagingCriteria.java

/**
 * Instantiates a new Paging criteria and not sort\search.
 * /*  w ww.ja v a 2 s.com*/
 * @param pageNumber the page number
 * @param pageSize the page size
 */
private PagingCriteria(int pageNumber, int pageSize) {
    this.pageNumber = pageNumber;
    this.pageSize = pageSize;
    this.searchFields = Lists.newArrayListWithCapacity(0);
    this.sortFields = Lists.newArrayListWithCapacity(0);
}

From source file:com.google.gitiles.RepositoryIndexServlet.java

private List<Map<String, String>> getRefs(HttpServletRequest req, String prefix) throws IOException {
    RefDatabase refdb = ServletUtils.getRepository(req).getRefDatabase();
    String repoName = ViewFilter.getView(req).getRepositoryName();
    Collection<Ref> refs = RefComparator.sort(refdb.getRefs(prefix).values());
    List<Map<String, String>> result = Lists.newArrayListWithCapacity(refs.size());

    for (Ref ref : refs) {
        String name = ref.getName().substring(prefix.length());
        boolean needPrefix = !ref.getName().equals(refdb.getRef(name).getName());
        result.add(ImmutableMap.of("url", GitilesView.log().copyFrom(req)
                .setRevision(Revision.unpeeled(needPrefix ? ref.getName() : name, ref.getObjectId())).toUrl(),
                "name", name));
    }//  w w w.  java  2  s.c o  m

    return result;
}

From source file:org.summer.dsl.xbase.typesystem.override.AbstractResolvedOperation.java

public List<IResolvedOperation> getOverriddenAndImplementedMethods() {
    if (validOverrides != null)
        return validOverrides;
    List<JvmOperation> candidates = getOverriddenAndImplementedMethodCandidates();
    if (candidates.isEmpty())
        return Collections.emptyList();
    List<IResolvedOperation> result = Lists.newArrayListWithCapacity(candidates.size());
    for (JvmOperation candidate : candidates) {
        // we know that our candidates are computed from the hierarchy
        // thus there is no need to check the declarator for inheritance
        IOverrideCheckResult checkResult = getOverrideTester().isSubsignature(this, candidate, false);
        if (checkResult.isOverridingOrImplementing()) {
            result.add(createResolvedOperationInHierarchy(candidate, checkResult));
        }//from   www  . jav  a  2  s .c  o  m
    }
    return validOverrides = Collections.unmodifiableList(result);
}