左外连接使用 Seq ,元组和流使用 jool java 8



我有两个列表客户和地址,它们将pmtxnid作为公共值。 我想使用 jool(java 8( leftouterjoin 方法,但我不知道正确的语法。也没有一个例子可以让我以更简单的方式理解它. 如果有人知道Seq,Tuples jool与java 8 Streams,请提供帮助。

List<Customers> customers = new ArrayList<Customers>();
customers.add(new Customers(16079391, 12, "A")); // NULL
customers.add(new Customers(16079392, 13, "B")); // 2
customers.add(new Customers(16079393, 14, "C")); // NULL
customers.add(new Customers(16079394, 15, "D")); // BIll
customers.add(new Customers(16079395, 16, "E")); // 1
List<Address> addresses = new ArrayList<Address>();
addresses.add(new Address(1, 16079392, "bangalore", "karnataka"));
addresses.add(new Address(2, 16079392, "chennai", "tamil nadu"));
addresses.add(new Address(3, 16079392, "hyderabad", "telanagana"));
addresses.add(new Address(4, 16079395, "indore", "mp"));
addresses.add(new Address(5, 16079395, "kanpur", "up"));
Seq<List<Customers>> s1 = Seq.of(customers);
Seq<List<Address>> s2 = Seq.of(addresses);

我尝试了下面的代码,但没有成功。

Seq<Tuple2<Seq<List<Customers>>, Seq<List<Address>>>> loj=  Seq.of(s1).leftOuterJoin(Seq.of(s2), (t, u) -> Objects.equals(t, u));

假设可以分别使用Customers#getPmtxnid()Address#getPmtxnid()访问公共pmtxnid值,则leftOuterJoin()调用应如下所示:

var result = Seq.of(s1).leftOuterJoin(Seq.of(s2),
(c, a) -> Objects.equals(c.getPmtxnid(), a.getPmtxnid()));

请注意,仅当任一对象可以具有nullpmtxnid 时,才需要Objects#equals()

相关内容

  • 没有找到相关文章