Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package rx.internal.operators;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Observable.Operator;
import rx.Observer;
import rx.Scheduler;
import rx.Scheduler.Worker;
import rx.Subscriber;
import rx.functions.Action0;
import rx.observers.SerializedObserver;
import rx.observers.SerializedSubscriber;
/**
* Creates windows of values into the source sequence with timed window creation, length and size bounds.
* If timespan == timeshift, windows are non-overlapping but may not be continuous if size number of items were already
* emitted. If more items arrive after the window has reached its size bound, those items are dropped.
*
*
Note that this conforms the Rx.NET behavior, but does not match former RxJava
* behavior, which operated as a regular buffer and mapped its lists to Observables.
*
* @param the value type
*/
public final class OperatorWindowWithTime implements Operator, T> {
/** Length of each window. */
final long timespan;
/** Period of creating new windows. */
final long timeshift;
final TimeUnit unit;
final Scheduler scheduler;
final int size;
public OperatorWindowWithTime(long timespan, long timeshift, TimeUnit unit, int size, Scheduler scheduler) {
this.timespan = timespan;
this.timeshift = timeshift;
this.unit = unit;
this.size = size;
this.scheduler = scheduler;
}
@Override
public Subscriber super T> call(Subscriber super Observable> child) {
Worker worker = scheduler.createWorker();
child.add(worker);
if (timespan == timeshift) {
ExactSubscriber s = new ExactSubscriber(child, worker);
s.scheduleExact();
return s;
}
InexactSubscriber s = new InexactSubscriber(child, worker);
s.startNewChunk();
s.scheduleChunk();
return s;
}
/** Indicate the current subject should complete and a new subject be emitted. */
static final Object NEXT_SUBJECT = new Object();
/** For error and completion indication. */
static final NotificationLite