package org.opendaylight.netconf.console.commands;
+import com.google.common.base.Strings;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import com.google.common.base.Strings;
-
-public class NetconfCommandUtils {
+public final class NetconfCommandUtils {
private static final Pattern IP_PATTERN = Pattern.compile(
- "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
- "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
- "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
- "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+ "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+
+ private NetconfCommandUtils() {
+
+ }
public static boolean isPortValid(final String devicePort) {
if (Strings.isNullOrEmpty(devicePort)) {
return false;
}
- Integer port = Integer.parseInt(devicePort);
- if (port != null && port >= 0 && port <= 65535) {
- return true;
+ Integer port;
+ try {
+ port = Integer.parseInt(devicePort);
+ } catch (NumberFormatException e) {
+ return false;
}
- return false;
+ return port >= 0 && port <= 65535;
}
public static boolean isIpValid(final String deviceIp) {