Optional<String> co = listAll.stream().filter(item -> item.contains(temp)).findFirst();
if (co.isPresent()) {
billType = co.get();
Optional<BillItem> obi = listItems.stream().filter(item -> item.getName().contains(temp)).findFirst();
if (obi.isPresent()) {
existItem = obi.get();
}
}
package com.ll.bm;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import java.util.*;
public class BillDateConvert implements Converter {
@Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext mContext) {
BillDate bd = (BillDate) o;
writer.addAttribute("time", bd.getTime());
List<BillItem>listItems=bd.getListItems();
for (BillItem bi:listItems){
writer.startNode("BillItem");
mContext.convertAnother(bi,new BillItemConvert());
writer.endNode();
}
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unContext) {
BillDate bd = new BillDate();
bd.setTime(reader.getAttribute("time"));
List<BillItem> list = new ArrayList<BillItem>();
while (reader.hasMoreChildren()) {
reader.moveDown();
Object o = unContext.convertAnother(bd, BillItem.class, new BillItemConvert());
BillItem od = (BillItem) o;
list.add(od);
reader.moveUp();
}
bd.setAnimalList(list);
// Object o= unContext.convertAnother(bd,bd.getListItems().getClass(),new BillItemConvert());
return bd;
}
@Override
public boolean canConvert(Class aClass) {
return aClass.equals(BillDate.class);
}
}
<Bill>
<BillDate time="2020-10-27">
<BillItem name="1|購物" val="5.0"/>
<BillItem name="2|餐飲" val="13.0"/>
<BillItem name="6|交通" val="9.0"/>
</BillDate>
</Bill>
代碼下載java
javase記帳本管理程序