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.codelibs.elasticsearch.taste.common.iterator.FixedSizeSamplingIterator.java

public FixedSizeSamplingIterator(final int size, final Iterator<T> source) {
    final List<T> buf = Lists.newArrayListWithCapacity(size);
    int sofar = 0;
    final Random random = RandomUtils.getRandom();
    while (source.hasNext()) {
        final T v = source.next();
        sofar++;//w ww  .j ava2s .  com
        if (buf.size() < size) {
            buf.add(v);
        } else {
            final int position = random.nextInt(sofar);
            if (position < buf.size()) {
                buf.set(position, v);
            }
        }
    }
    delegate = buf.iterator();
}

From source file:com.google.gdt.eclipse.core.update.internal.core.FacetFinder.java

/**
 * Obtains a list of facet IDs for all non-Java facets enabled for a specified Eclipse project.
 * //w  w  w.java 2 s .c  o m
 * @param project the specified Eclipse project
 * @return the list of facet IDs
 */
public static List<String> getEnabledNonJavaFacetIds(IProject project) {
    IFacetedProject facetedProject;
    try {
        facetedProject = ProjectFacetsManager.create(project);
    } catch (CoreException e) {
        CorePluginLog.logError(e);
        return NO_STRINGS;
    }
    if (facetedProject == null) {
        return NO_STRINGS;
    }
    Collection<IProjectFacetVersion> projectFacetVersions = facetedProject.getProjectFacets();
    List<String> facetsEnabled = Lists.newArrayListWithCapacity(projectFacetVersions.size());
    for (IProjectFacetVersion facet : facetedProject.getProjectFacets()) {
        // Skip Java facet, since that is always on by default.
        String facetId = facet.getProjectFacet().getId();
        if (!facetId.equals(FACET_JST_JAVA) && !facetId.equals(FACET_JAVA)) {
            facetsEnabled.add(facetId);
        }
    }
    return facetsEnabled;
}

From source file:com.google.gerrit.server.project.CommentLinkProvider.java

@Override
public List<CommentLinkInfo> get() {
    Set<String> subsections = cfg.getSubsections(ProjectConfig.COMMENTLINK);
    List<CommentLinkInfo> cls = Lists.newArrayListWithCapacity(subsections.size());
    for (String name : subsections) {
        CommentLinkInfo cl = ProjectConfig.buildCommentLink(cfg, name, true);
        if (cl.isOverrideOnly()) {
            throw new ProvisionException("commentlink " + name + " empty except for \"enabled\"");
        }/*w w w . j a  v a  2 s.c o  m*/
        cls.add(cl);
    }
    return ImmutableList.copyOf(cls);
}

From source file:org.apache.mahout.cf.taste.hadoop.TopItemsQueue.java

public List<RecommendedItem> getTopItems() {
    List<RecommendedItem> recommendedItems = Lists.newArrayListWithCapacity(maxSize);
    while (size() > 0) {
        MutableRecommendedItem topItem = pop();
        // filter out "sentinel" objects necessary for maintaining an efficient priority queue
        if (topItem.getItemID() != SENTINEL_ID) {
            recommendedItems.add(topItem);
        }//from  ww  w .  j ava2s  .  co m
    }
    Collections.reverse(recommendedItems);
    return recommendedItems;
}

From source file:com.cloudera.oryx.als.common.rescorer.AbstractRescorerProvider.java

/**
 * @param classNamesString a comma-delimited list of class names, where classes implement {@link RescorerProvider}
 * @return a {@link MultiRescorerProvider} which rescores using all of them
 *//*  w  ww.  ja  va  2s  . co m*/
public static RescorerProvider loadRescorerProviders(String classNamesString) {
    if (classNamesString == null || classNamesString.isEmpty()) {
        return null;
    }
    String[] classNames = classNamesString.split(",");
    if (classNames.length == 1) {
        return ClassUtils.loadInstanceOf(classNames[0], RescorerProvider.class);
    }
    List<RescorerProvider> providers = Lists.newArrayListWithCapacity(classNames.length);
    for (String className : classNames) {
        providers.add(ClassUtils.loadInstanceOf(className, RescorerProvider.class));
    }
    return new MultiRescorerProvider(providers);
}

From source file:org.apache.mahout.cf.taste.hadoop.similarity.item.TopSimilarItemsQueue.java

public List<SimilarItem> getTopItems() {
    List<SimilarItem> items = Lists.newArrayListWithCapacity(maxSize);
    while (size() > 0) {
        SimilarItem topItem = pop();/*from   w  w  w .j  a  va2 s.  c om*/
        // filter out "sentinel" objects necessary for maintaining an efficient priority queue
        if (topItem.getItemID() != SENTINEL_ID) {
            items.add(topItem);
        }
    }
    Collections.reverse(items);
    return items;
}

From source file:org.eclipse.xtext.xbase.typesystem.util.Multimaps2.java

/**
 * Constructs an empty {@code ListMultimap} with enough capacity to hold the specified numbers of keys and values
 * without resizing. It uses a linked map internally.
 * //from  w w  w  .jav a2s  .c  o  m
 * @param expectedKeys
 *            the expected number of distinct keys
 * @param expectedValuesPerKey
 *            the expected average number of values per key
 * @throws IllegalArgumentException
 *             if {@code expectedKeys} or {@code expectedValuesPerKey} is negative
 */
public static <K, V> ListMultimap<K, V> newLinkedHashListMultimap(int expectedKeys,
        final int expectedValuesPerKey) {
    return Multimaps.newListMultimap(new LinkedHashMap<K, Collection<V>>(expectedKeys),
            new Supplier<List<V>>() {
                @Override
                public List<V> get() {
                    return Lists.newArrayListWithCapacity(expectedValuesPerKey);
                }
            });
}

From source file:com.nike.cerberus.service.RoleService.java

/**
 * Retrieves all roles from the data store and returns them.
 *
 * @return List of role domain objects./*from w  w  w.  j ava  2 s  .c om*/
 */
public List<Role> getAllRoles() {
    final List<RoleRecord> roleRecords = roleDao.getAllRoles();
    final List<Role> roles = Lists.newArrayListWithCapacity(roleRecords.size());

    roleRecords.forEach(r -> roles.add(new Role().setId(r.getId()).setName(r.getName())
            .setCreatedBy(r.getCreatedBy()).setLastUpdatedBy(r.getLastUpdatedBy())
            .setCreatedTs(r.getCreatedTs()).setLastUpdatedTs(r.getLastUpdatedTs())));

    return roles;
}

From source file:org.apache.hadoop.hbase.util.ByteRangeUtils.java

public static ArrayList<ByteRange> fromArrays(Collection<byte[]> arrays) {
    if (arrays == null) {
        return new ArrayList<ByteRange>(0);
    }//from w  w w .j a v  a 2s.  c  om
    ArrayList<ByteRange> ranges = Lists.newArrayListWithCapacity(arrays.size());
    for (byte[] array : arrays) {
        ranges.add(new SimpleByteRange(array));
    }
    return ranges;
}

From source file:org.kiji.schema.util.SplitKeyFile.java

/**
 * Constructs a split key file from an input stream.  This object will take ownership of
 * the inputStream, which you should clean up by calling close().
 *
 * @param inputStream The file contents.
 * @return the region boundaries, as a list of row keys.
 * @throws IOException on I/O error.//from ww w.  j  a  v a2 s. co m
 */
public static List<byte[]> decodeRegionSplitList(InputStream inputStream) throws IOException {
    try {
        final String content = Bytes.toString(IOUtils.toByteArray(Preconditions.checkNotNull(inputStream)));
        final String[] encodedKeys = content.split("\n");
        final List<byte[]> keys = Lists.newArrayListWithCapacity(encodedKeys.length);
        for (String encodedKey : encodedKeys) {
            keys.add(decodeRowKey(encodedKey));
        }
        return keys;
    } finally {
        ResourceUtils.closeOrLog(inputStream);
    }
}