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.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import rx.*;
import rx.Observable.*;
import rx.exceptions.Exceptions;
import rx.functions.*;
import rx.internal.producers.ProducerArbiter;
import rx.internal.util.*;
import rx.observables.GroupedObservable;
import rx.observers.Subscribers;
import rx.plugins.RxJavaHooks;
import rx.subscriptions.Subscriptions;
/**
* Groups the items emitted by an Observable according to a specified criterion, and emits these
* grouped items as Observables, one Observable per group.
*
*
*
* @param
* the key type
* @param
* the source and group value type
* @param
* the value type of the groups
*/
public final class OperatorGroupBy implements Operator, T>{
final Func1 super T, ? extends K> keySelector;
final Func1 super T, ? extends V> valueSelector;
final int bufferSize;
final boolean delayError;
final Func1, Map> mapFactory; //nullable
@SuppressWarnings({ "unchecked", "rawtypes" })
public OperatorGroupBy(Func1 super T, ? extends K> keySelector) {
this(keySelector, (Func1)UtilityFunctions.identity(), RxRingBuffer.SIZE, false, null);
}
public OperatorGroupBy(Func1 super T, ? extends K> keySelector, Func1 super T, ? extends V> valueSelector) {
this(keySelector, valueSelector, RxRingBuffer.SIZE, false, null);
}
public OperatorGroupBy(Func1 super T, ? extends K> keySelector, Func1 super T, ? extends V> valueSelector, Func1, Map> mapFactory) {
this(keySelector, valueSelector, RxRingBuffer.SIZE, false, mapFactory);
}
public OperatorGroupBy(Func1 super T, ? extends K> keySelector, Func1 super T, ? extends V> valueSelector, int bufferSize, boolean delayError, Func1, Map> mapFactory) {
this.keySelector = keySelector;
this.valueSelector = valueSelector;
this.bufferSize = bufferSize;
this.delayError = delayError;
this.mapFactory = mapFactory;
}
@Override
public Subscriber super T> call(Subscriber super GroupedObservable> child) {
final GroupBySubscriber parent; // NOPMD
try {
parent = new GroupBySubscriber(child, keySelector, valueSelector, bufferSize, delayError, mapFactory);
} catch (Throwable ex) {
//Can reach here because mapFactory.call() may throw in constructor of GroupBySubscriber
Exceptions.throwOrReport(ex, child);
Subscriber super T> parent2 = Subscribers.empty();
parent2.unsubscribe();
return parent2;
}
child.add(Subscriptions.create(new Action0() {
@Override
public void call() {
parent.cancel();
}
}));
child.setProducer(parent.producer);
return parent;
}
public static final class GroupByProducer implements Producer {
final GroupBySubscriber, ?, ?> parent;
public GroupByProducer(GroupBySubscriber, ?, ?> parent) {
this.parent = parent;
}
@Override
public void request(long n) {
parent.requestMore(n);
}
}
public static final class GroupBySubscriber
extends Subscriber {
final Subscriber super GroupedObservable> actual;
final Func1 super T, ? extends K> keySelector;
final Func1 super T, ? extends V> valueSelector;
final int bufferSize;
final boolean delayError;
final Map