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


Java Deque.clear方法代码示例

本文整理汇总了Java中java.util.Deque.clear方法的典型用法代码示例。如果您正苦于以下问题:Java Deque.clear方法的具体用法?Java Deque.clear怎么用?Java Deque.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Deque的用法示例。


在下文中一共展示了Deque.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: call

import java.util.Deque; //导入方法依赖的package包/类
public Subscriber<? super T> call(Subscriber<? super T> subscriber) {
    final Deque<Object> deque = new ArrayDeque();
    final NotificationLite<T> notification = NotificationLite.instance();
    final TakeLastQueueProducer<T> producer = new TakeLastQueueProducer(notification, deque, subscriber);
    subscriber.setProducer(producer);
    final Subscriber<? super T> subscriber2 = subscriber;
    return new Subscriber<T>(subscriber) {
        public void onStart() {
            request(Long.MAX_VALUE);
        }

        public void onCompleted() {
            deque.offer(notification.completed());
            producer.startEmitting();
        }

        public void onError(Throwable e) {
            deque.clear();
            subscriber2.onError(e);
        }

        public void onNext(T value) {
            if (OperatorTakeLast.this.count != 0) {
                if (deque.size() == OperatorTakeLast.this.count) {
                    deque.removeFirst();
                }
                deque.offerLast(notification.next(value));
            }
        }
    };
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:32,代码来源:OperatorTakeLast.java

示例2: call

import java.util.Deque; //导入方法依赖的package包/类
public Subscriber<? super T> call(Subscriber<? super T> subscriber) {
    final Deque<Object> buffer = new ArrayDeque();
    final Deque<Long> timestampBuffer = new ArrayDeque();
    final NotificationLite<T> notification = NotificationLite.instance();
    final TakeLastQueueProducer<T> producer = new TakeLastQueueProducer(notification, buffer, subscriber);
    subscriber.setProducer(producer);
    final Subscriber<? super T> subscriber2 = subscriber;
    return new Subscriber<T>(subscriber) {
        protected void runEvictionPolicy(long now) {
            while (OperatorTakeLastTimed.this.count >= 0 && buffer.size() > OperatorTakeLastTimed.this.count) {
                timestampBuffer.pollFirst();
                buffer.pollFirst();
            }
            while (!buffer.isEmpty() && ((Long) timestampBuffer.peekFirst()).longValue() < now - OperatorTakeLastTimed.this.ageMillis) {
                timestampBuffer.pollFirst();
                buffer.pollFirst();
            }
        }

        public void onStart() {
            request(Long.MAX_VALUE);
        }

        public void onNext(T args) {
            long t = OperatorTakeLastTimed.this.scheduler.now();
            timestampBuffer.add(Long.valueOf(t));
            buffer.add(notification.next(args));
            runEvictionPolicy(t);
        }

        public void onError(Throwable e) {
            timestampBuffer.clear();
            buffer.clear();
            subscriber2.onError(e);
        }

        public void onCompleted() {
            runEvictionPolicy(OperatorTakeLastTimed.this.scheduler.now());
            timestampBuffer.clear();
            buffer.offer(notification.completed());
            producer.startEmitting();
        }
    };
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:45,代码来源:OperatorTakeLastTimed.java


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