List of usage examples for com.google.common.collect Lists newArrayListWithCapacity
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize)
From source file:com.google.gerrit.server.change.ReviewerJson.java
public List<ReviewerInfo> format(Collection<ReviewerResource> rsrcs) throws OrmException { List<ReviewerInfo> infos = Lists.newArrayListWithCapacity(rsrcs.size()); AccountInfo.Loader loader = accountLoaderFactory.create(true); for (ReviewerResource rsrc : rsrcs) { ReviewerInfo info = format(rsrc, null); loader.put(info);/*from w w w . j av a 2s. c o m*/ infos.add(info); } loader.fill(); return infos; }
From source file:org.plista.kornakapi.core.recommender.ArrayTopItems.java
public static List<RecommendedItem> getTopItems(int howMany, long[] possibleItemIDs, int fromIndex, int toIndex, IDRescorer rescorer, TopItems.Estimator<Long> estimator) throws TasteException { Preconditions.checkArgument(possibleItemIDs != null, "possibleItemIDs is null"); Preconditions.checkArgument(estimator != null, "estimator is null"); Queue<RecommendedItem> topItems = new PriorityQueue<RecommendedItem>(howMany + 1, Collections.reverseOrder(ByValueRecommendedItemComparator.getInstance())); boolean full = false; double lowestTopValue = Double.NEGATIVE_INFINITY; for (int index = fromIndex; index < toIndex; index++) { long itemID = possibleItemIDs[index]; if (rescorer == null || !rescorer.isFiltered(itemID)) { double preference; try { preference = estimator.estimate(itemID); } catch (NoSuchItemException nsie) { continue; } catch (NoSuchUserException nsue) { continue; }/*from w ww . j av a 2s. c o m*/ double rescoredPref = rescorer == null ? preference : rescorer.rescore(itemID, preference); if (!Double.isNaN(rescoredPref) && (!full || rescoredPref > lowestTopValue)) { topItems.add(new GenericRecommendedItem(itemID, (float) rescoredPref)); if (full) { topItems.poll(); } else if (topItems.size() > howMany) { full = true; topItems.poll(); } lowestTopValue = topItems.peek().getValue(); } } } int size = topItems.size(); if (size == 0) { return Collections.emptyList(); } List<RecommendedItem> result = Lists.newArrayListWithCapacity(size); result.addAll(topItems); Collections.sort(result, ByValueRecommendedItemComparator.getInstance()); return result; }
From source file:monasca.api.infrastructure.persistence.hibernate.AlarmHibernateUtils.java
public List<String> findAlarmIds(String tenantId, Map<String, String> dimensions) { logger.trace(BaseSqlRepo.ORM_LOG_MARKER, "findAlarmIds(...) entering"); List<String> alarmIdList = null; StatelessSession session = null;//from w w w.ja va2s . c o m try { session = sessionFactory.openStatelessSession(); final String sql = this.findAlarmQueryString(dimensions); final Query query = session.createSQLQuery(sql).setString("tenantId", tenantId); this.bindDimensionsToQuery(query, dimensions); @SuppressWarnings("unchecked") List<Object[]> rows = query.list(); alarmIdList = Lists.newArrayListWithCapacity(rows.size()); for (Object[] row : rows) { String id = (String) row[0]; alarmIdList.add(id); } } finally { if (session != null) { session.close(); } } // no need to check if alarmIdList != null, because in case of exception method // will leave immediately, otherwise list wont be null. return alarmIdList; }
From source file:com.google.dart.compiler.ast.NodeList.java
@Override public E set(int index, E element) { if (elements == null) { elements = Lists.newArrayListWithCapacity(index + 1); }/*from w w w . java 2 s. co m*/ E result = elements.set(index, element); owner.becomeParentOf(element); return result; }
From source file:com.isotrol.impe3.core.component.CookieExtractors.java
/** * Performs an extraction./*from ww w . j ava 2s. com*/ * @param target Target object. * @return Actions to register. */ public final List<NewCookie> extract(Object target) { if (isEmpty()) { return ImmutableList.of(); } final List<NewCookie> actions = Lists.newArrayListWithCapacity(extractors.size()); for (CookieExtractor e : extractors) { final NewCookie cookie = e.extract(target); if (cookie != null) { actions.add(cookie); } } return actions; }
From source file:org.apache.mahout.ga.watchmaker.cd.CDCrossover.java
@Override protected List<CDRule> mate(CDRule parent1, CDRule parent2, int numberOfCrossoverPoints, Random rng) { Preconditions.checkArgument(parent1.getNbConditions() == parent2.getNbConditions(), "Cannot perform cross-over with parents of different size."); CDRule offspring1 = new CDRule(parent1); CDRule offspring2 = new CDRule(parent2); // Apply as many cross-overs as required. for (int i = 0; i < numberOfCrossoverPoints; i++) { // Cross-over index is always greater than zero and less than // the length of the parent so that we always pick a point that // will result in a meaningful cross-over. int crossoverIndex = 1 + rng.nextInt(parent1.getNbConditions() - 1); for (int j = 0; j < crossoverIndex; j++) { swap(offspring1, offspring2, j); }//from w w w.jav a 2 s .com } List<CDRule> result = Lists.newArrayListWithCapacity(2); result.add(offspring1); result.add(offspring2); return result; }
From source file:com.isotrol.impe3.core.component.ActionExtractors.java
/** * Performs an extraction.//from w ww. j a v a2 s .co m * @param target Target object. * @return Actions to register. */ public final List<Action> extract(Object target) { if (isEmpty()) { return ImmutableList.of(); } final List<Action> actions = Lists.newArrayListWithCapacity(extractors.size()); for (ActionExtractor e : extractors) { final Action action = e.extract(target); if (action != null) { actions.add(action); } } return actions; }
From source file:com.pinterest.terrapin.controller.FileSetStatusServlet.java
/** * Get all missing partitions/*from w w w . ja va2 s . c o m*/ * @param zkManager ZookeeperManager instance * @param fileSetInfo file set information * @return list of missing partitions */ public static List<Integer> getMissingPartitions(ZooKeeperManager zkManager, FileSetInfo fileSetInfo) { if (fileSetInfo.servingInfo == null) { return Lists.newArrayListWithCapacity(0); } ViewInfo viewInfo = zkManager.getViewInfo(fileSetInfo.servingInfo.helixResource); if (viewInfo == null) { return Lists.newArrayListWithCapacity(0); } List<Integer> missingPartitions = new ArrayList<Integer>(); for (int i = 0; i < fileSetInfo.servingInfo.numPartitions; i++) { String partitionName = TerrapinUtil.getViewPartitionName(fileSetInfo.servingInfo.helixResource, i); if (!viewInfo.isOnlinePartition(partitionName)) { missingPartitions.add(i); } } return missingPartitions; }
From source file:org.apache.mahout.cf.taste.hadoop.RecommendedItemsWritable.java
@Override public void readFields(DataInput in) throws IOException { int size = in.readInt(); recommended = Lists.newArrayListWithCapacity(size); for (int i = 0; i < size; i++) { long itemID = Varint.readSignedVarLong(in); float value = in.readFloat(); RecommendedItem recommendedItem = new GenericRecommendedItem(itemID, value); recommended.add(recommendedItem); }/*from w w w .j a v a 2 s . c o m*/ }
From source file:cpw.mods.fml.common.network.ModMissingPacket.java
@Override public FMLPacket consumePacket(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); int missingLen = dat.readInt(); missing = Lists.newArrayListWithCapacity(missingLen); for (int i = 0; i < missingLen; i++) { ModData md = new ModData(); md.modId = dat.readUTF();/*from w w w .jav a 2 s . c o m*/ md.modVersion = dat.readUTF(); missing.add(md); } int badVerLength = dat.readInt(); badVersion = Lists.newArrayListWithCapacity(badVerLength); for (int i = 0; i < badVerLength; i++) { ModData md = new ModData(); md.modId = dat.readUTF(); md.modVersion = dat.readUTF(); badVersion.add(md); } return this; }