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.apache.kylin.engine.mr.steps.lookup.LookupExecutableUtil.java

public static List<String> getSegments(Map<String, String> params) {
    final String ids = params.get(SEGMENT_IDS);
    if (ids != null) {
        final String[] splitted = StringUtils.split(ids, ",");
        ArrayList<String> result = Lists.newArrayListWithExpectedSize(splitted.length);
        for (String id : splitted) {
            result.add(id);/*  w  w w. jav  a2  s.  com*/
        }
        return result;
    } else {
        return Collections.emptyList();
    }
}

From source file:com.google.jstestdriver.FailureParser.java

public List<Failure> parse(String failure) {
    String message = "";
    List<Failure> failures;
    String stackStripPrefix = pathPrefix.prefixPath("/static/");
    Pattern stackStripPattern = Pattern.compile("http://[^/]*/*" + stackStripPrefix, Pattern.CASE_INSENSITIVE);
    try {/*from www  .  java2  s  . c  o m*/
        Collection<JsException> exceptions = gson.fromJson(failure, new TypeToken<Collection<JsException>>() {
        }.getType());
        failures = Lists.newArrayListWithExpectedSize(exceptions.size());
        for (JsException exception : exceptions) {
            if (exception.getName() != null && !exception.getName().isEmpty()) {
                message = String.format("%s: %s", exception.getName(), exception.getMessage());
            } else {
                message = exception.getMessage();
            }
            String errorStack = exception.getStack();
            String[] lines = errorStack.split("\n");

            final List<String> stack = Lists.newLinkedList();
            for (String l : lines) {
                if (!stackStripPattern.matcher(l).find()) {
                    stack.add(l);
                }
            }
            failures.add(new Failure(message, stack));
        }
    } catch (Exception e) {
        logger.error("Error converting JsExceptions[{}]", failure, e);
        failures = Lists.newArrayList(new Failure(failure, Lists.<String>newArrayList()));
    }
    return failures;
}

From source file:com.android.tools.idea.tests.gui.framework.fixture.TranslationsEditorFixture.java

@NotNull
private static List<String> getColumnHeaderValues(@NotNull final JTable table) {
    return GuiQuery.getNonNull(() -> {
        int columnCount = table.getColumnModel().getColumnCount();
        List<String> columns = Lists.newArrayListWithExpectedSize(columnCount);
        for (int i = 0; i < columnCount; i++) {
            columns.add(table.getColumnName(i));
        }//w ww.  j a va 2s . com
        return columns;
    });
}

From source file:com.github.camellabs.iot.cloudlet.document.driver.mongodb.BsonMapperProcessor.java

@Override
public void process(Exchange exchange) throws Exception {
    Object rawBody = exchange.getIn().getBody();
    if (!(rawBody instanceof Iterable)) {
        DBObject inDocument = exchange.getIn().getBody(DBObject.class);
        if (inDocument != null) {
            DBObject json = map(inDocument);
            exchange.getIn().setBody(json);
        }/*from   ww  w  .j ava  2s.  co  m*/
    } else {
        List<DBObject> bsons = exchange.getIn().getBody(List.class);
        if (bsons != null) {
            List<DBObject> resultBsons = Lists.newArrayListWithExpectedSize(bsons.size());
            for (DBObject bs : bsons) {
                resultBsons.add(map(bs));
            }
            exchange.getIn().setBody(resultBsons);
        }
    }
}

From source file:org.zanata.rest.editor.service.LocalesService.java

@Override
public Response get() {
    List<HLocale> locales = localeServiceImpl.getAllLocales();

    List<Locale> localesRefs = Lists.newArrayListWithExpectedSize(locales.size());

    localesRefs.addAll(/* w ww.ja v  a 2 s . co  m*/
            locales.stream().map(hLocale -> new Locale(hLocale.getLocaleId(), hLocale.retrieveDisplayName()))
                    .collect(Collectors.toList()));

    Type genericType = new GenericType<List<Locale>>() {
    }.getGenericType();
    Object entity = new GenericEntity<List<Locale>>(localesRefs, genericType);
    return Response.ok(entity).build();
}

From source file:com.torodb.mongodb.language.update.UpdatedToroDocumentArrayBuilder.java

public UpdatedToroDocumentArrayBuilder(int expectedSize) {
    built = false;
    values = Lists.newArrayListWithExpectedSize(expectedSize);
}

From source file:org.auraframework.impl.root.component.ComponentDefRefArray.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Component> newInstance(BaseComponent<?, ?> fallbackValueProvider,
        Map<String, Object> extraProviders) throws QuickFixException {
    List<Component> components = Lists.newArrayListWithExpectedSize(cdrs.size());
    BaseComponent<?, ?> valueProvider = this.vp != null ? this.vp : fallbackValueProvider;
    if (extraProviders != null) {
        // TODO: rename this thing
        valueProvider = new IterationValueProvider(valueProvider, extraProviders);
    }/*  w w w.j a va 2 s.c  om*/
    AuraContext context = Aura.getContextService().getCurrentContext();
    int idx = 0;
    for (ComponentDefRef cdr : this.cdrs) {
        // only foreach returns a list, once that is gone get rid of get(0)
        context.getInstanceStack().setAttributeIndex(idx);
        components.add(cdr.newInstance(valueProvider).get(0));
        context.getInstanceStack().clearAttributeIndex(idx);
        idx += 1;
    }
    return components;
}

From source file:com.android.ide.common.blame.parser.aapt.ReadOnlyDocument.java

/**
 * Creates a new {@link ReadOnlyDocument} for the given file.
 *
 * @param file the file whose text will be stored in the document. UTF-8 charset is used to
 *             decode the contents of the file.
 * @throws java.io.IOException if an error occurs while reading the file.
 */// w  w  w.  j av  a2s.  c  o  m
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
ReadOnlyDocument(@NonNull File file) throws IOException {
    String xml = Files.toString(file, Charsets.UTF_8);
    if (xml.startsWith("\uFEFF")) { // Strip byte order mark if necessary
        xml = xml.substring(1);
    }
    mFileContents = xml;
    myFile = file;
    myLastModified = file.lastModified();
    myOffsets = Lists.newArrayListWithExpectedSize(mFileContents.length() / 30);
    for (int i = 0; i < mFileContents.length(); i++) {
        char c = mFileContents.charAt(i);
        if (c == '\n') {
            myOffsets.add(i + 1);
        }
    }
}

From source file:eu.project.ttc.engines.morpho.CompoundUtils.java

/**
 * Returns all possible components for a compound word 
 * by combining its atomic components./*w w w .  jav a  2s . co m*/
 * 
 * E.g. ab|cd|ef returns
 *       abcdef,
 *       ab, cdef,
 *       abcd, ef,
 *       cd
 * 
 * 
 * @param word the compound word
 * @return
 *          the list of all possible component lemmas
 */
public static List<Component> allSizeComponents(Word word) {
    Set<Component> components = Sets.newHashSet();
    for (int nbComponents = word.getComponents().size(); nbComponents > 0; nbComponents--) {

        for (int startIndex = 0; startIndex <= word.getComponents().size() - nbComponents; startIndex++) {
            List<Component> toMerge = Lists.newArrayListWithExpectedSize(nbComponents);

            for (int i = 0; i < nbComponents; i++)
                toMerge.add(word.getComponents().get(startIndex + i));

            components.add(merge(word, toMerge));
        }
    }
    return Lists.newArrayList(components);
}

From source file:voldemort.store.routed.action.AbstractReadRepair.java

public AbstractReadRepair(PD pipelineData, Event completeEvent, int preferred, long timeoutMs,
        Map<Integer, NonblockingStore> nonblockingStores, ReadRepairer<ByteArray, byte[]> readRepairer) {
    super(pipelineData, completeEvent);
    this.preferred = preferred;
    this.timeoutMs = timeoutMs;
    this.nonblockingStores = nonblockingStores;
    this.readRepairer = readRepairer;
    this.nodeValues = Lists.newArrayListWithExpectedSize(pipelineData.getResponses().size());
}