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;
|
}
|
|
}
|