누구나 내지도의 결과를 외곽지도와 매핑하는 방법을 안내해 줄 수 있습니까? 나는 각각의 pricepoint에 대한 최소 순위를 얻음으로써 내부지도에 매핑 한 List holding Id, Pricepoint, Rank와 함께 Pricepoint 객체를 만들었으므로 이제는 특정 ID와 결과를 매핑하려고합니다. 솔직히 당신이 정말로 이것에 대한 사용 사례를 희망 ...Pricepoint의 최소 계급을 찾는 방법
Map<String, Map<String, Integer>> map1 = p.stream()
.collect(Collectors.collectingAndThen(
Collectors.groupingBy(
Pricepoint::getPricepoint,
Collectors.collectingAndThen(
Collectors.minBy(Comparator.comparing(Pricepoint::getRank)),
Optional::get)),
(Map<String, Pricepoint> x) -> {
return x.entrySet()
.stream()
.collect(Collectors.groupingBy(
entry -> entry.getValue().getId(),
Collectors.toMap(Entry::getKey, e -> e.getValue().getRank())));
}));
System.out.println(map1);
을하지만 이것은 단지 미친 듯이 복잡하다 : 덕분에
public class Pricepoint {
String id;
String pricepoint;
int rank;
public Pricepoint(String id,String pricepoint,int rank)
{
this.id = id;
this.pricepoint = pricepoint;
this.rank= rank;
}
public String getId() {
return id;
}
public String getPricepoint() {
return pricepoint;
}
public int getRank() {
return rank;
}
public static void main(String[] args)
{
final Comparator<Pricepoint> comp = (p1, p2) -> Integer.compare(p1.getRank(), p2.getRank());
List<Pricepoint> p = new LinkedList<>();
p.add(new Pricepoint("1","PP1",1));
p.add(new Pricepoint("2", "PP1", 2));
p.add(new Pricepoint("3","PP2",3));
p.add(new Pricepoint("4", "PP2", 4));
Map<String,Map<String,Integer>> map1 = p.stream()
.collect(Collectors.toMap(Pricepoint::getPricepoint,Pricepoint::getRank,Math::min))// I'm struck here
질문을 명확히하십시오. 결과는 어떻게 생겼습니까? – Flown
아래 코드는 {1 = pp1 = 1,3 = pp2 = 3} – user9122587