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:com.android.tools.lint.client.api.CompositeIssueRegistry.java

@NonNull
@Override//from w w  w  .  j  av a2  s  .c om
public List<Issue> getIssues() {
    if (myIssues == null) {
        List<Issue> issues = Lists.newArrayListWithExpectedSize(200);
        for (IssueRegistry registry : myRegistries) {
            issues.addAll(registry.getIssues());
        }
        myIssues = issues;
    }

    return myIssues;
}

From source file:org.apache.crunch.io.CrunchInputs.java

public static void addInputPaths(Job job, Collection<Path> paths, FormatBundle inputBundle, int nodeIndex) {
    Configuration conf = job.getConfiguration();
    List<String> encodedPathStrs = Lists.newArrayListWithExpectedSize(paths.size());
    for (Path path : paths) {
        String pathStr = encodePath(path);
        Preconditions.checkArgument(pathStr.indexOf(RECORD_SEP) == -1 && pathStr.indexOf(FIELD_SEP) == -1
                && pathStr.indexOf(PATH_SEP) == -1);
        encodedPathStrs.add(pathStr);/*from ww  w  . j ava  2  s.  co  m*/
    }
    String inputs = JOINER.join(inputBundle.serialize(), String.valueOf(nodeIndex),
            Joiner.on(PATH_SEP).join(encodedPathStrs));
    String existing = conf.get(CRUNCH_INPUTS);
    conf.set(CRUNCH_INPUTS, existing == null ? inputs : existing + RECORD_SEP + inputs);
}

From source file:org.jetbrains.android.dom.drawable.AndroidDrawableDomUtil.java

public static List<String> getPossibleRoots(AndroidFacet facet) {
    AndroidVersion sdkVersion = AndroidModuleInfo.get(facet).getBuildSdkVersion();
    List<String> result = Lists
            .newArrayListWithExpectedSize(DRAWABLE_ROOTS_V1.length + DRAWABLE_ROOTS_V21.length);
    Collections.addAll(result, DRAWABLE_ROOTS_V1);
    if (sdkVersion == null || sdkVersion.getFeatureLevel() >= 21
            || ApplicationManager.getApplication().isUnitTestMode()) {
        Collections.addAll(result, DRAWABLE_ROOTS_V21);
    }//  w  w w .  j  a v  a2 s. c  o m

    return result;
}

From source file:defrac.intellij.projectView.DefracProjectViewUtil.java

@NotNull
public static List<Module> getModules(@NotNull final Collection<WeakReference2<Module>> modules,
        @Nullable final Condition<Module> filter) {
    final Iterator<WeakReference2<Module>> iterator = modules.iterator();
    final List<Module> result = Lists.newArrayListWithExpectedSize(modules.size());

    while (iterator.hasNext()) {
        final WeakReference2<Module> moduleRef = iterator.next();
        final Module module = moduleRef.get();

        if (module == null || module.isDisposed()) {
            iterator.remove();//from   w  w  w .ja v  a  2  s.c om
            continue;
        }

        if (filter == null || filter.value(module)) {
            result.add(module);
        }
    }

    return result;
}

From source file:com.android.tools.idea.uibuilder.property.NlPropertiesGrouper.java

public List<PTableItem> group(@NotNull List<NlPropertyItem> properties, @NotNull List<NlComponent> components) {
    String className = getCommonTagName(components);

    List<PTableItem> result = Lists.newArrayListWithExpectedSize(properties.size());

    // group theme attributes together
    NlPropertyAccumulator themePropertiesAccumulator = new NlPropertyAccumulator("Theme", p -> p != null
            && (p.getParentStylables().contains("Theme") || p.getName().equalsIgnoreCase("theme")));

    // Disable this for now...
    ////from   w w  w .j a va 2s  .co  m
    // group attributes that correspond to this component together
    //NlPropertyAccumulator customViewPropertiesAccumulator = null;
    //if (className != null) {
    //  customViewPropertiesAccumulator = new NlPropertyAccumulator(className, p -> p != null && p.getParentStylables().contains(className));
    //}

    // group margin, padding and layout attributes together
    NlPropertyAccumulator paddingPropertiesAccumulator = new NlMarginPropertyAccumulator("Padding",
            ATTR_PADDING, ATTR_PADDING_LEFT, ATTR_PADDING_RIGHT, ATTR_PADDING_START, ATTR_PADDING_END,
            ATTR_PADDING_TOP, ATTR_PADDING_BOTTOM);
    NlPropertyAccumulator layoutViewPropertiesAccumulator = new NlMarginPropertyAccumulator("Layout_Margin",
            ATTR_LAYOUT_MARGIN, ATTR_LAYOUT_MARGIN_LEFT, ATTR_LAYOUT_MARGIN_RIGHT, ATTR_LAYOUT_MARGIN_START,
            ATTR_LAYOUT_MARGIN_END, ATTR_LAYOUT_MARGIN_TOP, ATTR_LAYOUT_MARGIN_BOTTOM);

    PropertyNamePrefixAccumulator constraintPropertiesAccumulator = new PropertyNamePrefixAccumulator(
            "Constraints", "layout_constraint");

    List<NlPropertyAccumulator> accumulators = Lists.newArrayList(themePropertiesAccumulator,
            paddingPropertiesAccumulator, layoutViewPropertiesAccumulator, constraintPropertiesAccumulator);

    for (NlPropertyItem p : properties) {
        boolean added = false;
        for (NlPropertyAccumulator accumulator : accumulators) {
            added = accumulator.process(p);
            if (added) {
                break;
            }
        }

        if (!added) {
            result.add(p);
        }
    }

    int insertionPoint = findInsertionPoint(result);

    for (NlPropertyAccumulator accumulator : accumulators) {
        if (accumulator.hasItems()) {
            result.add(insertionPoint, accumulator.getGroupNode());
        }
    }

    return result;
}

From source file:org.jiemamy.dialect.postgresql.PostgreSqlTokenResolver.java

@Override
protected List<Token> resolveType(DataType type) {
    Validate.notNull(type);/*from w  w  w . j av  a 2 s  .  c  o m*/
    Boolean serial = type.getParam(TypeParameterKey.SERIAL);
    if (serial != null && serial == true) {
        List<Token> result = Lists.newArrayListWithExpectedSize(5);
        if (type.getRawTypeDescriptor().getTypeName().equals("INTEGER")) {
            result.add(Keyword.of("SERIAL"));
            return result;
        } else if (type.getRawTypeDescriptor().getTypeName().equals("BIGINT")) {
            result.add(Keyword.of("BIGSERIAL"));
            return result;
        }
    }
    return super.resolveType(type);
}

From source file:com.mgmtp.jfunk.data.generator.control.LinearControl.java

/**
 * Generates a FieldCase [min, min + 1, ... , max - 1, max] for every value within the allowed
 * range./*  w w w  .j  av a 2 s . c o  m*/
 * 
 * @return a list that contains a FieldCase for every allowed value
 */
@Override
protected List<FieldCase> createCases() {
    List<FieldCase> list = Lists.newArrayListWithExpectedSize(range.getRange() * 2 + 2);
    for (int i = range.getMin(); i <= range.getMax(); i++) {
        list.add(new FieldCase(i));
    }
    return list;
}

From source file:net.sourceforge.cilib.util.selection.weighting.LinearWeighting.java

@Override
public <T> Iterable<WeightedObject> weigh(Iterable<T> iterable) {
    List<T> elements = Lists.newArrayList(iterable);
    List<WeightedObject> results = Lists.newArrayListWithExpectedSize(elements.size());

    double stepSize = (this.max - this.min) / (elements.size() - 1);
    int objectIndex = 0;
    for (T element : elements) {
        results.add(new WeightedObject(element, objectIndex++ * stepSize + this.min));
    }/* w w  w.j a  va 2  s  .c om*/
    return results;
}

From source file:org.gradoop.flink.representation.transactional.traversalcode.TraversalCode.java

/**
 * Constructor.//from w w  w.  j ava  2  s . c  o  m
 *
 * @param traversal initial traversals
 */
public TraversalCode(Traversal<C> traversal) {
    this.traversals = Lists.newArrayListWithExpectedSize(1);
    this.traversals.add(traversal);
}

From source file:com.ardor3d.extension.terrain.providers.image.ImageTextureSource.java

public ImageTextureSource(final int tileSize, final Image map, final List<Integer> heightMapSizes) {
    this.tileSize = tileSize;
    maps = Lists.newArrayListWithExpectedSize(heightMapSizes.size());
    this.heightMapSizes = Lists.newArrayList(heightMapSizes);
    buildMips(map);/*from   w  ww  . jav  a2 s. c o m*/
}