title: Java Stream -> Creating a list from another list of different structure
body: <p>I am new to Java Stream api and your help is highly appreciated.</p>
  
  <p>I am trying to convert this structure(first Structure) to</p>
  
  <pre><code>[(id=BNA, name=Nashville, TN, loadsCount=1, distance=null, metricScoresList=[BattingOrderResponse.MetricScoresList(identifier=BNA, name=null, aggregatedScore=35.5, onTimeToDestinationPercentage=0.0, onTimeToPickupPercentage=0.0, onTimeToPickupDepartPercentage=0.0, tenderAcceptancePercentage=18.2, tenderCancellationPercentage=0.0, appUsageCompliancePercentage=100.0, revenue=0.0, loadsCount=1, distance=0.0)])...]
  </code></pre>
  
  <p>This is the class model:</p>
  
  <pre><code>@ToString
  @Getter
  public final class BattingOrderResponse {
  
  private final String id;
  private final String name;
  private final long loadsCount;
  private final Distance distance;
  private final List&lt;MetricScores&gt; metricScores;
  @JsonCreator
  public BattingOrderResponse(@JsonProperty("id") final String id,
          @JsonProperty("name") final String name,
          @JsonProperty("loadsCount") final long loadsCount,
          @JsonProperty("distance") final Distance distance,
          @JsonProperty("metricScores") final List&lt;MetricScores&gt; metricScores) {
      this.id = id;
      this.name = name;
      this.loadsCount = loadsCount;
      this.distance = distance;
      this.metricScores = metricScores;
  }
  
  @ToString
  @Getter
  public static final class Distance {
  
      private final double value;
      private final String unit;
      @JsonCreator
      public Distance(@JsonProperty("value") final double value,
              @JsonProperty("unit") final String unit) {
          this.value = value;
          this.unit = unit;
      }
  
  }
  
  @ToString
  @Getter
  public static final class MetricScores {
  
      private final String identifier;
      private final String name;
      private final double aggregatedScore;
      private final double onTimeToDestinationPercentage;
      private final double onTimeToPickupPercentage;
      private final double onTimeToPickupDepartPercentage;
      private final double tenderAcceptancePercentage;
      private final double tenderCancellationPercentage;
      private final double appUsageCompliancePercentage;
      private final double revenue;
      private final long loadsCount;
      private final double distance;
  
      @JsonCreator
      //CHECKSTYLE:SUPPRESS:ParameterNumberCheck
      public MetricScores(@JsonProperty("identifier") final String identifier,
              @JsonProperty("name") final String name,
              @JsonProperty("aggregatedScore") final double aggregatedScore,
              @JsonProperty("onTimeToDestinationPercentage") final double onTimeToDestinationPercentage,
              @JsonProperty("onTimeToPickupPercentage") final double onTimeToPickupPercentage,
              @JsonProperty("onTimeToPickupDepartPercentage") final double onTimeToPickupDepartPercentage,
              @JsonProperty("tenderAcceptancePercentage") final double tenderAcceptancePercentage,
              @JsonProperty("tenderCancellationPercentage") final double tenderCancellationPercentage,
              @JsonProperty("appUsageCompliancePercentage") final double appUsageCompliancePercentage,
              @JsonProperty("revenue") final double revenue,
              @JsonProperty("loadsCount") final long loadsCount,
              @JsonProperty("distance") final double distance) {
          this.identifier = identifier;
          this.name = name;
          this.aggregatedScore = aggregatedScore;
          this.onTimeToDestinationPercentage = onTimeToDestinationPercentage;
          this.onTimeToPickupPercentage = onTimeToPickupPercentage;
          this.onTimeToPickupDepartPercentage = onTimeToPickupDepartPercentage;
          this.tenderAcceptancePercentage = tenderAcceptancePercentage;
          this.tenderCancellationPercentage = tenderCancellationPercentage;
          this.appUsageCompliancePercentage = appUsageCompliancePercentage;
          this.revenue = revenue;
          this.loadsCount = loadsCount;
          this.distance = distance;
      }
  
  }
  }
  </code></pre>
  
  <p>to </p>
  
  <pre><code>[(id=BNA, name=null, overallScore=35.5, onTimeScore=0.0, TenderAcceptanceScore=18.2, appUsageScore=100.0),...]
  </code></pre>
  
  <p>class model:</p>
  
  <pre><code>@Getter
  @ToString
  @Builder
  public final class DomicileScore {
  
  private final String id;
  
  private final String name;
  
  private final double overallScore;
  
  private final double onTimeScore;
  
  private final double TenderAcceptanceScore;
  
  private final double appUsageScore;
  
  }
  </code></pre>
  
  <p>Hint: id is BattingOrderResponse.id
        name is BattingOrderResponse.name
        overallScore is BattinOrderResponse.MetricScore
        and remaining all are from BattinOrderResponse.MetricScore</p>
  
  <p>where it should be 'name=Nashville' instead of 'name=null' (which has been referred from metricScoresList.</p>
  
  <p>This is the code that i have tried.</p>
  
  <pre><code>scoreByDomicile.stream()
              .peek(i -&gt; System.out.println(i.getName()))
              .map(i -&gt; i.getMetricScoresList().get(0))
              .map(i -&gt; DomicileScore.builder()
                      .id(i.getIdentifier())
                      .name(i.getName())
                      .overallScore(i.getAggregatedScore())
                      .appUsageScore(i.getAppUsageCompliancePercentage())
                      .onTimeScore(i.getOnTimeToDestinationPercentage())
                      .TenderAcceptanceScore(i.getTenderAcceptancePercentage())
                      .build())
               .collect(Collectors.toList());
  </code></pre>
  
  <p>where scoreByDomicile is the list of the raw data as in my first structure. I need to add the outcome of peek in the map(second map in the code) inside the build().</p>
  
  <p>I am struck with this for last few hours and not able to resolve it. Let me know if you need more details. Thanks in advance.</p>