@Test public void getSumByPaymentMethodLot() { entries = new ArrayList<>(); entries.add(new LabeledGraphEntry(15, LABEL_1)); entries.add(new LabeledGraphEntry(3, LABEL_2)); entries.add(new LabeledGraphEntry(5, LABEL_3)); entries.add(new LabeledGraphEntry(5, LABEL_4)); entries.add(new LabeledGraphEntry(2, LABEL_5)); entries.add(new LabeledGraphEntry(2, LABEL_6)); when(groupingController.getSummationByPaymentMethodAsGraphEntries(trip)).thenReturn(Single.just(entries)); List<LabeledGraphEntry> sortedEntries = new ArrayList<>(entries); Collections.sort(sortedEntries); List<LabeledGraphEntry> expectedEntries = sortedEntries.subList(0, GraphsInteractor.PAYMENT_METHODS_MAX_COUNT); expectedEntries.add(new LabeledGraphEntry(2 + 2, context.getString(R.string.graphs_label_others))); interactor.getSummationByPaymentMethod(trip) .test() .assertNoErrors() .assertComplete() .assertValues(GraphUiIndicator.summationByPaymentMethod(expectedEntries)); }
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()); }
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()); } }
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  GraphsInteractor(Context context, GroupingController groupingController); }
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  GraphsInteractor(Context context, GroupingController groupingController); Maybe<GraphUiIndicator> getSummationByCategories(Trip trip); Maybe<GraphUiIndicator> getSummationByReimbursement(Trip trip); Maybe<GraphUiIndicator> getSummationByPaymentMethod(Trip trip); Maybe<GraphUiIndicator> getSummationByDate(Trip trip); }
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  GraphsInteractor(Context context, GroupingController groupingController); Maybe<GraphUiIndicator> getSummationByCategories(Trip trip); Maybe<GraphUiIndicator> getSummationByReimbursement(Trip trip); Maybe<GraphUiIndicator> getSummationByPaymentMethod(Trip trip); Maybe<GraphUiIndicator> getSummationByDate(Trip trip); final static int PAYMENT_METHODS_MAX_COUNT; }