1. private List<ConvertibleFundVO> getResortedConvertibleList(List<ConvertibleFundVO> convertibleFundList, String accountNo) {
    2. if (CollectionUtils.isEmpty(convertibleFundList)) {
    3. return convertibleFundList;
    4. }
    5. List<String> prodCodes = operateService
    6. .queryCollectProdCodes(new QueryCollectProdCodesReqBO().setAccountNo(accountNo))
    7. .getProdCodes();
    8. if (CollectionUtils.isEmpty(prodCodes)) {
    9. return convertibleFundList;
    10. }
    11. return convertibleFundList
    12. .stream()
    13. .sorted((x, y) -> {
    14. int indexX = prodCodes.indexOf(x.getTargetFundCode());
    15. int indexY = prodCodes.indexOf(y.getTargetFundCode());
    16. if (indexX == -1) {
    17. return 1;
    18. }
    19. if (indexY == -1) {
    20. return -1;
    21. }
    22. return indexX - indexY;
    23. }
    24. ).map(r -> r.setCollectFlag(prodCodes.contains(r.getTargetFundCode())))
    25. .collect(Collectors.toList());
    26. }
    27. // 示例
    28. public static void main(String[] args) {
    29. String[] regulation = {"诸葛亮", "鲁班", "xzcx", "貂蝉", "吕布"};
    30. final List regulationOrder = Arrays.asList(regulation);
    31. String[] ordered = {"nice", "貂蝉", "诸葛亮", "xzcx", "吕布", "貂蝉", "鲁班", "诸葛亮", "貂蝉", "鲁班", "诸葛亮", "hahahahah", "adsad"};
    32. List orderedList = Arrays.asList(ordered);
    33. Collections.sort(orderedList, (o1, o2) -> {
    34. int io1 = regulationOrder.indexOf(o1);
    35. int io2 = regulationOrder.indexOf(o2);
    36. if (io1 == -1) {
    37. return 1;
    38. }
    39. if (io2 == -1) {
    40. return -1;
    41. }
    42. return io1 - io2;
    43. });
    44. System.out.println(orderedList);
    45. }