模拟设备状态变更接口调整
This commit is contained in:
parent
77e2f2e104
commit
d154d09855
@ -0,0 +1,131 @@
|
||||
package club.joylink.xiannccda.ats.message.line3;
|
||||
|
||||
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class DeviceNameChanger {
|
||||
|
||||
// abstract List<String> findAllDeviceName(JSONArray dataArray);
|
||||
|
||||
abstract String changeDeviceName(String nccDeviceName);
|
||||
|
||||
static Map<DeviceType, DeviceNameChanger> NCC_DEVICE_TYPE_NAME_MAPPER = Maps.newHashMap();
|
||||
|
||||
static {
|
||||
NCC_DEVICE_TYPE_NAME_MAPPER.put(DeviceType.DEVICE_TYPE_SWITCH, new SwitchDevice());
|
||||
NCC_DEVICE_TYPE_NAME_MAPPER.put(DeviceType.DEVICE_TYPE_SIGNAL, new SignalDevice());
|
||||
NCC_DEVICE_TYPE_NAME_MAPPER.put(DeviceType.DEVICE_TYPE_TRACK, new TrackDevice());
|
||||
// NCC_DEVICE_TYPE_NAME_MAPPER.put(DeviceType.DEVICE_TYPE_PLATFORM, "stationStandList");
|
||||
}
|
||||
|
||||
|
||||
public static class SwitchDevice extends DeviceNameChanger {
|
||||
|
||||
/* @Override
|
||||
public List<String> findAllDeviceName(JSONArray dataArray) {
|
||||
List<String> mapDeviceNames = dataArray.stream().filter(d -> d instanceof JSONObject).map(d -> (JSONObject) d).map(d -> d.getString("name")).toList();
|
||||
return mapDeviceNames;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public String changeDeviceName(String nccDeviceName) {
|
||||
if (nccDeviceName.length() < 3) {
|
||||
return nccDeviceName;
|
||||
}
|
||||
|
||||
String started = nccDeviceName.substring(0, 1);
|
||||
String head = nccDeviceName.substring(1, 3);
|
||||
String tail = nccDeviceName.substring(4);
|
||||
return started + tail + head;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TrackDevice extends DeviceNameChanger {
|
||||
|
||||
/* @Override
|
||||
List<String> findAllDeviceName(JSONArray dataArray) {
|
||||
Map<String, JSONObject> jsonMap = dataArray.stream().filter(d -> d instanceof JSONObject).map(d -> (JSONObject) d).collect(Collectors.toMap((d) -> d.getString("code"), Function.identity()));
|
||||
List<String> newNames = Lists.newArrayList();
|
||||
for (JSONObject value : jsonMap.values()) {
|
||||
// JSONArray hasLogic = value.getJSONArray("logicSectionList");
|
||||
String physicsTrackCode = value.getString("parentCode");
|
||||
String name = value.getString("name");
|
||||
if (StringUtils.isEmpty(physicsTrackCode)) {
|
||||
newNames.add(name);
|
||||
} else {
|
||||
JSONObject physicsTrack = jsonMap.get(physicsTrackCode);
|
||||
String pn = physicsTrack.getString("name");
|
||||
newNames.add(pn + name);
|
||||
|
||||
}
|
||||
}
|
||||
return newNames;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
String changeDeviceName(String nccDeviceName) {
|
||||
if (nccDeviceName.length() < 4) {
|
||||
return nccDeviceName;
|
||||
}
|
||||
if (nccDeviceName.startsWith("T") && nccDeviceName.contains("_")) {
|
||||
return nccDeviceName.substring(1);
|
||||
} else if (nccDeviceName.matches("^[A-Za-z]{2}.*?")) {
|
||||
String head = nccDeviceName.substring(2, 4);
|
||||
String tail = nccDeviceName.substring(5);
|
||||
String tailEnd = "";
|
||||
if (tail.matches(".*?[A-Z]$")) {
|
||||
tail = nccDeviceName.substring(4, nccDeviceName.length() - 1);
|
||||
tailEnd = nccDeviceName.substring(nccDeviceName.length() - 1);
|
||||
}
|
||||
return "G" + tail + head + tailEnd;
|
||||
} else if (nccDeviceName.matches(".*?[A-Z]$")) {
|
||||
String head = nccDeviceName.substring(1, 3);
|
||||
String tail = nccDeviceName.substring(4);
|
||||
String tailEnd = "";
|
||||
if (tail.matches(".*?[A-Z]$")) {
|
||||
tail = nccDeviceName.substring(4, nccDeviceName.length() - 1);
|
||||
tailEnd = nccDeviceName.substring(nccDeviceName.length() - 1);
|
||||
}
|
||||
return "G" + tail + head + tailEnd;
|
||||
} else {
|
||||
return "S" + nccDeviceName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SignalDevice extends DeviceNameChanger {
|
||||
|
||||
/* @Override
|
||||
List<String> findAllDeviceName(JSONArray dataArray) {
|
||||
List<String> mapDeviceNames = dataArray.stream().filter(d -> d instanceof JSONObject).map(d -> (JSONObject) d).map(d -> d.getString("name")).toList();
|
||||
return mapDeviceNames;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
String changeDeviceName(String nccDeviceName) {
|
||||
if (nccDeviceName.length() <= 3) {
|
||||
return nccDeviceName;
|
||||
}
|
||||
String started = nccDeviceName.substring(0, 1);
|
||||
String head = nccDeviceName.substring(1, 3);
|
||||
String tail = nccDeviceName.substring(4);
|
||||
return started + tail + head;
|
||||
}
|
||||
}
|
||||
|
||||
/* public static class PlatformDevice extends Device {
|
||||
|
||||
@Override
|
||||
List<String> findAllDeviceName(JSONArray dataArray) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
String changeDeviceName(String nccDeviceName) {
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user