先日、2つのオブジェクトの比較、equals がそのまま使えること、"" 空文字=すなわち存在しないことと
null を同義とみた処理で書いてた。
・・・・実質、String と Integer にしかそのまま使えないけど、それしか目的にしてなかったのでそういうつもりで
使えばいいと安易な考え、自分勝手なものだけど。
この勢いで作ったのが、コレクションの比較
public static <T, U, R> Collection<R> parse(Collection<T> tcol, Collection<U> ucol, BiConsumer<Integer, T> tonly, BiConsumer<Integer, U> uonly){
AtomicInteger index = new AtomicInteger(0);
tcol.stream().forEach(t->{
int i = index.getAndIncrement();
if (ucol.stream().noneMatch(u->u.equals(t))){
tonly.accept(i, t);
}
});
index.set(0);
return ucol.stream().<R>map(u->{
int i = index.getAndIncrement();
if (tcol.stream().noneMatch(t->t.equals(u))){
uonly.accept(i, u);
return null;
}else{
return (R)u;
}
}).filter(r->r != null).collect(Collectors.toList());
}