class GraphsInteractor {

    public Maybe<GraphUiIndicator> getSummationByPaymentMethod(Trip trip) {
        return groupingController.getSummationByPaymentMethodAsGraphEntries(trip)
                .filter(graphEntries -> !graphEntries.isEmpty())
                .flatMapSingleElement(graphEntries -> {
                    List<LabeledGraphEntry> sortedEntries = new ArrayList<>(graphEntries);
                    Collections.sort(sortedEntries);

                    if (sortedEntries.size() > PAYMENT_METHODS_MAX_COUNT) {
                        List<LabeledGraphEntry> finalEntries = new ArrayList<>(sortedEntries.subList(0, PAYMENT_METHODS_MAX_COUNT));

                        float lastEntryValue = 0;
                        for (int i = PAYMENT_METHODS_MAX_COUNT; i < sortedEntries.size(); i++) {
                            lastEntryValue += sortedEntries.get(i).getY();
                        }

                        finalEntries.add(new LabeledGraphEntry(lastEntryValue, context.getString(R.string.graphs_label_others)));

                        return Single.just(finalEntries);

                    } else {
                        return Single.just(sortedEntries);
                    }
                })
                .map(GraphUiIndicator::summationByPaymentMethod)
                .observeOn(AndroidSchedulers.mainThread());
    }

    @Inject public  GraphsInteractor(Context context, GroupingController groupingController);

}