TransactionsPresenter extends BasePresenter<TransactionsContract.View> implements TransactionsContract.Presenter { private long getValidSmallerSequence(List<Transaction> transactionList) { return Flowable .range(0, transactionList.size()) .filter(new Predicate<Integer>() { @Override public boolean test(Integer integer) throws Exception { return transactionList.get(integer).getSequence() != 0; } }) .lastElement() .map(new Function<Integer, Long>() { @Override public Long apply(Integer integer) throws Exception { return transactionList.get(integer).getSequence(); } }) .blockingGet(); } TransactionsPresenter(); @SuppressLint("CheckResult") @Override void loadLatestData(); @SuppressLint("CheckResult") @Override void loadNew(String direction); @Override void deleteTransaction(Transaction transaction); @Override synchronized void addNewTransaction(Transaction transaction); final static String DIRECTION_OLD; final static String DIRECTION_NEW; }
@Test public void testGetValidSmallerSequence() { List<Transaction> list = new ArrayList<>(); Transaction transaction = new Transaction(); transaction.setActualTxCost("0.005648"); transaction.setBlockNumber("10556"); transaction.setNodeId("0xfa4a45sfa54s4dfa5s"); transaction.setNodeName("Node-1"); transaction.setFrom("0x4ded81199608adb765fb2fe029bbfdf57f538be8"); transaction.setSequence(1025); list.add(transaction); Transaction transaction2 = new Transaction(); transaction.setActualTxCost("0.005648"); transaction.setBlockNumber("10556"); transaction.setNodeId("0xfa4a45sfa54s4dfa5s"); transaction.setNodeName("Node-1"); transaction.setFrom("0x4ded81199608adb765fb2fe029bbfdf57f538be8"); transaction.setSequence(1028); list.add(transaction2); Transaction transaction3 = new Transaction(); transaction.setActualTxCost("0.005648"); transaction.setBlockNumber("10556"); transaction.setNodeId("0xfa4a45sfa54s4dfa5s"); transaction.setNodeName("Node-1"); transaction.setSequence(1035); transaction.setFrom("0x4ded81199608adb765fb2fe029bbfdf57f538be8"); list.add(transaction3); Transaction transaction4 = new Transaction(); transaction.setActualTxCost("0.005648"); transaction.setBlockNumber("10556"); transaction.setNodeId("0xfa4a45sfa54s4dfa5s"); transaction.setNodeName("Node-1"); transaction.setSequence(1055); transaction.setFrom("0x4ded81199608adb765fb2fe029bbfdf57f538be8"); list.add(transaction4); long smallSequence =Flowable .range(0, list.size()) .filter(new Predicate<Integer>() { @Override public boolean test(Integer integer) throws Exception { return list.get(integer).getSequence() != 0; } }) .lastElement() .map(new Function<Integer, Long>() { @Override public Long apply(Integer integer) throws Exception { return list.get(integer).getSequence(); } }) .blockingGet(); assertNotNull(smallSequence); System.out.println(smallSequence); }