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