本文整理汇总了Java中com.google.common.collect.Iterables.partition方法的典型用法代码示例。如果您正苦于以下问题:Java Iterables.partition方法的具体用法?Java Iterables.partition怎么用?Java Iterables.partition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Iterables
的用法示例。
在下文中一共展示了Iterables.partition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyDiff
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
protected void applyDiff ( final IProgressMonitor parentMonitor ) throws InterruptedException, ExecutionException
{
final SubMonitor monitor = SubMonitor.convert ( parentMonitor, 100 );
monitor.setTaskName ( Messages.ImportWizard_TaskName );
final Collection<DiffEntry> result = this.mergeController.merge ( wrap ( monitor.newChild ( 10 ) ) );
if ( result.isEmpty () )
{
monitor.done ();
return;
}
final Iterable<List<DiffEntry>> splitted = Iterables.partition ( result, Activator.getDefault ().getPreferenceStore ().getInt ( PreferenceConstants.P_DEFAULT_CHUNK_SIZE ) );
final SubMonitor sub = monitor.newChild ( 90 );
try
{
final int size = Iterables.size ( splitted );
sub.beginTask ( Messages.ImportWizard_TaskName, size );
int pos = 0;
for ( final Iterable<DiffEntry> i : splitted )
{
sub.subTask ( String.format ( Messages.ImportWizard_SubTaskName, pos, size ) );
final List<DiffEntry> entries = new LinkedList<DiffEntry> ();
Iterables.addAll ( entries, i );
final NotifyFuture<Void> future = this.connection.getConnection ().applyDiff ( entries, null, new DisplayCallbackHandler ( getShell (), "Apply diff", "Confirmation for applying diff is required" ) );
future.get ();
pos++;
sub.worked ( 1 );
}
}
finally
{
sub.done ();
}
}
示例2: updateLayout
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
private void updateLayout( ) {
getChildren( ).clear( );
final Collection<TileViewModel> builds = _model.getDisplayedBuilds( );
final Collection<ProjectTileViewModel> projects = _model.getDisplayedProjects( );
final int totalTilesCount = builds.size( ) + projects.size( );
final int maxTilesByColumn = _model.getMaxTilesByColumnProperty( ).get( );
final int maxTilesByRow = _model.getMaxTilesByRowProperty( ).get( );
final int maxByScreens = max( 1, maxTilesByColumn * maxTilesByRow );
final int nbScreen = max( 1, totalTilesCount / maxByScreens + ( ( totalTilesCount % maxByScreens > 0 ? 1 : 0 ) ) );
int byScreen = max( 1, totalTilesCount / nbScreen + ( ( totalTilesCount % nbScreen > 0 ? 1 : 0 ) ) );
// We search to complete columns of screen with tiles, not to have empty blanks (ie having a number of column which are all completed)
while ( byScreen % maxTilesByColumn != 0 )
byScreen++;
final int nbColums = max( 1, byScreen / maxTilesByColumn + ( ( byScreen % maxTilesByColumn > 0 ? 1 : 0 ) ) );
final int byColums = max( 1, byScreen / nbColums + ( ( byScreen % nbColums > 0 ? 1 : 0 ) ) );
final Iterable<List<Object>> screenPartition = Iterables.partition( Iterables.concat( builds, projects ), byScreen );
for ( final List<Object> buildsInScreen : screenPartition ) {
final GridPane screenPane = buildScreenPane( buildsInScreen, nbColums, byColums );
screenPane.setVisible( false );
getChildren( ).add( screenPane );
}
displayNextScreen( );
}
示例3: processAsynchronously
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
protected void processAsynchronously(List<T> adapters, Event event) {
// It must be Iterables.partition here, not Lists.partition because of concurrent access to the adapters list.
for (List<T> partition : Iterables.partition(adapters, asyncEventSetProcessorProcessingPartitionSize)) {
CompletableFuture.allOf(partition.stream().map(adapter -> CompletableFuture.runAsync(() -> {
try {
processAdapter(adapter, event);
} catch (Throwable e) {
getProcessingUnit().getEngine().handleError(
SyncAsyncEventSetProcessorMainProcessingUnitHandler.class.getSimpleName() + ".processAsynchronously", e);
}
}, getAsyncEventSetProcessorThreadPool().getExecutor())).toArray(CompletableFuture[]::new)).join();
}
}
示例4: splitEvery
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public static String splitEvery(String s, String delimiter, int partitionSize) {
StringBuilder sb = new StringBuilder();
for (Iterable<String> iterable : Iterables
.partition(Splitter.on(delimiter).split(s), partitionSize)) {
String str = Joiner.on(delimiter).join(iterable) + ",\n";
sb.append(str);
}
String result = replaceLast(sb.toString(), ",", "");
return result;
}
示例5: runWithAvailableThreads
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
* Similar to {@link #runWithAvailableThreads(ThreadPoolExecutor, int, Collection)}
* but this function will return a Future that wraps the futures of each callable
*
* @param executor executor that is used to execute the callableList
* @param poolSize the corePoolSize of the given executor
* @param callableCollection a collection of callable that should be executed
* @param mergeFunction function that will be applied to merge the results of multiple callable in case that they are
* executed together if the threadPool is exhausted
* @param <T> type of the final result
* @return a future that will return a list of the results of the callableList
* @throws RejectedExecutionException
*/
public static <T> ListenableFuture<List<T>> runWithAvailableThreads(
ThreadPoolExecutor executor,
int poolSize,
Collection<Callable<T>> callableCollection,
final Function<List<T>, T> mergeFunction) throws RejectedExecutionException {
ListeningExecutorService listeningExecutorService = MoreExecutors.listeningDecorator(executor);
List<ListenableFuture<T>> futures;
int availableThreads = Math.max(poolSize - executor.getActiveCount(), 1);
if (availableThreads < callableCollection.size()) {
Iterable<List<Callable<T>>> partition = Iterables.partition(callableCollection,
callableCollection.size() / availableThreads);
futures = new ArrayList<>(availableThreads + 1);
for (final List<Callable<T>> callableList : partition) {
futures.add(listeningExecutorService.submit(new Callable<T>() {
@Override
public T call() throws Exception {
List<T> results = new ArrayList<T>(callableList.size());
for (Callable<T> tCallable : callableList) {
results.add(tCallable.call());
}
return mergeFunction.apply(results);
}
}));
}
} else {
futures = new ArrayList<>(callableCollection.size());
for (Callable<T> callable : callableCollection) {
futures.add(listeningExecutorService.submit(callable));
}
}
return Futures.allAsList(futures);
}