本文整理汇总了Java中com.google.common.collect.Iterators.partition方法的典型用法代码示例。如果您正苦于以下问题:Java Iterators.partition方法的具体用法?Java Iterators.partition怎么用?Java Iterators.partition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Iterators
的用法示例。
在下文中一共展示了Iterators.partition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addListener
import com.google.common.collect.Iterators; //导入方法依赖的package包/类
@Override
public synchronized void addListener ( final EventListener eventListener )
{
this.listeners.add ( eventListener );
final UnmodifiableIterator<List<Event>> it = Iterators.partition ( AbstractEventQueryImpl.this.events.iterator (), chunkSize );
while ( it.hasNext () )
{
final List<org.eclipse.scada.ae.Event> chunk = it.next ();
this.executor.execute ( new Runnable () {
@Override
public void run ()
{
eventListener.handleEvent ( chunk );
}
} );
}
}
示例2: loadFromStorage
import com.google.common.collect.Iterators; //导入方法依赖的package包/类
private void loadFromStorage ()
{
// load initial set from storage, but restrict it to *daysToRetrieve* days
try
{
final long t = System.currentTimeMillis ();
// retrieve data per day, to restrict database load
for ( int daysBack = 1; daysBack <= daysToRetrieve; daysBack++ )
{
final Calendar calStart = new GregorianCalendar ();
final Calendar calEnd = new GregorianCalendar ();
calStart.setTimeInMillis ( t );
calStart.add ( Calendar.DAY_OF_YEAR, -daysBack );
calEnd.setTimeInMillis ( t );
calEnd.add ( Calendar.DAY_OF_YEAR, -daysBack + 1 );
final StringBuilder filter = new StringBuilder ();
filter.append ( "(&" );
if ( this.filter != null )
{
filter.append ( this.filter );
}
filter.append ( "(sourceTimestamp>=" + isoDateFormat.format ( calStart.getTime () ) + ")" );
if ( daysBack > 1 )
{
filter.append ( "(sourceTimestamp<" + isoDateFormat.format ( calEnd.getTime () ) + ")" );
}
filter.append ( ")" );
logger.debug ( "load events from filter: " + filter );
final Query query = this.storage.query ( filter.toString () );
try
{
int count;
synchronized ( this )
{
count = this.events.getCapacity ();
}
final Collection<Event> result = query.getNext ( count );
logger.debug ( "Loaded {} entries from storage", result.size () );
synchronized ( this )
{
this.events.addAll ( result );
final UnmodifiableIterator<List<Event>> it = Iterators.partition ( this.events.iterator (), chunkSize );
while ( it.hasNext () )
{
final List<org.eclipse.scada.ae.Event> chunk = it.next ();
notifyEvent ( chunk );
}
}
}
finally
{
query.dispose ();
}
if ( this.events.size () >= this.events.getCapacity () )
{
return;
}
}
logger.debug ( "load of events complete" );
}
catch ( final Exception e )
{
logger.error ( "loadFromStorage failed", e );
}
}