Guava - List to Map and Multimap

1523 단어
Get Ids from List
public static List<Long> getVendorItemIds(List<VendorItemDdp> vendorItems) {
    return Lists.transform(vendorItems, indexVendorItemId());
}

public static Function<VendorItemDdp, Long> indexVendorItemId() {
    return new Function<VendorItemDdp, Long>() {
        @Override
        public Long apply(VendorItemDdp input) {
            return input.getVendorItemId();
        }
    };
}

List to Map:
public static Map<Long, OriginPriceDto> wrapOriginPriceDto(List<OriginPriceDto> originPriceDtos) {
    return Maps.uniqueIndex(originPriceDtos, indexOriginDtoByVendorItemId());
}

public static Function<OriginPriceDto, Long> indexOriginDtoByVendorItemId() {
    return new Function<OriginPriceDto, Long>() {
        @Override
        public Long apply(OriginPriceDto input) {
            return input.getVendorItemId();
        }
    };
}

List to Multimap:
public static Multimap<Long, ItemPriceTypeDto> indexPriceTypeDto(List<ItemPriceTypeDto> itemPriceTypeDtos) {
    return Multimaps.index(itemPriceTypeDtos, uniqueIndexPriceTypeByVendorItemId());
}

public static Function<ItemPriceTypeDto, Long> uniqueIndexPriceTypeByVendorItemId() {
    return new Function<ItemPriceTypeDto, Long>() {
        @Override
        public Long apply(ItemPriceTypeDto input) {
            return input.getVendorItemId();
        }
    };
}

좋은 웹페이지 즐겨찾기