*
L
2 天以前 538ce7e95297953686db099cacd63e76d2d83154
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.zy.asrs.utils;
 
import com.zy.core.cache.RgvStatusCache;
import com.zy.core.model.RgvSlave;
import com.zy.core.model.protocol.RgvProtocol;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
 
/**
 * Created by Monkey D. Luffy on 2023/7/18
 */
public class LocFCSUtils {
 
 
    public static void main(String[] args) {
        ArrayList<String> locSF = new ArrayList<>();
        locSF.add("0102101");
        locSF.add("0100102");
        locSF.add("0100101");
        locSF.add("0101001");
        locSF.add("0107101");
        locSF.add("0108101");
        ArrayList<String> locSE = new ArrayList<>();
        locSE.add("0202101");
        locSE.add("0200102");
        locSE.add("0200101");
        locSE.add("0201001");
        locSE.add("0207101");
        locSE.add("0208101");
        System.out.println(Arrays.toString(locSF.toArray()));
        System.out.println(Arrays.toString(locSE.toArray()));
        ArrayList<String[]> locS1 = LocFCSUtils.getLocS(locSF);
        ArrayList<String[]> locS2 = LocFCSUtils.getLocS(locSE);
        ArrayList<String[]> arrayList = LocFCSUtils.updateLocSInPlace(locS1, locS2);
        for (String[] loc : arrayList) {
            System.out.println(Arrays.toString(loc));
        }
 
    }
    public static ArrayList<String[]> getLocS(ArrayList<String> locMastDemoListF) {
        ArrayList<String[]> locS = new ArrayList<>();
        // 提取数据
        int idx = 1;
        for (String locNo : locMastDemoListF) {
            if (locNo != null && locNo.length() >= 5) {
                String[] strings = new String[4];  // 增加一列用于排序序号
                String result = locNo.substring(2, 5);
 
                strings[0] = locNo;              // 原字符串
                strings[1] = result;              // 截取的部分
                strings[2] = String.valueOf(idx); // 原始序号
                strings[3] = "";                  // 排序序号(暂空)
 
                locS.add(strings);
            }
            idx++;
        }
 
// 排序
        Collections.sort(locS, (a, b) -> {
            int numA = Integer.parseInt(a[1]);
            int numB = Integer.parseInt(b[1]);
            return Integer.compare(numA, numB);
        });
 
// 设置排序序号
        for (int i = 0; i < locS.size(); i++) {
            locS.get(i)[3] = String.valueOf(i + 1);
        }
        return locS;
    }
 
    public static void updateLocSInPlace(ArrayList<String[]> locS) {
        if (locS == null || locS.isEmpty()) {
            return;
        }
 
        // 更新排序序号
        for (String[] row : locS) {
            int currentSort = Integer.parseInt(row[3]);
 
            if (currentSort == 1) {
                row[3] = String.valueOf(locS.size());
            } else {
                row[3] = String.valueOf(currentSort - 1);
            }
        }
    }
    public static ArrayList<String[]> updateLocSInPlace(ArrayList<String[]> locSF,ArrayList<String[]> locSE) {
        if (locSF == null || locSF.isEmpty()) {
            return new ArrayList<>();
        }
        if (locSE == null || locSE.isEmpty()) {
            return new ArrayList<>();
        }
 
        for (String[] rowF : locSF) {
            for (String[] rowE : locSE) {
                if (rowF[3].equals(rowE[3])) {
                    rowF[2] =  rowE[0];
                }
            }
        }
        return locSF;
    }
 
}