package javaflow.network.api;
import java.lang.reflect.Field;
import javaflow.components.api.Name;
public class NetworkApiUtil {
public static String portNameForField(Field field) {
Name n = field.getAnnotation(Name.class);
final String portName;
if (null == n) {
String possiblePortName = field.getName().toUpperCase();
portName = stringWithoutPossiblePortSuffix(possiblePortName);
} else {
portName = n.value();
}
return portName;
}
private static String stringWithoutPossiblePortSuffix(String possiblePortName) {
String portName;
if (possiblePortName.endsWith("PORT")) {
portName = possiblePortName.substring(0, possiblePortName.length() - 4);
} else {
portName = possiblePortName;
}
return portName;
}
/**
* Checks if string is name of a port.
* Port name is written in capital letters.
* @param portName
* @return
*/
public static boolean isPortName(String portName) {
return portName.toUpperCase().equals(portName);
}
}