我有以下情况,两个邻里对象和同一条街道但不同的房子。
我想知道使用流如何将我分组为一个邻域对象
总之,我有以下数据
Neighborhood: n11
streets: s11
houses: h1
Neighborhood: n11
streets: s11
houses: h2
我想合并它以显示如下
Neighborhood: n11
streets: s11
houses: h1,h2
代码如下
public class Neighborhood{
public UUID id;
public List<Street> streets;
public Neighborhood(UUID id, List<Street> streets)
{
this.id=id;
this.streets=streets;
}
}
public class Streets
{
public UUID id;
public List<House> houses;
public Streets(UUID id, List<House> houses)
{
this.id=id;
this.houses=houses
}
}
public class House
{
public UUID id;
public House(id)
{
this.id=id;
}
}
House h1= new House("h11")
Street s1= new Street("s11", asList(h1))
Neighborhood n1 = new Neighborhood("n11", asList(s1));
House h2= new House("h12")
Street s2= new Street("s11", asList(h2))
Neighborhood n2 = new Neighborhood("n11", asList(s2));
慕标5832272
蝴蝶刀刀
相关分类