06.2026
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package sparseviewer.model;
|
||||
|
||||
public class ChannelUtils {
|
||||
|
||||
public static int findChannelIndex(String[] channelNames, String targetName) {
|
||||
if (channelNames == null || targetName == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < channelNames.length; i++) {
|
||||
if (targetName.equals(channelNames[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int resolveChannelIndex(String[] channelNames,
|
||||
String storedName,
|
||||
int storedIndex,
|
||||
int defaultIndex) {
|
||||
int byName = findChannelIndex(channelNames, storedName);
|
||||
|
||||
if (byName >= 0) {
|
||||
return byName;
|
||||
}
|
||||
|
||||
if (storedIndex >= 0 && channelNames != null && storedIndex < channelNames.length) {
|
||||
return storedIndex;
|
||||
}
|
||||
|
||||
if (channelNames != null && channelNames.length > 0) {
|
||||
if (defaultIndex < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (defaultIndex >= channelNames.length) {
|
||||
return channelNames.length - 1;
|
||||
}
|
||||
|
||||
return defaultIndex;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static String shortName(String name) {
|
||||
if (name == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String s = name;
|
||||
|
||||
int typeIdx = s.lastIndexOf(":float");
|
||||
if (typeIdx > 0) {
|
||||
s = s.substring(0, typeIdx);
|
||||
}
|
||||
|
||||
int idx = s.lastIndexOf(':');
|
||||
if (idx >= 0 && idx < s.length() - 1) {
|
||||
return s.substring(idx + 1);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user