首页 > 解决方案 > Java android房间对象映射

问题描述

我有这门课:

public class RelationshipsOrderAndBins {

    @Embedded
    public RowEntity order;

    @Relation(parentColumn = "order_id", entityColumn = "orderId",entity = LoadingRow.class)
    public List<LoadingRow> bins;
}

LiveData<List<RelationshipsOrderAndBins>>我这样做:

@Query("SELECT * FROM orders INNER JOIN bin ON orders.order_id= bin.orderId")
    LiveData<List<RelationshipsOrderAndBins>> geRelationshipsOrderAndBins();

而且我不知道如何转换为:HashMap<Integer,List,Loadings>关键在哪里order.getId()

标签: javaandroidandroid-room

解决方案


要将 a 转换List为 a Map,您可以使用流并使用收集它Collectors.toMap

List<RelationshipsOrderAndBins> list = new ArrayList<RelationshipsOrderAndBins>();

Map<Integer, List<LoadingRow>> map = list.stream()
        .collect(Collectors.toMap(
                r -> r.getOrder().getId(),
                r -> r.getBins()));

推荐阅读