我尝试了解新的Java 8 Streams,并且我尝试了几天将嵌套的foreach循环转移到Java 8 Streams中的集合上.
是否有可能重构以下嵌套的foreach循环,包括Java-8-Streams中的if-conditions?
如果是的话会是什么样子.
ArrayList<ClassInq> Inq = new ArrayList<>();
TreeMap<String, SalesQuot> Quotations = new TreeMap<>();
ArrayList<ClassInq> tempInqAndQuot = new ArrayList<>();
ArrayList<SalesQuot> tempQuotPos = new ArrayList<>();
for(ClassInq simInq : this.Inq) {
if(!simInq.isClosed() && !simInq.isDenied()) {
for(Map.Entry<String, SalesQuot> Quot: Quotations.entrySet()) {
SalesQuot sapQuot = Quot.getValue();
if(sapQuot.getInquiryDocumentNumber().compareTo(simInq.getSapInquiryNumber()) == 0) {
simInq.setSAPQuotationNumber(sapQuot.getQuotationDocumentNumber());
tempInqAndQuot.add(simInq);
for(Map.Entry<String, SalesQuotPosition> quotp : sapQuot.getPosition().entrySet()) {
tempQuotPos.add(quotp.getValue());
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
非常感谢你的帮助.
BR
也许有人可以帮助我。我试图将以下 ist 平铺到一个 Pandas 数据帧中:
[{u'_id': u'2',
u'_index': u'list',
u'_score': 1.4142135,
u'_source': {u'name': u'name3'},
u'_type': u'doc'},
{u'_id': u'5',
u'_index': u'list',
u'_score': 1.4142135,
u'_source': {u'dat': u'2016-12-12', u'name': u'name2'},
u'_type': u'doc'},
{u'_id': u'1',
u'_index': u'list',
u'_score': 1.4142135,
u'_source': {u'name': u'name1'},
u'_type': u'doc'}]
Run Code Online (Sandbox Code Playgroud)
结果应如下所示:
|_id | _index | _score | name | dat | _type |
------------------------------------------------------
|1 |list |1.4142..| name1| nan | doc |
|2 |list |1.4142..| name3| nan | doc |
|3 |list |1.4142..| name1| 2016-12-12 | doc |
Run Code Online (Sandbox Code Playgroud)
但是我尝试做的所有事情都无法获得所需的结果。我使用了这样的东西:
df …Run Code Online (Sandbox Code Playgroud) collections ×1
dataframe ×1
foreach ×1
java ×1
java-8 ×1
java-stream ×1
json ×1
nested ×1
pandas ×1
python ×1