当前位置: 首页>>代码示例>>Java>>正文


Java Iterators.partition方法代码示例

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

}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:21,代码来源:AbstractEventQueryImpl.java

示例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 );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:69,代码来源:EventPoolImpl.java


注:本文中的com.google.common.collect.Iterators.partition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。