本文整理匯總了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 );
}
}