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.twitter.distributedlog.feature.DynamicConfigurationFeatureProvider.java

@Override
public void start() throws IOException {
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayListWithExpectedSize(2);
    String baseConfigPath = conf.getFileFeatureProviderBaseConfigPath();
    Preconditions.checkNotNull(baseConfigPath);
    File baseConfigFile = new File(baseConfigPath);
    FileConfigurationBuilder baseProperties = new PropertiesConfigurationBuilder(
            baseConfigFile.toURI().toURL());
    fileConfigBuilders.add(baseProperties);
    String overlayConfigPath = conf.getFileFeatureProviderOverlayConfigPath();
    if (null != overlayConfigPath) {
        File overlayConfigFile = new File(overlayConfigPath);
        FileConfigurationBuilder overlayProperties = new PropertiesConfigurationBuilder(
                overlayConfigFile.toURI().toURL());
        fileConfigBuilders.add(overlayProperties);
    }/*from ww  w. jav  a2 s .  c  o m*/
    try {
        this.featuresConfSubscription = new ConfigurationSubscription(this.featuresConf, fileConfigBuilders,
                executorService, conf.getDynamicConfigReloadIntervalSec(), TimeUnit.SECONDS);
    } catch (ConfigurationException e) {
        throw new IOException("Failed to register subscription on features configuration");
    }
    this.featuresConfSubscription.registerListener(this);
}

From source file:com.android.tools.idea.navigator.nodes.AndroidResGroupNode.java

@NotNull
@Override// w w w . j  a  v a2s  . c  o  m
public Collection<? extends AbstractTreeNode> getChildren() {
    List<PsiFileNode> children = Lists.newArrayListWithExpectedSize(myFiles.size());
    for (PsiFile file : myFiles) {
        children.add(new AndroidResFileNode(myProject, file, getSettings(), myFacet));
    }
    return children;
}

From source file:org.bin01.db.verifier.ExternalClassLoader.java

public synchronized static URLClassLoader getClassLoaderForCoordinates(TeslaAether aether, String coordinate)
        throws DependencyResolutionException, MalformedURLException {
    URLClassLoader loader = loadersMap.get(coordinate);
    if (loader == null) {
        final CollectRequest collectRequest = new CollectRequest();
        collectRequest.setRoot(new Dependency(new DefaultArtifact(coordinate), JavaScopes.RUNTIME));
        DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils
                .andFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), new DependencyFilter() {
                    @Override//from w w w  . j  a va  2 s.  c o m
                    public boolean accept(DependencyNode node, List<DependencyNode> parents) {
                        if (accept(node.getArtifact())) {
                            return false;
                        }

                        for (DependencyNode parent : parents) {
                            if (accept(parent.getArtifact())) {
                                return false;
                            }
                        }

                        return true;
                    }

                    private boolean accept(final Artifact artifact) {
                        return exclusions.contains(artifact.getGroupId());
                    }
                }));

        try {
            final List<Artifact> artifacts = aether.resolveArtifacts(dependencyRequest);

            List<URL> urls = Lists.newArrayListWithExpectedSize(artifacts.size());
            for (Artifact artifact : artifacts) {
                if (!exclusions.contains(artifact.getGroupId())) {
                    urls.add(artifact.getFile().toURI().toURL());
                } else {
                    log.debug("Skipped Artifact[{}]", artifact);
                }
            }

            for (URL url : urls) {
                log.info("Added URL[{}]", url);
            }

            loader = new URLClassLoader(urls.toArray(new URL[urls.size()]),
                    ExternalClassLoader.class.getClassLoader());
            loadersMap.put(coordinate, loader);
        } catch (Exception e) {
            log.error("Unable to resolve artifacts for [{}].", dependencyRequest, e);
            throw Throwables.propagate(e);
        }
    }
    return loader;
}

From source file:org.apache.shindig.gadgets.parse.caja.CajaCssParser.java

public List<ParsedCssDeclaration> parseInline(String style) throws GadgetException {
    if (style.matches("\\s*")) {
        return Lists.newArrayList();
    }/*from   w w  w .  j ava2s.  co  m*/

    CssParser parser = getParser(style);
    CssTree.DeclarationGroup declGroup = null;

    try {
        declGroup = parser.parseDeclarationGroup();
    } catch (ParseException e) {
        throw new GadgetException(GadgetException.Code.CSS_PARSE_ERROR, e);
    }

    List<ParsedCssDeclaration> attributes = Lists.newArrayListWithExpectedSize(declGroup.children().size());
    for (CssTree node : declGroup.children()) {
        if (node instanceof CssTree.Declaration) {
            CssTree.Declaration decl = (CssTree.Declaration) node;
            if (decl.getProperty() != null) {
                attributes.add(new CajaParsedCssDeclaration(decl));
            }
        }
    }

    return attributes;
}

From source file:com.android.build.gradle.internal.transforms.BaseProguardAction.java

public void keepattributes() {
    configuration.keepAttributes = Lists.newArrayListWithExpectedSize(0);
}

From source file:org.moe.designer.rendering.ModuleResourceRepository.java

/**
 * Creates a new resource repository for the given module, <b>not</b> including its dependent modules.
 *
 * @param facet the facet for the module
 * @return the resource repository/*from   ww w.jav  a 2s .  c  o  m*/
 */
@NotNull
public static LocalResourceRepository create(@NotNull final AndroidFacet facet) {
    boolean gradleProject = true;// facet.isGradleProject();
    if (!gradleProject) {
        // Always just a single resource folder: simple
        VirtualFile primaryResourceDir = null;//facet.getPrimaryResourceDir();
        if (primaryResourceDir == null) {
            return new EmptyRepository();
        }
        return ResourceFolderRegistry.get(facet, primaryResourceDir);
    }

    ResourceFolderManager folderManager = facet.getResourceFolderManager();
    List<VirtualFile> resourceDirectories = folderManager.getFolders();

    List<LocalResourceRepository> resources = Lists.newArrayListWithExpectedSize(resourceDirectories.size());
    for (VirtualFile resourceDirectory : resourceDirectories) {
        ResourceFolderRepository repository = ResourceFolderRegistry.get(facet, resourceDirectory);
        resources.add(repository);
    }

    //    DynamicResourceValueRepository dynamicResources = DynamicResourceValueRepository.create(facet);
    //    resources.add(dynamicResources);

    // We create a ModuleResourceRepository even if resources.isEmpty(), because we may
    // dynamically add children to it later (in updateRoots)
    final ModuleResourceRepository repository = new ModuleResourceRepository(facet, resources);

    // If the model is not yet ready, we may get an incomplete set of resource
    // directories, so in that case update the repository when the model is available.

    folderManager.addListener(new ResourceFolderManager.ResourceFolderListener() {
        @Override
        public void resourceFoldersChanged(@NotNull AndroidFacet facet, @NotNull List<VirtualFile> folders,
                @NotNull Collection<VirtualFile> added, @NotNull Collection<VirtualFile> removed) {
            repository.updateRoots();
        }
    });

    return repository;
}

From source file:jflowmap.views.flowmap.VisualNodeCluster.java

public static List<VisualNodeCluster> createClusters(List<List<VisualNode>> nodeClusterLists,
        double clusterDistanceThreshold) {
    //    List<List<VisualNode>> clusters = Lists.newArrayList(Iterators.filter(
    //        ClusterSetBuilder.getClusters(rootCluster, clusterDistanceThreshold).iterator(),
    //        new Predicate<List<VisualNode>>() {
    //          public boolean apply(List<VisualNode> nodes) {
    //            return (nodes.size() > 1);
    //          }
    //        }/*  w  w w. ja v  a2s  . c om*/
    //    ));
    final int numClusters = nodeClusterLists.size();

    Color[] colors = ColorUtils.createCategoryColors(numClusters);
    List<VisualNodeCluster> nodeClusters = Lists.newArrayListWithExpectedSize(numClusters);
    int cnt = 0;
    for (Collection<VisualNode> nodes : nodeClusterLists) {
        nodeClusters.add(VisualNodeCluster.createFor(cnt + 1, colors[cnt], nodes.iterator()));
        cnt++;
    }
    return nodeClusters;
}

From source file:org.eclipse.xtext.xbase.typesystem.internal.ExpressionScope.java

public ExpressionScope(FeatureScopes featureScopes, EObject context, Anchor anchor, ITypeReferenceOwner owner) {
    this.owner = owner;
    this.data = Lists.newArrayListWithExpectedSize(2);
    this.featureScopes = featureScopes;
    this.context = context;
    this.anchor = anchor;
}

From source file:com.android.tools.idea.run.DeviceSelectionUtils.java

@NotNull
public static Collection<IDevice> getOnlineDevices(@Nullable Collection<IDevice> devices) {
    if (devices == null) {
        return Collections.emptyList();
    }//from   w w  w .j  a v  a  2  s. c  om

    final List<IDevice> online = Lists.newArrayListWithExpectedSize(devices.size());
    for (IDevice device : devices) {
        if (device.isOnline()) {
            online.add(device);
        }
    }
    return online;
}

From source file:org.gradoop.model.impl.algorithms.fsm.gspan.miners.bulkiteration.GSpanBulkIteration.java

@Override
public DataSet<WithCount<CompressedDFSCode>> mine(DataSet<GSpanGraph> graphs, DataSet<Integer> minFrequency,
        FSMConfig fsmConfig) {/*ww w.j av a  2s  .c om*/

    DataSet<IterationItem> transactions = graphs.map(new IterationItemWithTransaction());
    //      .map(new Print<IterationItem>(""));

    // create search space with collector

    Collection<WithCount<CompressedDFSCode>> emptySubgraphList = Lists.newArrayListWithExpectedSize(0);

    DataSet<IterationItem> searchSpace = transactions
            .union(getExecutionEnvironment().fromElements(emptySubgraphList)
                    .map(new IterationItemWithCollector()).returns(TypeInformation.of(IterationItem.class)));

    // ITERATION HEAD
    IterativeDataSet<IterationItem> workSet = searchSpace.iterate(fsmConfig.getMaxEdgeCount());

    // ITERATION BODY

    // determine grown frequent subgraphs
    transactions = workSet.filter(new IsTransaction());

    // report ,filter and validate frequent subgraphs
    DataSet<WithCount<CompressedDFSCode>> currentFrequentSubgraphs = transactions
            .flatMap(new ReportGrownSubgraphs()).map(new AddCount<SerializedDFSCode>())
            // count frequency per worker, prune and compress subgraph
            .groupBy(0).combineGroup(new SumCount<SerializedDFSCode>())
            .flatMap(new PostPruneAndCompress(fsmConfig))
            // count global frequency and filter frequent subgraphs
            .groupBy(0).sum(1).filter(new Frequent<CompressedDFSCode>())
            .withBroadcastSet(minFrequency, BroadcastNames.MIN_FREQUENCY);

    // get all frequent subgraphs
    DataSet<Collection<WithCount<CompressedDFSCode>>> collector = workSet.filter(new IsCollector())
            .map(new SubgraphCollection())
            .union(currentFrequentSubgraphs.reduceGroup(new SubgraphCollection(fsmConfig)))
            .reduce(new SubgraphCollection());

    // grow frequent subgraphs
    DataSet<IterationItem> nextWorkSet = transactions.map(new GrowFrequentSubgraphs(fsmConfig))
            .withBroadcastSet(currentFrequentSubgraphs, BroadcastNames.FREQUENT_SUBGRAPHS)
            .filter(new HasGrownSubgraphs()).union(collector.map(new IterationItemWithCollector()));

    // ITERATION FOOTER
    DataSet<IterationItem> resultSet = workSet
            // terminate, if no new frequent DFS patterns
            .closeWith(nextWorkSet, currentFrequentSubgraphs);

    return resultSet.filter(new IsCollector()).flatMap(new ExpandSubgraphs());
}