當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。