在我的项目中,我使用RxJava2,因为我发现它非常强大。不过,我一直在努力寻找如何将方法迁移到RxJava2语法的方法。
应用程序读取XML文件,并在XML的每个节点上发出可观察到的信息。然后,我对每个被忽略的项目执行一些任务,最后将所有操作分组在一个列表中。
问题在于某些操作被“重复”了。我们来看一个例子:
<CashTransaction dateTime="07/06/19;20:20:00" type="Withholding Tax" symbol="LNR" amount="-3.02" fxRateToBase="0.66496" />
<CashTransaction dateTime="07/06/19;20:20:00" type="Withholding Tax" symbol="LNR" amount="3.02" fxRateToBase="0.68529" />
<CashTransaction dateTime="07/06/19;20:20:00" type="Withholding Tax" symbol="LNR" amount="-3.02" fxRateToBase="0.68529" />
我在XML中有3种不同的操作,但我想做一个单独的操作,以显示与3种操作相同的内容:
<CashTransaction dateTime="07/06/19;20:20:00" type="Withholding Tax" symbol="LNR" amount="-3.02" fxRateToBase="0.66496" />
此刻,我正在最终列表上执行此方法,但我想知道是否可以在Observable Stream中执行此操作。
public static List<iIB> groupSplittedOperations(List<iIB> iIBNewTransactions)
{
ArrayList<iIB> groupedOperations = new ArrayList<>();
//Iterate all over the operations retrieved from the XML report
for(int originalIndex = 0; originalIndex < iIBNewTransactions.size(); originalIndex++)
{
boolean exists = false;
//This is current operation
iIB currentOperation = iIBNewTransactions.get(originalIndex);
//Check if current operation could be grouped into another operation iterating all
//over grouped operations
for(int groupedIndex = 0; groupedIndex < groupedOperations.size(); groupedIndex++)
{
//This is current grouped operation
iIB groupedOperation = groupedOperations.get(groupedIndex);
//This is the criteria to determine if an operation could be grouped into another one
if(currentOperation.getDateTime().equals(groupedOperation.getDateTime())
&& currentOperation.getOperationType().equals(groupedOperation.getOperationType())
&& currentOperation.getSymbol().equals(groupedOperation.getSymbol())
&& currentOperation.getDescription().equals(groupedOperation.getDescription()))
{
//Update amount of new operation and mark it as existent to avoid adding it to the grouped list
groupedOperation.setamount(String.valueOf(groupedOperation.getamount() + currentOperation.getamount()));
exists = true;
break;
}
}
//Only add operation to grouped list if it was not found on previous search
if(!exists)
groupedOperations.add(currentOperation);
}
return groupedOperations;
}