Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to find the best way to optimise the converters below to follow the flow I call 'convertAndGroupForUpdate' first which triggers the conversions and relevant mappings.

Any help to optimise this code would be massively appreciated.

Java
public List<GroupedOrderActionUpdateEntity> convertAndGroupForUpdate(List<SimpleRatifiableAction> actions) {
    List<GroupedOrderActionUpdateEntity> groupedActions = new ArrayList<>();

    Map<String, List<SimpleRatifiableAction>> groupSimple = actions.stream()
        .collect(Collectors.groupingBy(x -> x.getOrderNumber() + x.getActionType()));

    groupSimple.entrySet().stream()
        .map(x -> convertToUpdateGroup(x.getValue()))
        .forEachOrdered(groupedActions::add);

    return groupedActions;
  }

  public GroupedOrderActionUpdateEntity convertToUpdateGroup(List<SimpleRatifiableAction> actions) {
    List<OrderActionUpdateEntity> actionList = actions.stream().map(x -> convertToUpdateEntity(x)).collect(Collectors.toList());

    return new GroupedOrderActionUpdateEntity(
        actions.get(0).getOrderNumber(),
        OrderActionType.valueOf(actions.get(0).getActionType()),
        actions.get(0).getSource(),
        12345,
        actions.stream().map(SimpleRatifiableAction::getNote)
            .collect(Collectors.joining(", ", "Group Order Note: ", ".")),
        actionList);
  }

  public OrderActionUpdateEntity convertToUpdateEntity(SimpleRatifiableAction action) {
    return new OrderActionUpdateEntity(action.getId(), OrderActionState.valueOf(action.getState()));
  }


What I have tried:

I have split the functionality into multiple streams but I now am unsure the best approach to optimise this further.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900