本文整理匯總了Java中com.google.common.collect.Lists.partition方法的典型用法代碼示例。如果您正苦於以下問題:Java Lists.partition方法的具體用法?Java Lists.partition怎麽用?Java Lists.partition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Lists
的用法示例。
在下文中一共展示了Lists.partition方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: reindex
import com.google.common.collect.Lists; //導入方法依賴的package包/類
@Override
public int reindex(List<K> keys, int batchSize, ReindexOperation<E> reindexOperation) {
int count = 0;
List<List<K>> batches = Lists.partition(keys, batchSize);
for (List<K> batchKeys : batches) {
List<E> batch = get(batchKeys);
batch = reindexOperation == null ? batch : reindexOperation.apply(batch);
if (reindexOperation != null) {
// we only re-save the batch when a re-index op is supplied, otherwise the data can't have changed.
ofy().save().entities(batch).now();
}
if (shouldSearch()) {
index(batch).complete();
}
count += batch.size();
ofy().clear(); // Clear the Objectify cache to free memory for next batch
Logger.info("Reindexed %d entities of type %s, %d of %d", batch.size(), entityType.getSimpleName(), count, keys.size());
}
return count;
}
示例2: updateAndDeleteCache
import com.google.common.collect.Lists; //導入方法依賴的package包/類
private void updateAndDeleteCache() {
List<Long> ids = Lists.newArrayList(appNamespaceIdCache.keySet());
if (CollectionUtils.isEmpty(ids)) {
return;
}
List<List<Long>> partitionIds = Lists.partition(ids, 500);
for (List<Long> toRebuild : partitionIds) {
Iterable<AppNamespace> appNamespaces = appNamespaceRepository.findAll(toRebuild);
if (appNamespaces == null) {
continue;
}
//handle updated
Set<Long> foundIds = handleUpdatedAppNamespaces(appNamespaces);
//handle deleted
handleDeletedAppNamespaces(Sets.difference(Sets.newHashSet(toRebuild), foundIds));
}
}
示例3: generateHtmlChunks
import com.google.common.collect.Lists; //導入方法依賴的package包/類
private static List<String> generateHtmlChunks(List<ReportItem> reportItemList) {
List<String> htmlChunks = new ArrayList<>();
VelocityEngine velocityEngine = new VelocityEngine();
Properties p = new Properties();
p.setProperty("resource.loader", "class");
p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
velocityEngine.init(p);
Template template = velocityEngine.getTemplate("template/report_template.html");
int maxItemsInReport = CliHelper.getMaxItemsInReport();
List<List<ReportItem>> reportItemsChunks = Lists.partition(reportItemList, maxItemsInReport);
for (List<ReportItem> reportItemsChunk : reportItemsChunks ) {
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("jarPath", CliHelper.getPathToAnalyze());
velocityContext.put("ruleName", reportItemsChunk.get(0).getRuleName());
velocityContext.put("reportItems", reportItemsChunk);
StringWriter stringWriter = new StringWriter();
template.merge(velocityContext, stringWriter);
htmlChunks.add(stringWriter.toString());
}
return htmlChunks;
}
示例4: publiceerSelectieTaken
import com.google.common.collect.Lists; //導入方法依賴的package包/類
private void publiceerSelectieTaken(List<SelectieAutorisatieBericht> selectieAutorisatieBerichten, List<PersoonCache> caches) {
final List<SelectieVerwerkTaakBericht> selectieTaken = new ArrayList<>();
//verdeel personen in config chunk size
final List<List<PersoonCache>> persoonsLijstChunks = Lists.partition(caches, configuratieService.getBlobsPerSelectieTaak());
//verdeel autorisaties in config chunk size
final List<List<SelectieAutorisatieBericht>> autorisatieChunks =
Lists.partition(selectieAutorisatieBerichten, configuratieService.getAutorisatiesPerSelectieTaak());
//maak selectietaken
for (List<SelectieAutorisatieBericht> autorisatieChunk : autorisatieChunks) {
for (List<PersoonCache> bundelChunk : persoonsLijstChunks) {
SelectieVerwerkTaakBericht selectieTaak = maakSelectieTaak(bundelChunk, autorisatieChunk);
selectieTaken.add(selectieTaak);
selectieJobRunStatusService.getStatus().incrementEnGetVerwerkTaken();
}
}
selectieTaakPublicatieService.publiceerSelectieTaak(selectieTaken);
}
示例5: generateHtmlCssFunctionTable
import com.google.common.collect.Lists; //導入方法依賴的package包/類
private String generateHtmlCssFunctionTable(List<StandardFunction> standardFunctions) {
StringBuilder html = new StringBuilder("<table style=\"border: 0;\">\n");
List<List<StandardFunction>> subLists = Lists.partition(standardFunctions, 3);
for (List<StandardFunction> subList : subLists) {
html.append("<tr>");
for (StandardFunction standardCssFunction : subList) {
List<String> links = standardCssFunction.getLinks().stream().filter(f -> !f.contains("lesscss.org")).collect(Collectors.toList());
html.append("<td style=\"border: 0; \">");
if (!links.isEmpty()) {
html.append("<a target=\"_blank\" href=\"").append(links.get(0)).append("\">");
}
html.append("<code>").append(standardCssFunction.getName()).append("</code>");
if (!links.isEmpty()) {
html.append("</a>");
}
html.append("</code>");
for (int i = 1; i < links.size(); i++) {
html.append(" <a target=\"_blank\" href=\"").append(links.get(i)).append("\">#").append(i + 1).append("</a>");
}
html.append("</td>\n");
}
html.append("</tr>");
}
html.append("</table>\n");
return html.toString();
}
示例6: export
import com.google.common.collect.Lists; //導入方法依賴的package包/類
private static void export(final Configuration configuration,
final TableInfo table) throws IOException {
warnOnMultipleScans(configuration, table);
final List<Attribute> attributes = CommonObjects.getTableToAttribute().get(table);
final List<List<Attribute>> groups = Lists.partition(attributes, configuration.getOpenFileNr());
int startIndex = 0;
for (final List<Attribute> group : groups) {
final List<Writer> writers = writeToDisk(configuration, table, group, startIndex);
uniqueAndSort(configuration, writers);
startIndex += group.size();
}
}
示例7: getBalances
import com.google.common.collect.Lists; //導入方法依賴的package包/類
/**
* This may take a while, make sure you obey the limits of the api provider
*/
public BigInteger getBalances(List<String> contract) throws IOException {
BigInteger result = BigInteger.ZERO;
List<List<String>> part = Lists.partition(contract, 20);
for(List<String> p:part) {
result = result.add(get20Balances(p));
}
return result;
//TODO:caching!
}
示例8: createPartitionedFilledPairedStatsAccumulator
import com.google.common.collect.Lists; //導入方法依賴的package包/類
/**
* Creates a {@link PairedStatsAccumulator} filled with the given lists of {@code x} and {@code y}
* values, which must be of the same size, added in groups of {@code partitionSize} using
* {@link PairedStatsAccumulator#addAll(PairedStats)}.
*/
static PairedStatsAccumulator createPartitionedFilledPairedStatsAccumulator(
List<Double> xValues, List<Double> yValues, int partitionSize) {
checkArgument(xValues.size() == yValues.size());
checkArgument(partitionSize > 0);
PairedStatsAccumulator accumulator = new PairedStatsAccumulator();
List<List<Double>> xPartitions = Lists.partition(xValues, partitionSize);
List<List<Double>> yPartitions = Lists.partition(yValues, partitionSize);
for (int index = 0; index < xPartitions.size(); index++) {
accumulator.addAll(createPairedStatsOf(xPartitions.get(index), yPartitions.get(index)));
}
return accumulator;
}
示例9: createPartitionSublists
import com.google.common.collect.Lists; //導入方法依賴的package包/類
@Override
protected void createPartitionSublists() {
List<String> fileLocations = ((FormatSelection) scanRel.getDrillTable().getSelection()).getAsFiles();
List<PartitionLocation> locations = new LinkedList<>();
for (String file: fileLocations) {
locations.add(new DFSPartitionLocation(MAX_NESTED_SUBDIRS, getBaseTableLocation(), file));
}
locationSuperList = Lists.partition(locations, PartitionDescriptor.PARTITION_BATCH_SIZE);
sublistsCreated = true;
}
示例10: createPartitionSublists
import com.google.common.collect.Lists; //導入方法依賴的package包/類
@Override
protected void createPartitionSublists() {
Set<String> fileLocations = ((ParquetGroupScan) scanRel.getGroupScan()).getFileSet();
List<PartitionLocation> locations = new LinkedList<>();
for (String file: fileLocations) {
locations.add(new DFSPartitionLocation(MAX_NESTED_SUBDIRS, getBaseTableLocation(), file));
}
locationSuperList = Lists.partition(locations, PartitionDescriptor.PARTITION_BATCH_SIZE);
sublistsCreated = true;
}
示例11: createPartitionSublists
import com.google.common.collect.Lists; //導入方法依賴的package包/類
@Override
protected void createPartitionSublists() {
List<PartitionLocation> locations = new LinkedList<>();
HiveReadEntry origEntry = ((HiveScan) scanRel.getGroupScan()).hiveReadEntry;
for (Partition partition: origEntry.getPartitions()) {
locations.add(new HivePartitionLocation(partition.getValues(), partition.getSd().getLocation()));
}
locationSuperList = Lists.partition(locations, PartitionDescriptor.PARTITION_BATCH_SIZE);
sublistsCreated = true;
}
示例12: zetOpdrachtenOpQueue
import com.google.common.collect.Lists; //導入方法依賴的package包/類
private void zetOpdrachtenOpQueue(SelectieVerwerkTaakBericht selectieTaak, int verwerkerPoolSize,
BlockingQueue<MaakPersoonslijstBatchOpdracht> persoonsBeeldTaakQueue)
throws InterruptedException {
//zet de opdrachten op de queue
final List<List<SelectiePersoonBericht>> bundelChunks = Lists.partition(selectieTaak.getPersonen(), verwerkerPoolSize);
for (List<SelectiePersoonBericht> bundelChunk : bundelChunks) {
final MaakPersoonslijstBatchOpdracht maakPersoonslijstBatchOpdracht = new MaakPersoonslijstBatchOpdracht();
maakPersoonslijstBatchOpdracht.setCaches(bundelChunk);
persoonsBeeldTaakQueue.put(maakPersoonslijstBatchOpdracht);
}
}
示例13: insertVideoEvents
import com.google.common.collect.Lists; //導入方法依賴的package包/類
@Override
public void insertVideoEvents(List<VideoViewEvent> videoViewEvents) {
try (Cluster cassandraConnection = buildConnection()) {
try (Session session = cassandraConnection.connect()) {
List<List<VideoViewEvent>> partition = Lists.partition(videoViewEvents, batchSize);
int total = 0;
for (List<VideoViewEvent> list : partition) {
String q = "BEGIN BATCH \n";
for (VideoViewEvent videoViewEvent : list) {
String insertQuery = "insert into wootag.video_view (" + "user_id," + " video_id, "
+ " session_id, " + " event_start_timestamp, "
+ " view_duration_in_second) VALUES ";
insertQuery += "\n (" + "'" + videoViewEvent.getUserId() + "'" + "," + "'"
+ videoViewEvent.getVideoId() + "'" + "," + "'" + videoViewEvent.getSessionId() + "'"
+ "," + videoViewEvent.getEventStartTimestamp() + ","
+ videoViewEvent.getViewDurationInSeconds() + ");\n";
q += insertQuery;
}
session.execute(q + " APPLY BATCH; ");
total += batchSize;
System.out.println("Executing batch of " + batchSize + ", Total : " + total);
}
}
}
}
示例14: insertRows
import com.google.common.collect.Lists; //導入方法依賴的package包/類
@Override
public void insertRows(List<org.apache.spark.sql.Row> collectAsList, String tableName, List<String> columns)
throws QueryExecutionException {
try (Cluster cassandraConnection = buildConnection()) {
try (Session session = cassandraConnection.connect()) {
System.out.println("columns : " + columns);
List<List<org.apache.spark.sql.Row>> partition = Lists.partition(collectAsList, batchSize);
int total = 0;
for (List<org.apache.spark.sql.Row> list : partition) {
String q = "BEGIN BATCH \n";
for (org.apache.spark.sql.Row row : list) {
String insertQuery = "insert into wootag." + tableName + " (" + columns.get(0) + ", "
+ columns.get(1) + ", " + columns.get(2) + ") VALUES ";
insertQuery += "\n (" + "'" + row.getString(0) + "'" + "," + row.getLong(1) + ","
+ row.getLong(2) + ");\n";
q += insertQuery;
}
session.execute(q + " APPLY BATCH; ");
total += batchSize;
System.out.println("Executing batch of " + batchSize + ", Total : " + total);
}
}
}
}
示例15: generateHtmlTableFromListOfStrings
import com.google.common.collect.Lists; //導入方法依賴的package包/類
private String generateHtmlTableFromListOfStrings(List<String> elements) {
StringBuilder html = new StringBuilder("<table style=\"border: 0;\">\n");
List<List<String>> subLists = Lists.partition(elements, 3);
for (List<String> subList : subLists) {
html.append("<tr>");
for (String element : subList) {
html.append("<td style=\"border: 0; \">");
html.append("<code>").append(element).append("</code>");
html.append("</td>\n");
}
html.append("</tr>");
}
html.append("</table>\n");
return html.toString();
}