Package javaflow.network.api

Source Code of javaflow.network.api.NetworkApiUtil

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

Related Classes of javaflow.network.api.NetworkApiUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.